Skip to content
Browse files

Rename the configuration to raise_on_unpermitted_parameters

Also changed the exception to UnpermittedParameters
  • Loading branch information...
1 parent 58f5267 commit 1401f96492d7fc7ea0688c1d4b7f0232d2f34eb6 @rafaelfranca rafaelfranca committed Jan 5, 2013
View
18 actionpack/lib/action_controller/metal/strong_parameters.rb
@@ -20,17 +20,17 @@ def initialize(param) # :nodoc:
end
end
- # Raised when a supplied parameter is not expected.
+ # Raised when a supplied parameter is not permitted.
#
# params = ActionController::Parameters.new(a: "123", b: "456")
# params.permit(:c)
- # # => ActionController::UnexpectedParameter: found unexpected keys: a, b
- class UnexpectedParameters < IndexError
+ # # => ActionController::UnpermittedParameters: found unpermitted keys: a, b
+ class UnpermittedParameters < IndexError
attr_reader :params
def initialize(params)
@params = params
- super("found unexpected keys: #{params.join(", ")}")
+ super("found unpermitted keys: #{params.join(", ")}")
end
end
@@ -80,7 +80,7 @@ def initialize(params)
# params["key"] # => "value"
class Parameters < ActiveSupport::HashWithIndifferentAccess
cattr_accessor :permit_all_parameters, instance_accessor: false
- cattr_accessor :raise_on_unexpected, instance_accessor: false
+ cattr_accessor :raise_on_unpermitted_parameters, instance_accessor: false
# Returns a new instance of <tt>ActionController::Parameters</tt>.
# Also, sets the +permitted+ attribute to the default value of
@@ -238,10 +238,10 @@ def permit(*filters)
end
end
- if Parameters.raise_on_unexpected
- unexpected_keys = self.keys - params.keys
- if unexpected_keys.any?
- raise ActionController::UnexpectedParameters.new(unexpected_keys)
+ if Parameters.raise_on_unpermitted_parameters
+ unpermitted_keys = self.keys - params.keys
+ if unpermitted_keys.any?
+ raise ActionController::UnpermittedParameters.new(unpermitted_keys)
end
end
View
6 actionpack/lib/action_controller/railtie.rb
@@ -20,8 +20,10 @@ class Railtie < Rails::Railtie #:nodoc:
end
initializer "action_controller.parameters_config" do |app|
- ActionController::Parameters.permit_all_parameters = app.config.action_controller.delete(:permit_all_parameters) { false }
- ActionController::Parameters.raise_on_unexpected = app.config.action_controller.delete(:raise_on_unexpected_params) { Rails.env.test? || Rails.env.development? }
+ options = app.config.action_controller
+
+ ActionController::Parameters.permit_all_parameters = options.delete(:permit_all_parameters) { false }
+ ActionController::Parameters.raise_on_unpermitted_parameters = options.delete(:raise_on_unpermitted_parameters) { Rails.env.test? || Rails.env.development? }
end
initializer "action_controller.set_configs" do |app|
View
8 ...eters/raise_on_unpermitted_params_test.rb → ...s/raise_on_unpermitted_parameters_test.rb
@@ -1,13 +1,13 @@
require 'abstract_unit'
require 'action_controller/metal/strong_parameters'
-class RaiseOnUnpermittedParamsTest < ActiveSupport::TestCase
+class RaiseOnUnpermittedParametersTest < ActiveSupport::TestCase
def setup
- ActionController::Parameters.raise_on_unexpected = true
+ ActionController::Parameters.raise_on_unpermitted_parameters = true
end
def teardown
- ActionController::Parameters.raise_on_unexpected = false
+ ActionController::Parameters.raise_on_unpermitted_parameters = false
end
test "raises on unexpected params" do
@@ -30,4 +30,4 @@ def teardown
params.permit(book: [:pages])
end
end
-end
+end
View
18 railties/test/application/configuration_test.rb
@@ -567,7 +567,7 @@ def create
assert_equal 'permitted', last_response.body
end
- test "config.action_controller.raise_on_unexpected_params = true" do
+ test "config.action_controller.raise_on_unpermitted_parameters = true" do
app_file 'app/controllers/posts_controller.rb', <<-RUBY
class PostsController < ActionController::Base
def create
@@ -580,39 +580,39 @@ def create
routes.prepend do
resources :posts
end
- config.action_controller.raise_on_unexpected_params = true
+ config.action_controller.raise_on_unpermitted_parameters = true
RUBY
require "#{app_path}/config/environment"
- assert_equal true, ActionController::Parameters.raise_on_unexpected
+ assert_equal true, ActionController::Parameters.raise_on_unpermitted_parameters
post "/posts", {post: {"title" =>"zomg"}}
assert_match /We're sorry, but something went wrong/, last_response.body
end
- test "config.action_controller.raise_on_unexpected_params is true by default on development" do
+ test "config.action_controller.raise_on_unpermitted_parameters is true by default on development" do
ENV["RAILS_ENV"] = "development"
require "#{app_path}/config/environment"
- assert_equal true, ActionController::Parameters.raise_on_unexpected
+ assert_equal true, ActionController::Parameters.raise_on_unpermitted_parameters
end
- test "config.action_controller.raise_on_unexpected_params is true by defaul on test" do
+ test "config.action_controller.raise_on_unpermitted_parameters is true by defaul on test" do
ENV["RAILS_ENV"] = "test"
require "#{app_path}/config/environment"
- assert_equal true, ActionController::Parameters.raise_on_unexpected
+ assert_equal true, ActionController::Parameters.raise_on_unpermitted_parameters
end
- test "config.action_controller.raise_on_unexpected_params is false by default on production" do
+ test "config.action_controller.raise_on_unpermitted_parameters is false by default on production" do
ENV["RAILS_ENV"] = "production"
require "#{app_path}/config/environment"
- assert_equal false, ActionController::Parameters.raise_on_unexpected
+ assert_equal false, ActionController::Parameters.raise_on_unpermitted_parameters
end
test "config.action_dispatch.ignore_accept_header" do

0 comments on commit 1401f96

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