diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-08-02 16:09:06 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-08-16 22:50:41 +0900 |
commit | 9d0088840cfa57018d2f1b60d8e6a6842b60fc61 (patch) | |
tree | 2d4718c08941fbcefb541914f3432cc45a73ada7 /activerecord/test/cases/associations | |
parent | 82ec6b36065e91fe0ec5a87f9419840618ce2c5d (diff) | |
download | rails-9d0088840cfa57018d2f1b60d8e6a6842b60fc61.tar.gz rails-9d0088840cfa57018d2f1b60d8e6a6842b60fc61.tar.bz2 rails-9d0088840cfa57018d2f1b60d8e6a6842b60fc61.zip |
Finder bang method should call non bang method
Otherwise CollectionProxy's bang methdos cannot respect dirty target.
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 40 |
1 files changed, 40 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 d53c2b0c51..5a108333b0 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -424,6 +424,46 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end end + def test_finder_method_with_dirty_target + company = companies(:first_firm) + new_clients = [] + assert_no_queries(ignore_none: false) do + new_clients << company.clients_of_firm.build(name: "Another Client") + new_clients << company.clients_of_firm.build(name: "Another Client II") + new_clients << company.clients_of_firm.build(name: "Another Client III") + end + + assert_not company.clients_of_firm.loaded? + assert_queries(1) do + assert_same new_clients[0], company.clients_of_firm.third + assert_same new_clients[1], company.clients_of_firm.fourth + assert_same new_clients[2], company.clients_of_firm.fifth + assert_same new_clients[0], company.clients_of_firm.third_to_last + assert_same new_clients[1], company.clients_of_firm.second_to_last + assert_same new_clients[2], company.clients_of_firm.last + end + end + + def test_finder_bang_method_with_dirty_target + company = companies(:first_firm) + new_clients = [] + assert_no_queries(ignore_none: false) do + new_clients << company.clients_of_firm.build(name: "Another Client") + new_clients << company.clients_of_firm.build(name: "Another Client II") + new_clients << company.clients_of_firm.build(name: "Another Client III") + end + + assert_not company.clients_of_firm.loaded? + assert_queries(1) do + assert_same new_clients[0], company.clients_of_firm.third! + assert_same new_clients[1], company.clients_of_firm.fourth! + assert_same new_clients[2], company.clients_of_firm.fifth! + assert_same new_clients[0], company.clients_of_firm.third_to_last! + assert_same new_clients[1], company.clients_of_firm.second_to_last! + assert_same new_clients[2], company.clients_of_firm.last! + end + end + def test_create_resets_cached_counters person = Person.create!(first_name: "tenderlove") post = Post.first |