Skip to content

Commit

Permalink
test-case to prevent regressions on Association#build with an Array.
Browse files Browse the repository at this point in the history
Closes #11026
  • Loading branch information
senny committed Jun 22, 2013
1 parent 763635e commit 951bde4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions activerecord/test/cases/associations/has_many_associations_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ def test_building_the_associated_object_with_an_unrelated_type
assert_raise(ActiveRecord::SubclassNotFound) { firm.companies.build(:type => "Account") } assert_raise(ActiveRecord::SubclassNotFound) { firm.companies.build(:type => "Account") }
end end


test "building the association with an array" do
speedometer = Speedometer.new(speedometer_id: "a")
data = [{name: "first"}, {name: "second"}]
speedometer.minivans.build(data)

assert_equal 2, speedometer.minivans.size
assert speedometer.save
assert_equal ["first", "second"], speedometer.reload.minivans.map(&:name)
end

def test_association_keys_bypass_attribute_protection def test_association_keys_bypass_attribute_protection
car = Car.create(:name => 'honda') car = Car.create(:name => 'honda')


Expand Down

0 comments on commit 951bde4

Please sign in to comment.