rack-attack/spec/acceptance/rails_middleware_spec.rb
Gonzalo Rodriguez e3056e737f
fix: avoid unintended effects on load_config_initializers and other gems load order
Because of the sort algorithm rails uses to satisfy `after` and `before`
constraints, gems can have unintended effects on others. See
0a120a818d

Prefer making rack-attack middleware idempotent instead of relying on
the load order and the contents of the middleware stack too much.

closes #452
closes #456
2019-10-29 15:45:26 -03:00

35 lines
1 KiB
Ruby

# frozen_string_literal: true
require_relative "../spec_helper"
if defined?(Rails)
describe "Middleware for Rails" do
before do
@app = Class.new(Rails::Application) do
config.eager_load = false
config.logger = Logger.new(nil) # avoid creating the log/ directory automatically
config.cache_store = :null_store # avoid creating tmp/ directory for cache
end
end
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)
end
it "is not added when it was explicitly deleted" do
@app.config.middleware.delete(Rack::Attack)
@app.initialize!
refute @app.middleware.include?(Rack::Attack)
end
end
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)
end
end
end
end