Skip to content
This repository has been archived by the owner on Aug 17, 2017. It is now read-only.

Commit

Permalink
Use #require instead of #required for parity with #permit -- #require…
Browse files Browse the repository at this point in the history
…d is an alias until v1.0
  • Loading branch information
dhh committed Mar 29, 2012
1 parent dac840f commit 1e238a2
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions 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)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion lib/action_controller/parameters.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/strong_parameters/version.rb
@@ -1,3 +1,3 @@
module StrongParameters
VERSION = "0.1.2"
VERSION = "0.1.3"
end
2 changes: 1 addition & 1 deletion test/action_controller_required_params_test.rb
Expand Up @@ -2,7 +2,7 @@

class BooksController < ActionController::Base
def create
params.required(:book).required(:name)
params.require(:book).require(:name)
head :ok
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/parameters_require_test.rb
Expand Up @@ -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

0 comments on commit 1e238a2

Please sign in to comment.