aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/parameters
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 19:44:11 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 19:44:11 +0200
commit411ccbdab2608c62aabdb320d52cb02d446bb39c (patch)
tree05671553ac2a23dd1db4d11949c1ac43c3dd1367 /actionpack/test/controller/parameters
parent60b67d76dc1d98e4269aac7705e9d8323eb42942 (diff)
downloadrails-411ccbdab2608c62aabdb320d52cb02d446bb39c.tar.gz
rails-411ccbdab2608c62aabdb320d52cb02d446bb39c.tar.bz2
rails-411ccbdab2608c62aabdb320d52cb02d446bb39c.zip
remove redundant curlies from hash arguments
Diffstat (limited to 'actionpack/test/controller/parameters')
-rw-r--r--actionpack/test/controller/parameters/always_permitted_parameters_test.rb6
-rw-r--r--actionpack/test/controller/parameters/log_on_unpermitted_params_test.rb20
-rw-r--r--actionpack/test/controller/parameters/multi_parameter_attributes_test.rb6
-rw-r--r--actionpack/test/controller/parameters/nested_parameters_permit_test.rb60
-rw-r--r--actionpack/test/controller/parameters/parameters_permit_test.rb4
-rw-r--r--actionpack/test/controller/parameters/raise_on_unpermitted_params_test.rb10
6 files changed, 35 insertions, 71 deletions
diff --git a/actionpack/test/controller/parameters/always_permitted_parameters_test.rb b/actionpack/test/controller/parameters/always_permitted_parameters_test.rb
index 40e2f5152a..9c9749c037 100644
--- a/actionpack/test/controller/parameters/always_permitted_parameters_test.rb
+++ b/actionpack/test/controller/parameters/always_permitted_parameters_test.rb
@@ -19,10 +19,8 @@ class AlwaysPermittedParametersTest < ActiveSupport::TestCase
end
test "permits parameters that are whitelisted" do
- params = ActionController::Parameters.new({
- book: { pages: 65 },
- format: "json"
- })
+ params = ActionController::Parameters.new( book: { pages: 65 },
+ format: "json")
permitted = params.permit book: [:pages]
assert permitted.permitted?
end
diff --git a/actionpack/test/controller/parameters/log_on_unpermitted_params_test.rb b/actionpack/test/controller/parameters/log_on_unpermitted_params_test.rb
index b1a9b9176c..a6e48b8ded 100644
--- a/actionpack/test/controller/parameters/log_on_unpermitted_params_test.rb
+++ b/actionpack/test/controller/parameters/log_on_unpermitted_params_test.rb
@@ -11,10 +11,8 @@ class LogOnUnpermittedParamsTest < ActiveSupport::TestCase
end
test "logs on unexpected param" do
- params = ActionController::Parameters.new({
- book: { pages: 65 },
- fishing: "Turnips"
- })
+ params = ActionController::Parameters.new( book: { pages: 65 },
+ fishing: "Turnips")
assert_logged("Unpermitted parameter: fishing") do
params.permit(book: [:pages])
@@ -22,11 +20,9 @@ class LogOnUnpermittedParamsTest < ActiveSupport::TestCase
end
test "logs on unexpected params" do
- params = ActionController::Parameters.new({
- book: { pages: 65 },
+ params = ActionController::Parameters.new( book: { pages: 65 },
fishing: "Turnips",
- car: "Mersedes"
- })
+ car: "Mersedes")
assert_logged("Unpermitted parameters: fishing, car") do
params.permit(book: [:pages])
@@ -34,9 +30,7 @@ class LogOnUnpermittedParamsTest < ActiveSupport::TestCase
end
test "logs on unexpected nested param" do
- params = ActionController::Parameters.new({
- book: { pages: 65, title: "Green Cats and where to find then." }
- })
+ params = ActionController::Parameters.new( book: { pages: 65, title: "Green Cats and where to find then." })
assert_logged("Unpermitted parameter: title") do
params.permit(book: [:pages])
@@ -44,9 +38,7 @@ class LogOnUnpermittedParamsTest < ActiveSupport::TestCase
end
test "logs on unexpected nested params" do
- params = ActionController::Parameters.new({
- book: { pages: 65, title: "Green Cats and where to find then.", author: "G. A. Dog" }
- })
+ params = ActionController::Parameters.new( book: { pages: 65, title: "Green Cats and where to find then.", author: "G. A. Dog" })
assert_logged("Unpermitted parameters: title, author") do
params.permit(book: [:pages])
diff --git a/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb b/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb
index 1009f533a4..44e39135a2 100644
--- a/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb
+++ b/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb
@@ -3,8 +3,7 @@ require "action_controller/metal/strong_parameters"
class MultiParameterAttributesTest < ActiveSupport::TestCase
test "permitted multi-parameter attribute keys" do
- params = ActionController::Parameters.new({
- book: {
+ params = ActionController::Parameters.new( book: {
"shipped_at(1i)" => "2012",
"shipped_at(2i)" => "3",
"shipped_at(3i)" => "25",
@@ -15,8 +14,7 @@ class MultiParameterAttributesTest < ActiveSupport::TestCase
"published_at(3i)" => "5",
"price(1)" => "R$",
"price(2f)" => "2.02"
- }
- })
+ })
permitted = params.permit book: [ :shipped_at, :price ]
diff --git a/actionpack/test/controller/parameters/nested_parameters_permit_test.rb b/actionpack/test/controller/parameters/nested_parameters_permit_test.rb
index f3c1caee61..e3f1ba5f0a 100644
--- a/actionpack/test/controller/parameters/nested_parameters_permit_test.rb
+++ b/actionpack/test/controller/parameters/nested_parameters_permit_test.rb
@@ -7,8 +7,7 @@ class NestedParametersPermitTest < ActiveSupport::TestCase
end
test "permitted nested parameters" do
- params = ActionController::Parameters.new({
- book: {
+ params = ActionController::Parameters.new( book: {
title: "Romeo and Juliet",
authors: [{
name: "William Shakespeare",
@@ -26,8 +25,7 @@ class NestedParametersPermitTest < ActiveSupport::TestCase
isbn: "x"
}
},
- magazine: "Mjallo!"
- })
+ magazine: "Mjallo!")
permitted = params.permit book: [ :title, { authors: [ :name ] }, { details: :pages }, :id ]
@@ -45,14 +43,12 @@ class NestedParametersPermitTest < ActiveSupport::TestCase
end
test "permitted nested parameters with a string or a symbol as a key" do
- params = ActionController::Parameters.new({
- book: {
+ params = ActionController::Parameters.new( book: {
"authors" => [
{ name: "William Shakespeare", born: "1564-04-26" },
{ name: "Christopher Marlowe" }
]
- }
- })
+ })
permitted = params.permit book: [ { "authors" => [ :name ] } ]
@@ -70,24 +66,20 @@ class NestedParametersPermitTest < ActiveSupport::TestCase
end
test "nested arrays with strings" do
- params = ActionController::Parameters.new({
- book: {
+ params = ActionController::Parameters.new( book: {
genres: ["Tragedy"]
- }
- })
+ })
permitted = params.permit book: {genres: []}
assert_equal ["Tragedy"], permitted[:book][:genres]
end
test "permit may specify symbols or strings" do
- params = ActionController::Parameters.new({
- book: {
+ params = ActionController::Parameters.new( book: {
title: "Romeo and Juliet",
author: "William Shakespeare"
},
- magazine: "Shakespeare Today"
- })
+ magazine: "Shakespeare Today")
permitted = params.permit({book: ["title", :author]}, "magazine")
assert_equal "Romeo and Juliet", permitted[:book][:title]
@@ -96,23 +88,19 @@ class NestedParametersPermitTest < ActiveSupport::TestCase
end
test "nested array with strings that should be hashes" do
- params = ActionController::Parameters.new({
- book: {
+ params = ActionController::Parameters.new( book: {
genres: ["Tragedy"]
- }
- })
+ })
permitted = params.permit book: { genres: :type }
assert_empty permitted[:book][:genres]
end
test "nested array with strings that should be hashes and additional values" do
- params = ActionController::Parameters.new({
- book: {
+ params = ActionController::Parameters.new( book: {
title: "Romeo and Juliet",
genres: ["Tragedy"]
- }
- })
+ })
permitted = params.permit book: [ :title, { genres: :type } ]
assert_equal "Romeo and Juliet", permitted[:book][:title]
@@ -120,26 +108,22 @@ class NestedParametersPermitTest < ActiveSupport::TestCase
end
test "nested string that should be a hash" do
- params = ActionController::Parameters.new({
- book: {
+ params = ActionController::Parameters.new( book: {
genre: "Tragedy"
- }
- })
+ })
permitted = params.permit book: { genre: :type }
assert_nil permitted[:book][:genre]
end
test "fields_for-style nested params" do
- params = ActionController::Parameters.new({
- book: {
+ params = ActionController::Parameters.new( book: {
authors_attributes: {
'0': { name: "William Shakespeare", age_of_death: "52" },
'1': { name: "Unattributed Assistant" },
'2': { name: %w(injected names) }
}
- }
- })
+ })
permitted = params.permit book: { authors_attributes: [ :name ] }
assert_not_nil permitted[:book][:authors_attributes]["0"]
@@ -152,14 +136,12 @@ class NestedParametersPermitTest < ActiveSupport::TestCase
end
test "fields_for-style nested params with negative numbers" do
- params = ActionController::Parameters.new({
- book: {
+ params = ActionController::Parameters.new( book: {
authors_attributes: {
'-1': { name: "William Shakespeare", age_of_death: "52" },
'-2': { name: "Unattributed Assistant" }
}
- }
- })
+ })
permitted = params.permit book: { authors_attributes: [:name] }
assert_not_nil permitted[:book][:authors_attributes]["-1"]
@@ -171,14 +153,12 @@ class NestedParametersPermitTest < ActiveSupport::TestCase
end
test "nested number as key" do
- params = ActionController::Parameters.new({
- product: {
+ params = ActionController::Parameters.new( product: {
properties: {
"0" => "prop0",
"1" => "prop1"
}
- }
- })
+ })
params = params.require(:product).permit(properties: ["0"])
assert_not_nil params[:properties]["0"]
assert_nil params[:properties]["1"]
diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb
index ca59e670b9..7467d5a78f 100644
--- a/actionpack/test/controller/parameters/parameters_permit_test.rb
+++ b/actionpack/test/controller/parameters/parameters_permit_test.rb
@@ -256,9 +256,9 @@ class ParametersPermitTest < ActiveSupport::TestCase
test "permitted takes a default value when Parameters.permit_all_parameters is set" do
begin
ActionController::Parameters.permit_all_parameters = true
- params = ActionController::Parameters.new({ person: {
+ params = ActionController::Parameters.new(person: {
age: "32", name: { first: "David", last: "Heinemeier Hansson" }
- }})
+ })
assert params.slice(:person).permitted?
assert params[:person][:name].permitted?
diff --git a/actionpack/test/controller/parameters/raise_on_unpermitted_params_test.rb b/actionpack/test/controller/parameters/raise_on_unpermitted_params_test.rb
index 80a057dbac..bcb16eaf89 100644
--- a/actionpack/test/controller/parameters/raise_on_unpermitted_params_test.rb
+++ b/actionpack/test/controller/parameters/raise_on_unpermitted_params_test.rb
@@ -11,10 +11,8 @@ class RaiseOnUnpermittedParamsTest < ActiveSupport::TestCase
end
test "raises on unexpected params" do
- params = ActionController::Parameters.new({
- book: { pages: 65 },
- fishing: "Turnips"
- })
+ params = ActionController::Parameters.new( book: { pages: 65 },
+ fishing: "Turnips")
assert_raises(ActionController::UnpermittedParameters) do
params.permit(book: [:pages])
@@ -22,9 +20,7 @@ class RaiseOnUnpermittedParamsTest < ActiveSupport::TestCase
end
test "raises on unexpected nested params" do
- params = ActionController::Parameters.new({
- book: { pages: 65, title: "Green Cats and where to find then." }
- })
+ params = ActionController::Parameters.new( book: { pages: 65, title: "Green Cats and where to find then." })
assert_raises(ActionController::UnpermittedParameters) do
params.permit(book: [:pages])