Fix Rails test not being ran (#649)

This commit is contained in:
Santiago Bartesaghi 2024-01-10 12:10:56 -03:00 committed by GitHub
parent cb82b9f873
commit 5124a172ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 14 deletions

View file

@ -12,11 +12,13 @@ describe "Cache store config when using allow2ban" do
end
end
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
it "gives semantic error if store is missing #read method" do
raised_exception = nil

View file

@ -12,11 +12,13 @@ describe "Cache store config when using fail2ban" do
end
end
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
it "gives semantic error if store is missing #read method" do
raised_exception = nil

View file

@ -9,11 +9,13 @@ describe "Cache store config when throttling without Rails" do
end
end
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
it "gives semantic error if incompatible store was configured" do
Rack::Attack.cache.store = Object.new

View file

@ -11,6 +11,7 @@ describe "Cache store config with Rails" do
end
end
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
@ -18,6 +19,7 @@ describe "Cache store config with Rails" do
end
end
end
end
it "works when Rails.cache is set" do
Object.stub_const(:Rails, OpenStruct.new(cache: ActiveSupport::Cache::MemoryStore.new)) do

View file

@ -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