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

View file

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

View file

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

View file

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

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