diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-08-17 00:08:34 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-17 00:08:34 -0300 |
commit | c183761f7929bab285416618bf95ad67939ebe4f (patch) | |
tree | d29ca768083ab74a4bf7b23e01f0739b114b4630 /activerecord/test/cases/associations/has_many_associations_test.rb | |
parent | 0549f9debfe27b804d8b35a7c67e3bf015ae1b89 (diff) | |
parent | 9d0088840cfa57018d2f1b60d8e6a6842b60fc61 (diff) | |
download | rails-c183761f7929bab285416618bf95ad67939ebe4f.tar.gz rails-c183761f7929bab285416618bf95ad67939ebe4f.tar.bz2 rails-c183761f7929bab285416618bf95ad67939ebe4f.zip |
Merge pull request #26021 from kamipo/finder_bang_method_should_call_non_bang_method
Finder bang method should call non bang method
Diffstat (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb')
-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 |