Skip to content

Commit c342933

Browse files
rossmedjmb
authored andcommitted
Clean up tests, and make some connections module methods private
1 parent e6bbc4e commit c342933

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

lib/solid_cache/store/connections.rb

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,6 @@ def with_each_connection(async: false, &block)
3434
end
3535
end
3636

37-
def with_connection_for(key, async: false, &block)
38-
connections.with_connection_for(key) do
39-
execute(async, &block)
40-
end
41-
end
42-
43-
def with_connection(name, async: false, &block)
44-
connections.with(name) do
45-
execute(async, &block)
46-
end
47-
end
48-
49-
def group_by_connection(keys)
50-
connections.assign(keys)
51-
end
52-
53-
def connection_names
54-
connections.names
55-
end
56-
5737
def connections
5838
@connections ||= SolidCache::Connections.from_config(@shard_options)
5939
end
@@ -63,34 +43,53 @@ def setup!
6343
connections
6444
end
6545

46+
def with_connection_for(key, async: false, &block)
47+
connections.with_connection_for(key) do
48+
execute(async, &block)
49+
end
50+
end
51+
52+
def with_connection(name, async: false, &block)
53+
connections.with(name) do
54+
execute(async, &block)
55+
end
56+
end
57+
58+
def group_by_connection(keys)
59+
connections.assign(keys)
60+
end
61+
62+
def connection_names
63+
connections.names
64+
end
65+
6666
def reading_key(key, failsafe:, failsafe_returning: nil, &block)
6767
failsafe(failsafe, returning: failsafe_returning) do
6868
with_connection_for(key, &block)
6969
end
7070
end
7171

7272
def reading_keys(keys, failsafe:, failsafe_returning: nil)
73-
group_by_connection(keys).map do |connection, keys|
73+
group_by_connection(keys).map do |connection, grouped_keys|
7474
failsafe(failsafe, returning: failsafe_returning) do
7575
with_connection(connection) do
76-
yield keys
76+
yield grouped_keys
7777
end
7878
end
7979
end
8080
end
8181

82-
8382
def writing_key(key, failsafe:, failsafe_returning: nil, &block)
8483
failsafe(failsafe, returning: failsafe_returning) do
8584
with_connection_for(key, &block)
8685
end
8786
end
8887

8988
def writing_keys(entries, failsafe:, failsafe_returning: nil)
90-
group_by_connection(entries).map do |connection, entries|
89+
group_by_connection(entries).map do |connection, grouped_entries|
9190
failsafe(failsafe, returning: failsafe_returning) do
9291
with_connection(connection) do
93-
yield entries
92+
yield grouped_entries
9493
end
9594
end
9695
end

test/unit/behaviors/cache_increment_decrement_behavior.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ def test_decrement
3131
assert_equal -100, missing
3232
end
3333

34-
def test_ttl_isnt_updated
34+
def test_ttl_is_not_updated
3535
key = SecureRandom.uuid
3636

3737
assert_equal 1, @cache.increment(key, 1, expires_in: 1)
3838
assert_equal 2, @cache.increment(key, 1, expires_in: 5000)
3939

40-
# having to sleep two seconds in a test is bad, but we're testing
41-
# a wide range of backends with different TTL mecanisms, most without
40+
# Having to sleep two seconds in a test is bad, but we're testing
41+
# a wide range of backends with different TTL mechanisms, most without
4242
# subsecond granularity, so this is the only reliable way.
4343
sleep 2
4444

test/unit/behaviors_rails_7_2/cache_increment_decrement_behavior.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ def test_decrement
3131
assert_equal -100, missing
3232
end
3333

34-
def test_ttl_isnt_updated
34+
def test_ttl_is_not_updated
3535
key = SecureRandom.uuid
3636

3737
assert_equal 1, @cache.increment(key, 1, expires_in: 1)
3838
assert_equal 2, @cache.increment(key, 1, expires_in: 5000)
3939

40-
# having to sleep two seconds in a test is bad, but we're testing
41-
# a wide range of backends with different TTL mecanisms, most without
40+
# Having to sleep two seconds in a test is bad, but we're testing
41+
# a wide range of backends with different TTL mechanisms, most without
4242
# subsecond granularity, so this is the only reliable way.
4343
sleep 2
4444

test/unit/delete_matched_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DeleteMatchedTest < ActiveSupport::TestCase
1414
@peek = lookup_store(expires_in: 60)
1515
end
1616

17-
test "deletes matched raises a NotImplementedError" do
17+
test "delete matched raises a NotImplementedError" do
1818
prefix = SecureRandom.alphanumeric
1919
assert_raises(NotImplementedError) { @cache.delete_matched("#{prefix}%") }
2020
end

test/unit/execution_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_active_record_instrumention_expiry
7575
}
7676

7777
ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
78-
# Warm up the connections as they may log before instrumenation can be disabled
78+
# Warm up the connections as they may log before instrumentation can be disabled
7979
uninstrumented_cache.write("foo", "bar")
8080
uninstrumented_cache.write("foo", "bar")
8181
uninstrumented_cache.write("foo", "bar")
@@ -90,7 +90,7 @@ def test_active_record_instrumention_expiry
9090
end
9191

9292
ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
93-
# Warm up the connections as they may log before instrumenation can be disabled
93+
# Warm up the connections as they may log before instrumentation can be disabled
9494
instrumented_cache.write("foo", "bar")
9595
instrumented_cache.write("foo", "bar")
9696
instrumented_cache.write("foo", "bar")

0 commit comments

Comments
 (0)