diff --git a/Gemfile.lock b/Gemfile.lock index 8d188ea..337adec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - strong_parameters (0.1.1) + strong_parameters (0.1.2) actionpack (>= 3.2.0) activemodel (>= 3.2.0) @@ -29,7 +29,7 @@ GEM hike (1.2.1) i18n (0.6.0) journey (1.0.3) - multi_json (1.1.0) + multi_json (1.2.0) rack (1.4.1) rack-cache (1.2) rack (>= 0.4) diff --git a/README.rdoc b/README.rdoc index 34d0f9b..8c719bf 100644 --- a/README.rdoc +++ b/README.rdoc @@ -25,7 +25,7 @@ In addition, parameters can be marked as required and flow through a predefined # since you'll be able to reuse the same permit list between create and update. Also, you # can specialize this method with per-user checking of permissible attributes. def person_params - params.required(:person).permit(:name, :age) + params.require(:person).permit(:name, :age) end end diff --git a/lib/action_controller/parameters.rb b/lib/action_controller/parameters.rb index a144853..daaf901 100644 --- a/lib/action_controller/parameters.rb +++ b/lib/action_controller/parameters.rb @@ -26,9 +26,11 @@ def permit! self end - def required(key) + def require(key) self[key].presence || raise(ActionController::ParameterMissing.new(key)) end + + alias :required :require def permit(*filters) params = self.class.new diff --git a/lib/strong_parameters/version.rb b/lib/strong_parameters/version.rb index 9255ff3..2ca3081 100644 --- a/lib/strong_parameters/version.rb +++ b/lib/strong_parameters/version.rb @@ -1,3 +1,3 @@ module StrongParameters - VERSION = "0.1.2" + VERSION = "0.1.3" end diff --git a/test/action_controller_required_params_test.rb b/test/action_controller_required_params_test.rb index 70b9daa..c4a034d 100644 --- a/test/action_controller_required_params_test.rb +++ b/test/action_controller_required_params_test.rb @@ -2,7 +2,7 @@ class BooksController < ActionController::Base def create - params.required(:book).required(:name) + params.require(:book).require(:name) head :ok end end diff --git a/test/parameters_require_test.rb b/test/parameters_require_test.rb index f5b5037..d210635 100644 --- a/test/parameters_require_test.rb +++ b/test/parameters_require_test.rb @@ -4,7 +4,7 @@ class ParametersRequireTest < ActiveSupport::TestCase test "required parameters must be present not merely not nil" do assert_raises(ActionController::ParameterMissing) do - ActionController::Parameters.new(person: {}).required(:person) + ActionController::Parameters.new(person: {}).require(:person) end end end