diff options
author | Sergio Romano <sromano@stelladot.com> | 2014-06-13 14:42:38 -0300 |
---|---|---|
committer | Sergio Romano <sromano@stelladot.com> | 2014-06-13 14:42:38 -0300 |
commit | 540d1535316d6ecbe755ee66dfcbc23dc0bde3a5 (patch) | |
tree | 4aa86144d8bb15ad872860ed82ae88513c869e5c | |
parent | 0bfdf4087047cf7ef72fa10d07baecadefc53b70 (diff) | |
download | rails-540d1535316d6ecbe755ee66dfcbc23dc0bde3a5.tar.gz rails-540d1535316d6ecbe755ee66dfcbc23dc0bde3a5.tar.bz2 rails-540d1535316d6ecbe755ee66dfcbc23dc0bde3a5.zip |
ActionController::Parameters#require now accepts FalseClass values
Fixes #15685.
-rw-r--r-- | actionpack/CHANGELOG.md | 6 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 1 | ||||
-rw-r--r-- | actionpack/test/controller/required_params_test.rb | 18 |
3 files changed, 24 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 5474f5dd58..7df0f8c6ae 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,9 @@ +* ActionController::Parameters#require now accepts FalseClass values + + Fixes #15685. + + *Sergio Romano* + * With authorization header `Authorization: Token token=`, `authenticate` now recognize token as nil, instead of "token". diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index c3c3e4c4f1..0fc5680dcc 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -184,6 +184,7 @@ module ActionController # ActionController::Parameters.new(person: {}).require(:person) # # => ActionController::ParameterMissing: param not found: person def require(key) + return false if self[key].is_a? FalseClass self[key].presence || raise(ParameterMissing.new(key)) end diff --git a/actionpack/test/controller/required_params_test.rb b/actionpack/test/controller/required_params_test.rb index 25d0337212..da80888b96 100644 --- a/actionpack/test/controller/required_params_test.rb +++ b/actionpack/test/controller/required_params_test.rb @@ -24,10 +24,26 @@ class ActionControllerRequiredParamsTest < ActionController::TestCase post :create, { book: { name: "Mjallo!" } } assert_response :ok end + + test "required parameters with false value will not raise" do + post :create, { book: { name: false } } + assert_response :ok + end end class ParametersRequireTest < ActiveSupport::TestCase - test "required parameters must be present not merely not nil" do + + test "required parameters should accept and return false value" do + assert(!ActionController::Parameters.new(person: false).require(:person)) + end + + test "required parameters must not be nil" do + assert_raises(ActionController::ParameterMissing) do + ActionController::Parameters.new(person: nil).require(:person) + end + end + + test "required parameters must not be empty" do assert_raises(ActionController::ParameterMissing) do ActionController::Parameters.new(person: {}).require(:person) end |