aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-07-18 08:42:29 -0400
committerSean Griffin <sean@thoughtbot.com>2015-07-18 08:44:24 -0400
commit68af63618223c238468af1afb093eb4ccc706761 (patch)
treec265cfe4ae7322445bdfe3bc6aae197086477bd1 /activerecord/test
parentc7449a2269c3d8b3f68b93401ab7a4fc524da918 (diff)
downloadrails-68af63618223c238468af1afb093eb4ccc706761.tar.gz
rails-68af63618223c238468af1afb093eb4ccc706761.tar.bz2
rails-68af63618223c238468af1afb093eb4ccc706761.zip
Ensure that `ActionController::Parameters` can still be passed to AR
Since nested hashes are also instances of `ActionController::Parameters`, and we're explicitly looking to work with a hash for nested attributes, this caused breakage in several points. This is the minimum viable fix for the issue (and one that I'm not terribly fond of). I can't think of a better place to handle this at the moment. I'd prefer to use some sort of solution that doesn't special case AC::Parameters, but we can't use something like `to_h` or `to_a` since `Enumerable` adds both. While I've added a trivial test case for verifying this fix in isolation, we really need better integration coverage to prevent regressions like this in the future. We don't actually have a lot of great places for integration coverage at the moment, so I'm deferring it for now. Fixes #20922.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index d72225f3d3..933dfac806 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -1064,4 +1064,27 @@ class TestHasManyAutosaveAssociationWhichItselfHasAutosaveAssociations < ActiveR
assert_not part.valid?
assert_equal ["Ship name can't be blank"], part.errors.full_messages
end
+
+ class ProtectedParameters
+ def initialize(hash)
+ @hash = hash
+ end
+
+ def permitted?
+ true
+ end
+
+ def to_h
+ @hash
+ end
+ end
+
+ test "strong params style objects can be assigned" do
+ params = { name: "Stern", ship_attributes:
+ ProtectedParameters.new(name: "The Black Rock") }
+ part = ShipPart.new(params)
+
+ assert_equal "Stern", part.name
+ assert_equal "The Black Rock", part.ship.name
+ end
end