aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-08-16 05:15:11 -0300
committerGitHub <noreply@github.com>2016-08-16 05:15:11 -0300
commit426ea715fd7522653c131076bd321e4caab40e8e (patch)
tree36fa3af92ccc76c51164fe4f65f55d3cabdcc3b1 /activerecord/test/cases
parent3e9070e645147b1a73013633002d27002b3a1f4f (diff)
parent33d62981b667e72e25c38de848dbac843713f192 (diff)
downloadrails-426ea715fd7522653c131076bd321e4caab40e8e.tar.gz
rails-426ea715fd7522653c131076bd321e4caab40e8e.tar.bz2
rails-426ea715fd7522653c131076bd321e4caab40e8e.zip
Merge pull request #26162 from kamipo/take_respects_dirty_target
`CollectionProxy#take` should respect dirty target
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index cc4419790c..dd3b7240b8 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -525,14 +525,18 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
def test_taking_with_a_number
# taking from unloaded Relation
bob = Author.find(authors(:bob).id)
+ new_post = bob.posts.build
+ assert_not bob.posts.loaded?
assert_equal [posts(:misc_by_bob)], bob.posts.take(1)
- bob = Author.find(authors(:bob).id)
assert_equal [posts(:misc_by_bob), posts(:other_by_bob)], bob.posts.take(2)
+ assert_equal [posts(:misc_by_bob), posts(:other_by_bob), new_post], bob.posts.take(3)
# taking from loaded Relation
- bob.posts.to_a
- assert_equal [posts(:misc_by_bob)], authors(:bob).posts.take(1)
- assert_equal [posts(:misc_by_bob), posts(:other_by_bob)], authors(:bob).posts.take(2)
+ bob.posts.load
+ assert bob.posts.loaded?
+ assert_equal [posts(:misc_by_bob)], bob.posts.take(1)
+ assert_equal [posts(:misc_by_bob), posts(:other_by_bob)], bob.posts.take(2)
+ assert_equal [posts(:misc_by_bob), posts(:other_by_bob), new_post], bob.posts.take(3)
end
def test_taking_with_inverse_of