mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Clear ActiveRecord object memoized by take
This commit is contained in:
parent
6b40767df8
commit
2a65310890
3 changed files with 27 additions and 1 deletions
|
@ -641,6 +641,7 @@ module ActiveRecord
|
|||
@to_sql = @arel = @loaded = @should_eager_load = nil
|
||||
@records = [].freeze
|
||||
@offsets = {}
|
||||
@take = nil
|
||||
self
|
||||
end
|
||||
|
||||
|
|
|
@ -390,7 +390,6 @@ module ActiveRecord
|
|||
assert_equal author_addresses(:david_address), author_address
|
||||
end
|
||||
|
||||
|
||||
def test_where_on_association_with_select_relation
|
||||
essay = Essay.where(author: Author.where(name: "David").select(:name)).take
|
||||
assert_equal essays(:david_modest_proposal), essay
|
||||
|
|
|
@ -2050,6 +2050,32 @@ class RelationTest < ActiveRecord::TestCase
|
|||
assert_equal [accounts(:signals37)], sub_accounts.available
|
||||
end
|
||||
|
||||
def test_where_with_take_memoization
|
||||
5.times do |idx|
|
||||
Post.create!(title: idx.to_s, body: idx.to_s)
|
||||
end
|
||||
|
||||
posts = Post.all
|
||||
first_post = posts.take
|
||||
third_post = posts.where(title: "3").take
|
||||
|
||||
assert_equal "3", third_post.title
|
||||
assert_not_equal first_post.object_id, third_post.object_id
|
||||
end
|
||||
|
||||
def test_find_by_with_take_memoization
|
||||
5.times do |idx|
|
||||
Post.create!(title: idx.to_s, body: idx.to_s)
|
||||
end
|
||||
|
||||
posts = Post.all
|
||||
first_post = posts.take
|
||||
third_post = posts.find_by(title: "3")
|
||||
|
||||
assert_equal "3", third_post.title
|
||||
assert_not_equal first_post.object_id, third_post.object_id
|
||||
end
|
||||
|
||||
test "#skip_query_cache!" do
|
||||
Post.cache do
|
||||
assert_queries(1) do
|
||||
|
|
Loading…
Reference in a new issue