diff options
author | L.Fexon <lfexon@partners.org> | 2017-08-01 14:02:41 -0400 |
---|---|---|
committer | st0012 <stan001212@gmail.com> | 2019-05-13 15:03:27 +0800 |
commit | 858c63a0a401ac76e7c59069cea3700181d30748 (patch) | |
tree | 4951bf54789abca4819414ab734417d17ff9232a /actionpack/test | |
parent | e84ee74854876be00c3d072182af4c936c7d303c (diff) | |
download | rails-858c63a0a401ac76e7c59069cea3700181d30748.tar.gz rails-858c63a0a401ac76e7c59069cea3700181d30748.tar.bz2 rails-858c63a0a401ac76e7c59069cea3700181d30748.zip |
fixed usage of Parameters when a non-numeric key exists
test for non-numeric key in nested attributes
test: extra blank line between tests removed
test for non-numeric key fixed (by Daniel)
Update according to feedback
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/parameters/nested_parameters_permit_test.rb | 30 |
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: { |