Merge pull request #51431 from fcce/fix-load_async-query_cache

Fix load_async to work with query cache
This commit is contained in:
Jean Boussier 2024-03-27 13:14:06 +01:00 committed by GitHub
commit e5d3bacc3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

@ -60,7 +60,6 @@ def self.wrap(result)
end
delegate :empty?, :to_a, to: :result
delegate_missing_to :result
attr_reader :lock_wait

@ -217,6 +217,11 @@ def test_pluck
assert_equal titles, Post.where(author_id: 1).load_async.pluck(:title)
end
def test_count
count = Post.where(author_id: 1).count
assert_equal count, Post.where(author_id: 1).load_async.count
end
def test_size
expected_size = Post.where(author_id: 1).size
@ -233,12 +238,19 @@ def test_empty?
assert_predicate deferred_posts, :loaded?
end
def test_load_async_with_query_cache
def test_load_async_pluck_with_query_cache
titles = Post.where(author_id: 1).pluck(:title)
Post.cache do
assert_equal titles, Post.where(author_id: 1).load_async.pluck(:title)
end
end
def test_load_async_count_with_query_cache
count = Post.where(author_id: 1).count
Post.cache do
assert_equal count, Post.where(author_id: 1).load_async.count
end
end
end
class LoadAsyncNullExecutorTest < ActiveRecord::TestCase