diff options
author | Prathamesh Sonpatki <csonpatki@gmail.com> | 2016-02-24 12:48:39 +0530 |
---|---|---|
committer | Prathamesh Sonpatki <csonpatki@gmail.com> | 2016-02-24 13:55:37 +0530 |
commit | 5f59c10471fee7bca43f65bb2bc776ed047715b6 (patch) | |
tree | a396b7393481625ad9f50ed504a8455854e02988 /actionpack | |
parent | 22db455dbe9c26fe6d723cac0758705d9943ea4b (diff) | |
download | rails-5f59c10471fee7bca43f65bb2bc776ed047715b6.tar.gz rails-5f59c10471fee7bca43f65bb2bc776ed047715b6.tar.bz2 rails-5f59c10471fee7bca43f65bb2bc776ed047715b6.zip |
Show permitted flag in the output of AC::Parameters#inspect
- Fixes #23822.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 24 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/parameters/accessors_test.rb | 16 |
3 files changed, 34 insertions, 8 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 4425a90798..cc336c0a02 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,4 +1,20 @@ -* Update session to have indifferent access across multiple requests +* Show `permitted` flag in the output of ActionController::Parameters#inspect. + + Before: + >> a = ActionController::Parameters.new(foo: 'bar') + => <ActionController::Parameters {"foo"=>"bar"}> + + After: + >> a = ActionController::Parameters.new(foo: 'bar') + => <ActionController::Parameters {"foo"=>"bar"} permitted: false> + >> a.permit(:foo) + => <ActionController::Parameters {"foo"=>"bar"} permitted: true> + + Fixes #23822. + + *Prathamesh Sonpatki* + +* Update session to have indifferent access across multiple requests. session[:deep][:hash] = "Magic" @@ -46,13 +62,13 @@ end end ``` - + Passing `as: :json` to integration test request helpers will set the format, content type and encode the parameters as JSON. - + Then on the response side, `parsed_body` will parse the body according to the content type the response has. - + Currently JSON is the only supported MIME type. Add your own with `ActionDispatch::IntegrationTest.register_encoder`. diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 25ec3cf5b6..a01110d474 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -579,7 +579,7 @@ module ActionController end def inspect - "<#{self.class} #{@parameters}>" + "<#{self.class} #{@parameters} permitted: #{@permitted}>" end def method_missing(method_sym, *args, &block) diff --git a/actionpack/test/controller/parameters/accessors_test.rb b/actionpack/test/controller/parameters/accessors_test.rb index 4ef5bed30d..cea265f9ab 100644 --- a/actionpack/test/controller/parameters/accessors_test.rb +++ b/actionpack/test/controller/parameters/accessors_test.rb @@ -4,6 +4,8 @@ require 'active_support/core_ext/hash/transform_values' class ParametersAccessorsTest < ActiveSupport::TestCase setup do + ActionController::Parameters.permit_all_parameters = false + @params = ActionController::Parameters.new( person: { age: '32', @@ -176,12 +178,20 @@ class ParametersAccessorsTest < ActiveSupport::TestCase assert(@params != false) end - test "inspect shows both class name and parameters" do + test "inspect shows both class name, parameters and permitted flag" do assert_equal( '<ActionController::Parameters {"person"=>{"age"=>"32", '\ - '"name"=>{"first"=>"David", "last"=>"Heinemeier Hansson"}, ' \ - '"addresses"=>[{"city"=>"Chicago", "state"=>"Illinois"}]}}>', + '"name"=>{"first"=>"David", "last"=>"Heinemeier Hansson"}, ' \ + '"addresses"=>[{"city"=>"Chicago", "state"=>"Illinois"}]}} permitted: false>', @params.inspect ) end + + test "inspect prints updated permitted flag in the output" do + assert_match(/permitted: false/, @params.inspect) + + @params.permit! + + assert_match(/permitted: true/, @params.inspect) + end end |