From 35670bbde59de9d0838027bd4fcd4cc04f928e3d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 6 Aug 2006 19:23:40 +0000 Subject: Don't save has_one associations unnecessarily. Closes #5735. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4690 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'activerecord/test/associations_test.rb') diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 747d04cf3f..eecb096521 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -291,6 +291,23 @@ class HasOneAssociationsTest < Test::Unit::TestCase assert_equal a, firm.account assert_equal a, firm.account(true) end + + def test_not_resaved_when_unchanged + firm = Firm.find(:first, :include => :account) + assert_queries(1) { firm.save! } + + firm = Firm.find(:first) + firm.account = Account.find(:first) + assert_queries(1) { firm.save! } + + firm = Firm.find(:first).clone + firm.account = Account.find(:first) + assert_queries(2) { firm.save! } + + firm = Firm.find(:first).clone + firm.account = Account.find(:first).clone + assert_queries(2) { firm.save! } + end end -- cgit v1.2.3