aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2012-09-01 02:30:07 -0500
committerGuillermo Iguaran <guilleiguaran@gmail.com>2012-09-16 23:58:21 -0500
commit91bcebbdef0e31d38622785a064d023272f712db (patch)
treeb629daa30db373d75dd2c3c760f572d0d706fb44 /actionpack/test
parent1aaf4490b29afc99cf19b18c4edbb1f28e6c37f5 (diff)
downloadrails-91bcebbdef0e31d38622785a064d023272f712db.tar.gz
rails-91bcebbdef0e31d38622785a064d023272f712db.tar.bz2
rails-91bcebbdef0e31d38622785a064d023272f712db.zip
Support fields_for attributes, which may have numeric symbols as hash keys
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/parameters/nested_parameters_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/actionpack/test/controller/parameters/nested_parameters_test.rb b/actionpack/test/controller/parameters/nested_parameters_test.rb
index 16e8d2e528..ea67126cc5 100644
--- a/actionpack/test/controller/parameters/nested_parameters_test.rb
+++ b/actionpack/test/controller/parameters/nested_parameters_test.rb
@@ -92,4 +92,22 @@ class NestedParametersTest < ActiveSupport::TestCase
permitted = params.permit book: { genre: :type }
assert_nil permitted[:book][:genre]
end
+
+ test "fields_for-style nested params" do
+ params = ActionController::Parameters.new({
+ book: {
+ authors_attributes: {
+ :'0' => { name: 'William Shakespeare', age_of_death: '52' },
+ :'-1' => { name: 'Unattributed Assistant' }
+ }
+ }
+ })
+ 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]['0'][:age_of_death]
+ assert_equal 'William Shakespeare', permitted[:book][:authors_attributes]['0'][:name]
+ assert_equal 'Unattributed Assistant', permitted[:book][:authors_attributes]['-1'][:name]
+ end
end