diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2013-11-01 17:28:05 -0700 |
---|---|---|
committer | Guillermo Iguaran <guilleiguaran@gmail.com> | 2013-11-01 17:28:05 -0700 |
commit | c2b5a8e61ba0f35015e6ac949a5c8fce2042a1f2 (patch) | |
tree | e8ac76013d192271e786d749229799a84c74249e /actionpack/test/controller | |
parent | 1918b12c0429caec2a6134ac5e5b42ade103fe90 (diff) | |
parent | b3f894c5282244b41221f98dfac5296cea5a4485 (diff) | |
download | rails-c2b5a8e61ba0f35015e6ac949a5c8fce2042a1f2.tar.gz rails-c2b5a8e61ba0f35015e6ac949a5c8fce2042a1f2.tar.bz2 rails-c2b5a8e61ba0f35015e6ac949a5c8fce2042a1f2.zip |
Merge pull request #9660 from sebasoga/change_strong_parameters_require_behaviour
Change ActionController::Parameters#require behavior when value is empty
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/parameters/parameters_require_test.rb | 8 | ||||
-rw-r--r-- | actionpack/test/controller/required_params_test.rb | 19 |
2 files changed, 26 insertions, 1 deletions
diff --git a/actionpack/test/controller/parameters/parameters_require_test.rb b/actionpack/test/controller/parameters/parameters_require_test.rb index bdaba8d2d8..21b3eaa6b5 100644 --- a/actionpack/test/controller/parameters/parameters_require_test.rb +++ b/actionpack/test/controller/parameters/parameters_require_test.rb @@ -2,8 +2,14 @@ require 'abstract_unit' require 'action_controller/metal/strong_parameters' class ParametersRequireTest < ActiveSupport::TestCase - test "required parameters must be present not merely not nil" do + test "required parameters must be present" do assert_raises(ActionController::ParameterMissing) do + ActionController::Parameters.new(name: {}).require(:person) + end + end + + test "required parameters can't be blank" do + assert_raises(ActionController::EmptyParameter) do ActionController::Parameters.new(person: {}).require(:person) end end diff --git a/actionpack/test/controller/required_params_test.rb b/actionpack/test/controller/required_params_test.rb index 343d57c300..b27069140b 100644 --- a/actionpack/test/controller/required_params_test.rb +++ b/actionpack/test/controller/required_params_test.rb @@ -5,6 +5,11 @@ class BooksController < ActionController::Base params.require(:book).require(:name) head :ok end + + def update + params.require(:book) + head :ok + end end class ActionControllerRequiredParamsTest < ActionController::TestCase @@ -20,6 +25,20 @@ class ActionControllerRequiredParamsTest < ActionController::TestCase end end + test "empty required parameters will raise an exception" do + assert_raise ActionController::EmptyParameter do + put :update, {book: {}} + end + + assert_raise ActionController::EmptyParameter do + put :update, {book: ''} + end + + assert_raise ActionController::EmptyParameter do + put :update, {book: nil} + end + end + test "required parameters that are present will not raise" do post :create, { book: { name: "Mjallo!" } } assert_response :ok |