aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorGannon McGibbon <gannon.mcgibbon@gmail.com>2019-05-13 13:10:58 -0400
committerGitHub <noreply@github.com>2019-05-13 13:10:58 -0400
commit7edb63009ed64bd227eaffd4ec1d7e662eb96f62 (patch)
tree6a7f17c6c05cd4887a0fd847c0bee2dc857b0561 /actionpack/test
parentb2b634137402a82a7dfd60b5646dbd0860a822ca (diff)
parent858c63a0a401ac76e7c59069cea3700181d30748 (diff)
downloadrails-7edb63009ed64bd227eaffd4ec1d7e662eb96f62.tar.gz
rails-7edb63009ed64bd227eaffd4ec1d7e662eb96f62.tar.bz2
rails-7edb63009ed64bd227eaffd4ec1d7e662eb96f62.zip
Merge pull request #36127 from st0012/fix_non_num_keys
Improve nested parameter resolving - continuation of 29888
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/parameters/nested_parameters_permit_test.rb30
1 files changed, 28 insertions, 2 deletions
diff --git a/actionpack/test/controller/parameters/nested_parameters_permit_test.rb b/actionpack/test/controller/parameters/nested_parameters_permit_test.rb
index 1403e224c0..6243b5c51b 100644
--- a/actionpack/test/controller/parameters/nested_parameters_permit_test.rb
+++ b/actionpack/test/controller/parameters/nested_parameters_permit_test.rb
@@ -125,7 +125,7 @@ class NestedParametersPermitTest < ActiveSupport::TestCase
assert_nil permitted[:book][:genre]
end
- test "fields_for-style nested params" do
+ test "nested params with numeric keys" do
params = ActionController::Parameters.new(
book: {
authors_attributes: {
@@ -150,7 +150,33 @@ class NestedParametersPermitTest < ActiveSupport::TestCase
assert_filtered_out permitted[:book][:authors_attributes]["0"], :age_of_death
end
- test "fields_for-style nested params with negative numbers" do
+ test "nested params with non_numeric keys" do
+ params = ActionController::Parameters.new(
+ book: {
+ authors_attributes: {
+ '0': { name: "William Shakespeare", age_of_death: "52" },
+ '1': { name: "Unattributed Assistant" },
+ '2': "Not a hash",
+ 'new_record': { name: "Some name" }
+ }
+ })
+ permitted = params.permit book: { authors_attributes: [ :name ] }
+
+ assert_not_nil permitted[:book][:authors_attributes]["0"]
+ assert_not_nil permitted[:book][:authors_attributes]["1"]
+
+ assert_nil permitted[:book][:authors_attributes]["2"]
+ assert_nil permitted[:book][:authors_attributes]["new_record"]
+ assert_equal "William Shakespeare", permitted[:book][:authors_attributes]["0"][:name]
+ assert_equal "Unattributed Assistant", permitted[:book][:authors_attributes]["1"][:name]
+
+ assert_equal(
+ { "book" => { "authors_attributes" => { "0" => { "name" => "William Shakespeare" }, "1" => { "name" => "Unattributed Assistant" } } } },
+ permitted.to_h
+ )
+ end
+
+ test "nested params with negative numeric keys" do
params = ActionController::Parameters.new(
book: {
authors_attributes: {