diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-08 22:39:58 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-08 22:39:58 +0900 |
commit | e133573c8195f088ce29fbebabe3428cff9dc20d (patch) | |
tree | e2d78c929967a908f6c96823887cb630d57ffead /activerecord/test/cases | |
parent | 4cb1438b57067d637c79d49d0662c43b5b4e64c2 (diff) | |
parent | 7f153e936af6ae2ac1809e5758000aaf003a1f62 (diff) | |
download | rails-e133573c8195f088ce29fbebabe3428cff9dc20d.tar.gz rails-e133573c8195f088ce29fbebabe3428cff9dc20d.tar.bz2 rails-e133573c8195f088ce29fbebabe3428cff9dc20d.zip |
Merge pull request #35178 from bogdan/has-many-size
Bugfix has_many association #size when ids reader is cached and assoc…
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 15 |
1 files changed, 15 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 5fdc5a92fc..bf44be1811 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -2004,6 +2004,21 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_not_predicate company.clients, :loaded? end + def test_ids_reader_cache_not_used_for_size_when_association_is_dirty + firm = Firm.create!(name: "Startup") + assert_equal 0, firm.client_ids.size + firm.clients.build + assert_equal 1, firm.clients.size + end + + def test_ids_reader_cache_should_be_cleared_when_collection_is_deleted + firm = companies(:first_firm) + assert_equal [2, 3, 11], firm.client_ids + client = firm.clients.first + firm.clients.delete(client) + assert_equal [3, 11], firm.client_ids + end + def test_zero_counter_cache_usage_on_unloaded_association car = Car.create!(name: "My AppliCar") assert_no_queries do |