Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

hash filters should be accessed with symbols or strings #64

Merged
merged 2 commits into from

2 participants

@frodsan

No description provided.

Francesco Rodriguez update dependencies 3e363d7
@rafaelfranca

@frodsan send to Rails first.

@rafaelfranca

Could you update the tests here too?

@frodsan

done. I will wait to Travis though :)

@rafaelfranca rafaelfranca merged commit 2df13a0 into rails:master
@frodsan

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 30, 2012
  1. update dependencies

    Francesco Rodriguez authored
  2. hash filters should be accessed with symbols or strings

    Francesco Rodriguez authored
This page is out of date. Refresh to see the latest.
View
3  Gemfile.lock
@@ -63,6 +63,7 @@ PLATFORMS
ruby
DEPENDENCIES
- mocha
+ mocha (~> 0.12.0)
rake
+ rdoc
strong_parameters!
View
2  lib/action_controller/parameters.rb
@@ -46,6 +46,8 @@ def permit(*filters)
params[filter] = self[filter] if has_key?(filter)
keys.grep(/\A#{Regexp.escape(filter.to_s)}\(\d+[if]?\)\z/).each { |key| params[key] = self[key] }
when Hash then
+ filter = filter.with_indifferent_access
+
self.slice(*filter.keys).each do |key, value|
return unless value
View
27 test/nested_parameters_test.rb
@@ -32,6 +32,31 @@ class NestedParametersTest < ActiveSupport::TestCase
assert_nil permitted[:magazine]
end
+ test "permitted nested parameters with a string or a symbol as a key" do
+ params = ActionController::Parameters.new({
+ :book => {
+ 'authors' => [
+ { :name => "William Shakespeare", :born => "1564-04-26" },
+ { :name => "Christopher Marlowe" }
+ ]
+ }
+ })
+
+ permitted = params.permit :book => [ { 'authors' => [ :name ] } ]
+
+ assert_equal "William Shakespeare", permitted[:book]['authors'][0][:name]
+ assert_equal "William Shakespeare", permitted[:book][:authors][0][:name]
+ assert_equal "Christopher Marlowe", permitted[:book]['authors'][1][:name]
+ assert_equal "Christopher Marlowe", permitted[:book][:authors][1][:name]
+
+ permitted = params.permit :book => [ { :authors => [ :name ] } ]
+
+ assert_equal "William Shakespeare", permitted[:book]['authors'][0][:name]
+ assert_equal "William Shakespeare", permitted[:book][:authors][0][:name]
+ assert_equal "Christopher Marlowe", permitted[:book]['authors'][1][:name]
+ assert_equal "Christopher Marlowe", permitted[:book][:authors][1][:name]
+ end
+
test "nested arrays with strings" do
params = ActionController::Parameters.new({
:book => {
@@ -112,7 +137,7 @@ class NestedParametersTest < ActiveSupport::TestCase
end
test "fields_for_style_nested_params with negative numbers" do
- params = ActionController::Parameters.new({
+ params = ActionController::Parameters.new({
:book => {
:authors_attributes => {
:'-1' => { :name => 'William Shakespeare', :age_of_death => '52' },
Something went wrong with that request. Please try again.