aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/nested_attributes_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-07-18 13:21:06 -0500
committerSean Griffin <sean@seantheprogrammer.com>2015-07-18 13:21:06 -0500
commit3f1c5d39c01e13bcf9e34865f00ded56a3a321fc (patch)
tree8dadb882509bedd79835122cbfe12ba4e1394749 /activerecord/test/cases/nested_attributes_test.rb
parent7550f0a016ee6647aaa76c0c0ae30bebc3867288 (diff)
parentb5d4dd47deaae27e8f362bb9636246c5b4c56e5c (diff)
downloadrails-3f1c5d39c01e13bcf9e34865f00ded56a3a321fc.tar.gz
rails-3f1c5d39c01e13bcf9e34865f00ded56a3a321fc.tar.bz2
rails-3f1c5d39c01e13bcf9e34865f00ded56a3a321fc.zip
Merge pull request #20932 from twalpole/collection_association_parameters
Ensure that 'ActionController::Parameters' can still be passed to AR …
Diffstat (limited to 'activerecord/test/cases/nested_attributes_test.rb')
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index 933dfac806..b8a0401fe3 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -1074,12 +1074,16 @@ class TestHasManyAutosaveAssociationWhichItselfHasAutosaveAssociations < ActiveR
true
end
+ def [](key)
+ @hash[key]
+ end
+
def to_h
@hash
end
end
- test "strong params style objects can be assigned" do
+ test "strong params style objects can be assigned for singular associations" do
params = { name: "Stern", ship_attributes:
ProtectedParameters.new(name: "The Black Rock") }
part = ShipPart.new(params)
@@ -1087,4 +1091,12 @@ class TestHasManyAutosaveAssociationWhichItselfHasAutosaveAssociations < ActiveR
assert_equal "Stern", part.name
assert_equal "The Black Rock", part.ship.name
end
+
+ test "strong params style objects can be assigned for collection associations" do
+ params = { trinkets_attributes: ProtectedParameters.new("0" => ProtectedParameters.new(name: "Necklace"), "1" => ProtectedParameters.new(name: "Spoon")) }
+ part = ShipPart.new(params)
+
+ assert_equal "Necklace", part.trinkets[0].name
+ assert_equal "Spoon", part.trinkets[1].name
+ end
end