File tree 4 files changed +22
-10
lines changed
4 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -54,4 +54,5 @@ gem "importmap-rails"
54
54
group :test do
55
55
gem "simplecov" , require : false
56
56
gem "simplecov-cobertura"
57
+ gem 'fakeredis'
57
58
end
Original file line number Diff line number Diff line change 102
102
factory_bot_rails (6.4.3 )
103
103
factory_bot (~> 6.4 )
104
104
railties (>= 5.0.0 )
105
+ fakeredis (0.1.4 )
105
106
fugit (1.11.1 )
106
107
et-orbi (~> 1 , >= 1.2.11 )
107
108
raabro (~> 1.4 )
@@ -303,6 +304,7 @@ DEPENDENCIES
303
304
debug
304
305
dotenv-rails
305
306
factory_bot_rails
307
+ fakeredis
306
308
importmap-rails
307
309
puma
308
310
rails (~> 7.2.1 )
Original file line number Diff line number Diff line change 1
1
require "redis"
2
2
3
- redis_url = ENV [ "REDIS_URL" ] || "redis://localhost:6379/0"
3
+ unless defined? ( REDIS )
4
+ redis_url = ENV [ "REDIS_URL" ] || "redis://localhost:6379/0"
4
5
5
- REDIS = Redis . new ( url : redis_url )
6
+ REDIS = Redis . new ( url : redis_url )
6
7
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
13
15
end
Original file line number Diff line number Diff line change @@ -21,5 +21,12 @@ class ActiveSupport::TestCase
21
21
# Add more helper methods to be used by all tests here...
22
22
end
23
23
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