Skip to content

Commit

Permalink
Don't autoplug middleware for untested rails versions
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Oct 12, 2019
1 parent f65431f commit 1167c65
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Or install it yourself as:

Then tell your ruby web application to use rack-attack as a middleware.

a) For __rails__ applications with versions >= 5 it is used by default. For older rails versions you should enable it explicitly:
a) For __rails__ applications with versions >= 5.1 it is used by default. For older rails versions you should enable it explicitly:
```ruby
# In config/application.rb

Expand Down
2 changes: 1 addition & 1 deletion lib/rack/attack/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Rack
class Attack
class Railtie < ::Rails::Railtie
initializer 'rack.attack.middleware', after: :load_config_initializers, before: :build_middleware_stack do |app|
if Gem::Version.new(::Rails::VERSION::STRING) >= Gem::Version.new("5")
if Gem::Version.new(::Rails::VERSION::STRING) >= Gem::Version.new("5.1")
middlewares = app.config.middleware
operations = middlewares.send(:operations) + middlewares.send(:delete_operations)

Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/rails_middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end
end

if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("5")
if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("5.1")
it "is used by default" do
@app.initialize!
assert_equal 1, @app.middleware.count(Rack::Attack)
Expand All @@ -31,7 +31,7 @@
end
end

if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new("5")
if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new("5.1")
it "is not used by default" do
@app.initialize!
assert_equal 0, @app.middleware.count(Rack::Attack)
Expand Down

0 comments on commit 1167c65

Please sign in to comment.