File tree Expand file tree Collapse file tree 4 files changed +22
-10
lines changed Expand file tree Collapse file tree 4 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -54,4 +54,5 @@ gem "importmap-rails"
5454group :test do
5555 gem "simplecov" , require : false
5656 gem "simplecov-cobertura"
57+ gem 'fakeredis'
5758end
Original file line number Diff line number Diff line change 102102 factory_bot_rails (6.4.3 )
103103 factory_bot (~> 6.4 )
104104 railties (>= 5.0.0 )
105+ fakeredis (0.1.4 )
105106 fugit (1.11.1 )
106107 et-orbi (~> 1 , >= 1.2.11 )
107108 raabro (~> 1.4 )
@@ -303,6 +304,7 @@ DEPENDENCIES
303304 debug
304305 dotenv-rails
305306 factory_bot_rails
307+ fakeredis
306308 importmap-rails
307309 puma
308310 rails (~> 7.2.1 )
Original file line number Diff line number Diff line change 11require "redis"
22
3- redis_url = ENV [ "REDIS_URL" ] || "redis://localhost:6379/0"
3+ unless defined? ( REDIS )
4+ redis_url = ENV [ "REDIS_URL" ] || "redis://localhost:6379/0"
45
5- REDIS = Redis . new ( url : redis_url )
6+ REDIS = Redis . new ( url : redis_url )
67
7- # Add error handling
8- begin
9- REDIS . ping
10- rescue Redis ::CannotConnectError => e
11- Rails . logger . error "Failed to connect to Redis: #{ e . message } "
12- REDIS = nil
8+ # Add error handling
9+ begin
10+ REDIS . ping
11+ rescue Redis ::CannotConnectError => e
12+ Rails . logger . error "Failed to connect to Redis: #{ e . message } "
13+ REDIS = nil
14+ end
1315end
Original file line number Diff line number Diff line change @@ -21,5 +21,12 @@ class ActiveSupport::TestCase
2121 # Add more helper methods to be used by all tests here...
2222end
2323
24- # Configure Redis for testing
25- REDIS = Redis . new ( url : ENV [ "REDIS_URL" ] || "redis://localhost:6379/1" )
24+ # Use FakeRedis for testing if available, otherwise use real Redis
25+ begin
26+ require 'fakeredis/minitest'
27+ puts "Using FakeRedis for testing"
28+ rescue LoadError
29+ puts "FakeRedis not available, using real Redis for testing"
30+ require 'redis'
31+ REDIS = Redis . new ( url : ENV [ 'REDIS_URL' ] || 'redis://localhost:6379/1' )
32+ end
You can’t perform that action at this time.
0 commit comments