From e76e4778d172e2bf43026490256d33a8f5441393 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 21 Apr 2018 16:11:57 +0900 Subject: Add test case for `collection.size` with dirty target --- .../test/cases/associations/has_many_associations_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 -- cgit v1.2.3