aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-04-21 16:11:57 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-04-21 16:18:03 +0900
commite76e4778d172e2bf43026490256d33a8f5441393 (patch)
treec0621ed4a021b23ddfc1b02b95812a022fd01475
parentac1efe7a947ba04b276a7109f1a86e559a6ab683 (diff)
downloadrails-e76e4778d172e2bf43026490256d33a8f5441393.tar.gz
rails-e76e4778d172e2bf43026490256d33a8f5441393.tar.bz2
rails-e76e4778d172e2bf43026490256d33a8f5441393.zip
Add test case for `collection.size` with dirty target
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index b00a3880f6..33fe5ccabc 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -983,6 +983,16 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_not_empty company.contracts
end
+ def test_collection_size_with_dirty_target
+ post = posts(:thinking)
+ assert_equal [], post.reader_ids
+ assert_equal 0, post.readers.size
+ post.readers.reset
+ post.readers.build
+ assert_equal [], post.reader_ids
+ assert_equal 1, post.readers.size
+ end
+
def test_collection_size_twice_for_regressions
post = posts(:thinking)
assert_equal 0, post.readers.size