1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixed that has_many.create ended up with duplicate objects (closes #5250) [daniel@nouvelles-solutions.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4416 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2006-06-03 21:16:50 +00:00
parent 01a52dd1ad
commit 1671609063
2 changed files with 9 additions and 1 deletions

View file

@ -114,7 +114,7 @@ module ActiveRecord
begin
if !loaded?
if @target.is_a?(Array) && @target.any?
@target = find_target + @target
@target = (find_target + @target).uniq
else
@target = find_target
end

View file

@ -461,6 +461,14 @@ class HasManyAssociationsTest < Test::Unit::TestCase
assert_equal natural, companies(:first_firm).clients_of_firm.last
end
def test_adding_using_create
first_firm = companies(:first_firm)
assert_equal 2, first_firm.plain_clients.size
natural = first_firm.plain_clients.create(:name => "Natural Company")
assert_equal 3, first_firm.plain_clients.length
assert_equal 3, first_firm.plain_clients.size
end
def test_adding_a_mismatch_class
assert_raises(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).clients_of_firm << nil }
assert_raises(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).clients_of_firm << 1 }