Skip to content

Commit

Permalink
Fix CollectionAssociation#replace to return new target (closes #6231)
Browse files Browse the repository at this point in the history
Conflicts:

	activerecord/test/cases/associations/has_many_associations_test.rb
  • Loading branch information
drogus committed May 17, 2012
1 parent e3033e3 commit 0f43592
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Expand Up @@ -481,6 +481,8 @@ def replace_records(new_target, original_target)
raise RecordNotSaved, "Failed to replace #{reflection.name} because one or more of the " \ raise RecordNotSaved, "Failed to replace #{reflection.name} because one or more of the " \
"new records could not be saved." "new records could not be saved."
end end

new_target
end end


def concat_records(records) def concat_records(records)
Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/associations/has_many_associations_test.rb
Expand Up @@ -1686,4 +1686,16 @@ def test_replace
assert_equal [bulb2], car.bulbs assert_equal [bulb2], car.bulbs
assert_equal [bulb2], car.reload.bulbs assert_equal [bulb2], car.reload.bulbs
end end

def test_replace_returns_new_target
car = Car.create(:name => 'honda')
bulb1 = car.bulbs.create
bulb2 = car.bulbs.create
bulb3 = Bulb.create

assert_equal [bulb1, bulb2], car.bulbs
result = car.bulbs.replace([bulb1, bulb3])
assert_equal [bulb1, bulb3], car.bulbs
assert_equal [bulb1, bulb3], result
end
end end

0 comments on commit 0f43592

Please sign in to comment.