Skip to content

Commit

Permalink
use global redis variable for Redis instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Cumming committed Mar 6, 2024
1 parent 256f7cc commit 2c688c1
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 36 deletions.
9 changes: 2 additions & 7 deletions config/coverband.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

# config/coverband.rb NOT in the initializers
Coverband.configure do |config|
redis = if Rails.env.test?
require 'mock_redis'
MockRedis.new(url: Settings.redis.app_data.url)
else
Redis.new(url: Settings.redis.app_data.url)
end
config.store = Coverband::Adapters::RedisStore.new(redis)

Check failure on line 5 in config/coverband.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
config.store = Coverband::Adapters::RedisStore.new($redis)
config.logger = Rails.logger

# config options false, true. (defaults to false)
Expand Down
10 changes: 1 addition & 9 deletions config/initializers/breakers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,7 @@

Rails.application.reloader.to_prepare do

Check failure on line 42 in config/initializers/breakers.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
redis = if Rails.env.test?
require 'mock_redis'
MockRedis.new(url: REDIS_CONFIG[:redis][:url])
else
Redis.new(REDIS_CONFIG[:redis].to_h)
end

redis_namespace = Redis::Namespace.new('breakers', redis: redis)

redis_namespace = Redis::Namespace.new('breakers', redis: $redis)

services = [
DebtManagementCenter::DebtsConfiguration.instance.breakers_service,
Expand Down
9 changes: 1 addition & 8 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ def remote_ip
end
end

redis = if Rails.env.test?
require 'mock_redis'
MockRedis.new(url: REDIS_CONFIG[:redis][:url])
else
Redis.new(REDIS_CONFIG[:redis].to_h)
end

Rack::Attack.cache.store = Rack::Attack::StoreProxy::RedisStoreProxy.new(redis)
Rack::Attack.cache.store = Rack::Attack::StoreProxy::RedisStoreProxy.new($redis)

throttle('example/ip', limit: 1, period: 5.minutes) do |req|
req.ip if req.path == '/v0/limited'
Expand Down
9 changes: 1 addition & 8 deletions modules/meb_api/config/initializers/breakers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@

Rails.application.reloader.to_prepare do

Check failure on line 13 in modules/meb_api/config/initializers/breakers.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
redis = if Rails.env.test?
require 'mock_redis'
MockRedis.new(url: REDIS_CONFIG[:redis][:url])
else
Redis.new(REDIS_CONFIG[:redis].to_h)
end

redis_namespace = Redis::Namespace.new('breakers', redis: redis)
redis_namespace = Redis::Namespace.new('breakers', redis: $redis)

services = [
MebApi::DGI::Configuration.instance.breakers_service,
Expand Down
1 change: 0 additions & 1 deletion spec/requests/breakers_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
# Not clearing the breakers would cause subsequent RX calls to fail after the breaker is
# triggered in this group.

# fakeredis/rspec has a `before` callback, but it's for the suite, not each example. Oops.
Breakers.client.redis_connection.redis.flushdb
end

Expand Down
4 changes: 1 addition & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@
end

config.before(:each) do
mock_redis = MockRedis.new(url: REDIS_CONFIG[:redis][:url])
allow(Redis).to receive(:new).and_return(mock_redis)
mock_redis.flushdb
$redis.flushdb
end

end

0 comments on commit 2c688c1

Please sign in to comment.