diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-25 03:32:36 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-25 03:32:36 +0900 |
commit | 186458753f3614623523ad079d92c537cf03cb4a (patch) | |
tree | 5e75374e3289543940d05735b4e3a4373abc4c6c /activerecord/test/cases/associations | |
parent | 3a4aa492560d311f8d549f739bd69945f5d508ea (diff) | |
parent | 3fe83d1dd99ac2662852da0dcfe7e91dc08ae160 (diff) | |
download | rails-186458753f3614623523ad079d92c537cf03cb4a.tar.gz rails-186458753f3614623523ad079d92c537cf03cb4a.tar.bz2 rails-186458753f3614623523ad079d92c537cf03cb4a.zip |
Merge pull request #35869 from abhaynikam/35866-add-touch-option-for-has-one-association
Adds missing touch option to has_one association
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/has_one_associations_test.rb | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 7bb629466d..fd727757a3 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -15,10 +15,13 @@ require "models/post" require "models/drink_designer" require "models/chef" require "models/department" +require "models/club" +require "models/membership" class HasOneAssociationsTest < ActiveRecord::TestCase self.use_transactional_tests = false unless supports_savepoints? - fixtures :accounts, :companies, :developers, :projects, :developers_projects, :ships, :pirates, :authors, :author_addresses + fixtures :accounts, :companies, :developers, :projects, :developers_projects, + :ships, :pirates, :authors, :author_addresses, :memberships, :clubs def setup Account.destroyed_account_ids.clear @@ -706,6 +709,40 @@ class HasOneAssociationsTest < ActiveRecord::TestCase end end + def test_has_one_with_touch_option_on_create + assert_queries(3) { + Club.create(name: "1000 Oaks", membership_attributes: { favourite: true }) + } + end + + def test_has_one_with_touch_option_on_update + new_club = Club.create(name: "1000 Oaks") + new_club.create_membership + + assert_queries(2) { new_club.update(name: "Effingut") } + end + + def test_has_one_with_touch_option_on_touch + new_club = Club.create(name: "1000 Oaks") + new_club.create_membership + + assert_queries(1) { new_club.touch } + end + + def test_has_one_with_touch_option_on_destroy + new_club = Club.create(name: "1000 Oaks") + new_club.create_membership + + assert_queries(2) { new_club.destroy } + end + + def test_has_one_with_touch_option_on_empty_update + new_club = Club.create(name: "1000 Oaks") + new_club.create_membership + + assert_no_queries { new_club.save } + end + class SpecialBook < ActiveRecord::Base self.table_name = "books" belongs_to :author, class_name: "SpecialAuthor" |