File tree 3 files changed +27
-1
lines changed
3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -641,6 +641,7 @@ def reset
641
641
@to_sql = @arel = @loaded = @should_eager_load = nil
642
642
@records = [ ] . freeze
643
643
@offsets = { }
644
+ @take = nil
644
645
self
645
646
end
646
647
Original file line number Diff line number Diff line change @@ -390,7 +390,6 @@ def test_where_with_relation_on_has_one_association
390
390
assert_equal author_addresses ( :david_address ) , author_address
391
391
end
392
392
393
-
394
393
def test_where_on_association_with_select_relation
395
394
essay = Essay . where ( author : Author . where ( name : "David" ) . select ( :name ) ) . take
396
395
assert_equal essays ( :david_modest_proposal ) , essay
Original file line number Diff line number Diff line change @@ -2050,6 +2050,32 @@ def test_relation_with_private_kernel_method
2050
2050
assert_equal [ accounts ( :signals37 ) ] , sub_accounts . available
2051
2051
end
2052
2052
2053
+ def test_where_with_take_memoization
2054
+ 5 . times do |idx |
2055
+ Post . create! ( title : idx . to_s , body : idx . to_s )
2056
+ end
2057
+
2058
+ posts = Post . all
2059
+ first_post = posts . take
2060
+ third_post = posts . where ( title : "3" ) . take
2061
+
2062
+ assert_equal "3" , third_post . title
2063
+ assert_not_equal first_post . object_id , third_post . object_id
2064
+ end
2065
+
2066
+ def test_find_by_with_take_memoization
2067
+ 5 . times do |idx |
2068
+ Post . create! ( title : idx . to_s , body : idx . to_s )
2069
+ end
2070
+
2071
+ posts = Post . all
2072
+ first_post = posts . take
2073
+ third_post = posts . find_by ( title : "3" )
2074
+
2075
+ assert_equal "3" , third_post . title
2076
+ assert_not_equal first_post . object_id , third_post . object_id
2077
+ end
2078
+
2053
2079
test "#skip_query_cache!" do
2054
2080
Post . cache do
2055
2081
assert_queries ( 1 ) do
You can’t perform that action at this time.
0 commit comments