Skip to content
This repository
Browse code

Use #require instead of #required for parity with #permit -- #require…

…d is an alias until v1.0
  • Loading branch information...
commit 1e238a2170badcb9a5212e642220d7239246e9b4 1 parent dac840f
David Heinemeier Hansson dhh authored
4 Gemfile.lock
... ... @@ -1,7 +1,7 @@
1 1 PATH
2 2 remote: .
3 3 specs:
4   - strong_parameters (0.1.1)
  4 + strong_parameters (0.1.2)
5 5 actionpack (>= 3.2.0)
6 6 activemodel (>= 3.2.0)
7 7
@@ -29,7 +29,7 @@ GEM
29 29 hike (1.2.1)
30 30 i18n (0.6.0)
31 31 journey (1.0.3)
32   - multi_json (1.1.0)
  32 + multi_json (1.2.0)
33 33 rack (1.4.1)
34 34 rack-cache (1.2)
35 35 rack (>= 0.4)
2  README.rdoc
Source Rendered
@@ -25,7 +25,7 @@ In addition, parameters can be marked as required and flow through a predefined
25 25 # since you'll be able to reuse the same permit list between create and update. Also, you
26 26 # can specialize this method with per-user checking of permissible attributes.
27 27 def person_params
28   - params.required(:person).permit(:name, :age)
  28 + params.require(:person).permit(:name, :age)
29 29 end
30 30 end
31 31
4 lib/action_controller/parameters.rb
@@ -26,9 +26,11 @@ def permit!
26 26 self
27 27 end
28 28
29   - def required(key)
  29 + def require(key)
30 30 self[key].presence || raise(ActionController::ParameterMissing.new(key))
31 31 end
  32 +
  33 + alias :required :require
32 34
33 35 def permit(*filters)
34 36 params = self.class.new
2  lib/strong_parameters/version.rb
... ... @@ -1,3 +1,3 @@
1 1 module StrongParameters
2   - VERSION = "0.1.2"
  2 + VERSION = "0.1.3"
3 3 end
2  test/action_controller_required_params_test.rb
@@ -2,7 +2,7 @@
2 2
3 3 class BooksController < ActionController::Base
4 4 def create
5   - params.required(:book).required(:name)
  5 + params.require(:book).require(:name)
6 6 head :ok
7 7 end
8 8 end
2  test/parameters_require_test.rb
@@ -4,7 +4,7 @@
4 4 class ParametersRequireTest < ActiveSupport::TestCase
5 5 test "required parameters must be present not merely not nil" do
6 6 assert_raises(ActionController::ParameterMissing) do
7   - ActionController::Parameters.new(person: {}).required(:person)
  7 + ActionController::Parameters.new(person: {}).require(:person)
8 8 end
9 9 end
10 10 end

0 comments on commit 1e238a2

Please sign in to comment.
Something went wrong with that request. Please try again.