Permalink
Browse files

Fixed that calling HasOneProxy#build_model repeatedly would cause sav…

…ing to happen (closes #4058) [anna@wota.jp]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3753 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 9ed7430 commit 116658e69b9c4a722e6ae8717629b8cd0057db89 @dhh dhh committed Mar 3, 2006
View
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that calling HasOneProxy#build_model repeatedly would cause saving to happen #4058 [anna@wota.jp]
+
* Added Sybase database adapter that relies on the Sybase Open Client bindings (see http://raa.ruby-lang.org/project/sybase-ctlib) #3765 [John Sheets]. It's almost completely Active Record compliant, but has the following caveats:
* Does not support DATE SQL column types; use DATETIME instead.
@@ -34,7 +34,7 @@ def replace(obj, dont_save = false)
@owner.clear_association_cache
else
@target[@reflection.primary_key_name] = nil
- @target.save unless @owner.new_record?
+ @target.save unless @owner.new_record? || @target.new_record?
end
end
@@ -158,6 +158,15 @@ def test_failing_build_association
assert_equal "can't be empty", account.errors.on("credit_limit")
end
+ def test_build_association_twice_without_saving_affects_nothing
+ count_of_account = Account.count
+ firm = Firm.find(:first)
+ account1 = firm.build_account("credit_limit" => 1000)
+ account2 = firm.build_account("credit_limit" => 2000)
+
+ assert_equal count_of_account, Account.count
+ end
+
def test_create_association
firm = Firm.new("name" => "GlobalMegaCorp")
firm.save

0 comments on commit 116658e

Please sign in to comment.