Skip to content

Commit 0350346

Browse files
committed
Ensure Kredis.namespace is set in the thread that executes the test
Otherwise, Kredis.namespace may be nil, resulting in wiping the whole Redis db in test teardown.
1 parent 57cedf5 commit 0350346

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/kredis/railtie.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@ class Kredis::Railtie < ::Rails::Railtie
55

66
initializer "kredis.testing" do
77
ActiveSupport.on_load(:active_support_test_case) do
8-
parallelize_setup { |worker| Kredis.namespace = "test-#{worker}" }
9-
teardown { Kredis.clear_all }
8+
$kredis_parallel_worker = nil
9+
parallelize_setup { |worker| $kredis_parallel_worker = worker }
10+
11+
setup do
12+
@original_namespace = Kredis.namespace
13+
Kredis.namespace = [ @original_namespace, :test, $kredis_parallel_worker ].compact.join("-")
14+
end
15+
16+
teardown do
17+
Kredis.clear_all
18+
Kredis.namespace = @original_namespace
19+
end
1020
end
1121
end
1222

0 commit comments

Comments
 (0)