mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Fix Rails test not being ran (#649)
This commit is contained in:
parent
cb82b9f873
commit
5124a172ac
5 changed files with 23 additions and 14 deletions
|
|
@ -12,9 +12,11 @@ describe "Cache store config when using allow2ban" do
|
|||
end
|
||||
end
|
||||
|
||||
it "gives semantic error if no store was configured" do
|
||||
assert_raises(Rack::Attack::MissingStoreError) do
|
||||
get "/scarce-resource"
|
||||
unless defined?(Rails)
|
||||
it "gives semantic error if no store was configured" do
|
||||
assert_raises(Rack::Attack::MissingStoreError) do
|
||||
get "/scarce-resource"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -12,9 +12,11 @@ describe "Cache store config when using fail2ban" do
|
|||
end
|
||||
end
|
||||
|
||||
it "gives semantic error if no store was configured" do
|
||||
assert_raises(Rack::Attack::MissingStoreError) do
|
||||
get "/private-place"
|
||||
unless defined?(Rails)
|
||||
it "gives semantic error if no store was configured" do
|
||||
assert_raises(Rack::Attack::MissingStoreError) do
|
||||
get "/private-place"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,11 @@ describe "Cache store config when throttling without Rails" do
|
|||
end
|
||||
end
|
||||
|
||||
it "gives semantic error if no store was configured" do
|
||||
assert_raises(Rack::Attack::MissingStoreError) do
|
||||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
|
||||
unless defined?(Rails)
|
||||
it "gives semantic error if no store was configured" do
|
||||
assert_raises(Rack::Attack::MissingStoreError) do
|
||||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,12 @@ describe "Cache store config with Rails" do
|
|||
end
|
||||
end
|
||||
|
||||
it "fails when Rails.cache is not set" do
|
||||
Object.stub_const(:Rails, OpenStruct.new(cache: nil)) do
|
||||
assert_raises(Rack::Attack::MissingStoreError) do
|
||||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
|
||||
unless defined?(Rails)
|
||||
it "fails when Rails.cache is not set" do
|
||||
Object.stub_const(:Rails, OpenStruct.new(cache: nil)) do
|
||||
assert_raises(Rack::Attack::MissingStoreError) do
|
||||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ end
|
|||
|
||||
safe_require "connection_pool"
|
||||
safe_require "dalli"
|
||||
safe_require "rails"
|
||||
safe_require "redis"
|
||||
safe_require "redis-store"
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ class Minitest::Spec
|
|||
include Rack::Test::Methods
|
||||
|
||||
before do
|
||||
if Object.const_defined?(:Rails) && Rails.respond_to?(:cache)
|
||||
if Object.const_defined?(:Rails) && Rails.respond_to?(:cache) && Rails.cache.respond_to?(:clear)
|
||||
Rails.cache.clear
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue