Skip to content

Commit 29858b8

Browse files
committed
added test for checking that read_collection is tolerant of already cached ActiveRecord::Relation instances
1 parent aa59cf6 commit 29858b8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/lib/namespaced_env_cache_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ class NamespacedEnvCacheTest < ActiveSupport::TestCase
1717
end
1818
end
1919

20+
test 'read_collection should not break on cached ActiveRecord::Relation objects' do
21+
@cache.write('test_posts_cache', Post.where(user: users(:standard_user)))
22+
23+
data = assert_nothing_raised do
24+
@cache.fetch_collection('test_posts_cache')
25+
end
26+
27+
assert_not_nil data
28+
end
29+
2030
test 'fetch_collection' do
2131
data = assert_nothing_raised do
2232
@cache.fetch_collection('test_posts_cache') do
@@ -30,9 +40,11 @@ class NamespacedEnvCacheTest < ActiveSupport::TestCase
3040
@cache.fetch_collection('test_posts_cache') do
3141
Post.where(user: users(:standard_user))
3242
end
43+
3344
data = assert_nothing_raised do
3445
@cache.fetch_collection('test_posts_cache')
3546
end
47+
3648
assert_not_nil data
3749
end
3850

@@ -51,6 +63,7 @@ class NamespacedEnvCacheTest < ActiveSupport::TestCase
5163
test 'normalize_collection should correctly prepare collections for caching' do
5264
collection = Post.where(user: users(:standard_user))
5365
normalized = QPixel::NamespacedEnvCache.normalize_collection(collection)
66+
5467
assert_equal Post.name, normalized.shift
5568
assert(collection.to_a.all? { |post| normalized.include?(post.id) })
5669
end

0 commit comments

Comments
 (0)