aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/parameters
diff options
context:
space:
mode:
authorThomas Drake-Brockman <thom@sfedb.com>2013-01-05 15:46:38 +0800
committerThomas Drake-Brockman <thom@sfedb.com>2013-01-05 15:46:38 +0800
commit08578bb40a66aa3c73edab8eef795da6647ed694 (patch)
tree8de50a0484d5b62015f9f0e717b18fc57d5b269e /actionpack/test/controller/parameters
parentc9402c0258e85f125ce7cdc292381eb8b9dcbbe0 (diff)
downloadrails-08578bb40a66aa3c73edab8eef795da6647ed694.tar.gz
rails-08578bb40a66aa3c73edab8eef795da6647ed694.tar.bz2
rails-08578bb40a66aa3c73edab8eef795da6647ed694.zip
Allow developers to enable raising of exception when unexpected params are provided.
Diffstat (limited to 'actionpack/test/controller/parameters')
-rw-r--r--actionpack/test/controller/parameters/raise_on_unpermitted_params_test.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/actionpack/test/controller/parameters/raise_on_unpermitted_params_test.rb b/actionpack/test/controller/parameters/raise_on_unpermitted_params_test.rb
new file mode 100644
index 0000000000..51bbc9c1b1
--- /dev/null
+++ b/actionpack/test/controller/parameters/raise_on_unpermitted_params_test.rb
@@ -0,0 +1,33 @@
+require 'abstract_unit'
+require 'action_controller/metal/strong_parameters'
+
+class RaiseOnUnpermittedParamsTest < ActiveSupport::TestCase
+ def setup
+ ActionController::Parameters.raise_on_unexpected = true
+ end
+
+ def teardown
+ ActionController::Parameters.raise_on_unexpected = false
+ end
+
+ test "raises on unexpected params" do
+ params = ActionController::Parameters.new({
+ book: { pages: 65 },
+ fishing: "Turnips"
+ })
+
+ assert_raises(ActionController::UnexpectedParameters) do
+ params.permit(book: [:pages])
+ end
+ end
+
+ test "raises on unexpected nested params" do
+ params = ActionController::Parameters.new({
+ book: { pages: 65, title: "Green Cats and where to find then." }
+ })
+
+ assert_raises(ActionController::UnexpectedParameters) do
+ params.permit(book: [:pages])
+ end
+ end
+end \ No newline at end of file