diff options
author | Alan Kennedy <alankennedy100@gmail.com> | 2012-11-25 21:01:27 +0000 |
---|---|---|
committer | Alan Kennedy <alankennedy100@gmail.com> | 2013-10-31 18:16:29 +0000 |
commit | f74a5616e89f03e13a025401475ac1101bb159ae (patch) | |
tree | df6a26ff670af4d3e35e4efd350ab203644cc803 /activerecord/test/cases | |
parent | 6e5d409f659c325871cac4cca79526e815644288 (diff) | |
download | rails-f74a5616e89f03e13a025401475ac1101bb159ae.tar.gz rails-f74a5616e89f03e13a025401475ac1101bb159ae.tar.bz2 rails-f74a5616e89f03e13a025401475ac1101bb159ae.zip |
Save has_one associations only if record has changes
Prevents save related callbacks such as `after_commit` being
triggered when `has_one` objects are already persisted and have no
changes.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/autosave_association_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 517d2674a7..acb19032ea 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -626,10 +626,25 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase end end + @ship.pirate.catchphrase = "Changed Catchphrase" + assert_raise(RuntimeError) { assert !@pirate.save } assert_not_nil @pirate.reload.ship end + def test_should_save_changed_has_one_changed_object_if_child_is_saved + @pirate.ship.name = "NewName" + @pirate.ship.expects(:save).once.returns(true) + + assert @pirate.save + end + + def test_should_not_save_changed_has_one_unchanged_object_if_child_is_saved + @pirate.ship.expects(:save).never + + assert @pirate.save + end + # belongs_to def test_should_destroy_a_parent_association_as_part_of_the_save_transaction_if_it_was_marked_for_destroyal assert !@ship.pirate.marked_for_destruction? |