Skip to content
Browse files

Lets kepp using Ruby 1.9 syntax

  • Loading branch information...
1 parent 16e0c88 commit cb56c39b5186255d8208c6139669ca74e75d5759 @rafaelfranca rafaelfranca committed Jan 22, 2013
View
40 actionpack/test/controller/parameters/nested_parameters_test.rb
@@ -16,7 +16,7 @@ def assert_filtered_out(params, key)
}, {
name: "Christopher Marlowe"
}, {
- :name => %w(malicious injected names)
+ name: %w(malicious injected names)
}],
details: {
pages: 200,
@@ -71,25 +71,25 @@ def assert_filtered_out(params, key)
test "nested arrays with strings" do
params = ActionController::Parameters.new({
- :book => {
- :genres => ["Tragedy"]
+ book: {
+ genres: ["Tragedy"]
}
})
- permitted = params.permit :book => {:genres => []}
+ 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 => {
- :title => "Romeo and Juliet",
- :author => "William Shakespeare"
+ book: {
+ title: "Romeo and Juliet",
+ author: "William Shakespeare"
},
- :magazine => "Shakespeare Today"
+ magazine: "Shakespeare Today"
})
- permitted = params.permit({:book => ["title", :author]}, "magazine")
+ permitted = params.permit({book: ["title", :author]}, "magazine")
assert_equal "Romeo and Juliet", permitted[:book][:title]
assert_equal "William Shakespeare", permitted[:book][:author]
assert_equal "Shakespeare Today", permitted[:magazine]
@@ -132,15 +132,15 @@ def assert_filtered_out(params, key)
test "fields_for-style nested params" do
params = ActionController::Parameters.new({
- :book => {
- :authors_attributes => {
- :'0' => { :name => 'William Shakespeare', :age_of_death => '52' },
- :'1' => { :name => 'Unattributed Assistant' },
- :'2' => { :name => %w(injected names)}
+ 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 ] }
+ permitted = params.permit book: { authors_attributes: [ :name ] }
assert_not_nil permitted[:book][:authors_attributes]['0']
assert_not_nil permitted[:book][:authors_attributes]['1']
@@ -153,14 +153,14 @@ def assert_filtered_out(params, key)
test "fields_for-style nested params with negative numbers" do
params = ActionController::Parameters.new({
- :book => {
- :authors_attributes => {
- :'-1' => { :name => 'William Shakespeare', :age_of_death => '52' },
- :'-2' => { :name => 'Unattributed Assistant' }
+ book: {
+ authors_attributes: {
+ :'-1' => { name: 'William Shakespeare', age_of_death: '52' },
+ :'-2' => { name: 'Unattributed Assistant' }
}
}
})
- permitted = params.permit :book => { :authors_attributes => [:name] }
+ permitted = params.permit book: { authors_attributes: [:name] }
assert_not_nil permitted[:book][:authors_attributes]['-1']
assert_not_nil permitted[:book][:authors_attributes]['-2']
View
34 actionpack/test/controller/parameters/parameters_permit_test.rb
@@ -20,7 +20,7 @@ def assert_filtered_out(params, key)
end
test 'if nothing is permitted, the hash becomes empty' do
- params = ActionController::Parameters.new(:id => '1234')
+ params = ActionController::Parameters.new(id: '1234')
permitted = params.permit
assert permitted.permitted?
assert permitted.empty?
@@ -34,7 +34,7 @@ def assert_filtered_out(params, key)
values += [StringIO.new]
values.each do |value|
- params = ActionController::Parameters.new(:id => value)
+ params = ActionController::Parameters.new(id: value)
permitted = params.permit(:id)
assert_equal value, permitted[:id]
@@ -47,15 +47,15 @@ def assert_filtered_out(params, key)
end
test 'key: unknown keys are filtered out' do
- params = ActionController::Parameters.new(:id => '1234', :injected => 'injected')
+ params = ActionController::Parameters.new(id: '1234', injected: 'injected')
permitted = params.permit(:id)
assert_equal '1234', permitted[:id]
assert_filtered_out permitted, :injected
end
test 'key: arrays are filtered out' do
[[], [1], ['1']].each do |array|
- params = ActionController::Parameters.new(:id => array)
+ params = ActionController::Parameters.new(id: array)
permitted = params.permit(:id)
assert_filtered_out permitted, :id
@@ -68,8 +68,8 @@ def assert_filtered_out(params, key)
end
test 'key: hashes are filtered out' do
- [{}, {:foo => 1}, {:foo => 'bar'}].each do |hash|
- params = ActionController::Parameters.new(:id => hash)
+ [{}, {foo: 1}, {foo: 'bar'}].each do |hash|
+ params = ActionController::Parameters.new(id: hash)
permitted = params.permit(:id)
assert_filtered_out permitted, :id
@@ -82,7 +82,7 @@ def assert_filtered_out(params, key)
end
test 'key: non-permitted scalar values are filtered out' do
- params = ActionController::Parameters.new(:id => Object.new)
+ params = ActionController::Parameters.new(id: Object.new)
permitted = params.permit(:id)
assert_filtered_out permitted, :id
@@ -94,37 +94,37 @@ def assert_filtered_out(params, key)
end
test 'key: it is not assigned if not present in params' do
- params = ActionController::Parameters.new(:name => 'Joe')
+ params = ActionController::Parameters.new(name: 'Joe')
permitted = params.permit(:id)
assert !permitted.has_key?(:id)
end
test 'key to empty array: empty arrays pass' do
- params = ActionController::Parameters.new(:id => [])
- permitted = params.permit(:id => [])
+ params = ActionController::Parameters.new(id: [])
+ permitted = params.permit(id: [])
assert_equal [], permitted[:id]
end
test 'key to empty array: arrays of permitted scalars pass' do
[['foo'], [1], ['foo', 'bar'], [1, 2, 3]].each do |array|
- params = ActionController::Parameters.new(:id => array)
- permitted = params.permit(:id => [])
+ params = ActionController::Parameters.new(id: array)
+ permitted = params.permit(id: [])
assert_equal array, permitted[:id]
end
end
test 'key to empty array: permitted scalar values do not pass' do
['foo', 1].each do |permitted_scalar|
- params = ActionController::Parameters.new(:id => permitted_scalar)
- permitted = params.permit(:id => [])
+ params = ActionController::Parameters.new(id: permitted_scalar)
+ permitted = params.permit(id: [])
assert_filtered_out permitted, :id
end
end
test 'key to empty array: arrays of non-permitted scalar do not pass' do
- [[Object.new], [[]], [[1]], [{}], [{:id => '1'}]].each do |non_permitted_scalar|
- params = ActionController::Parameters.new(:id => non_permitted_scalar)
- permitted = params.permit(:id => [])
+ [[Object.new], [[]], [[1]], [{}], [{id: '1'}]].each do |non_permitted_scalar|
+ params = ActionController::Parameters.new(id: non_permitted_scalar)
+ permitted = params.permit(id: [])
assert_filtered_out permitted, :id
end
end

0 comments on commit cb56c39

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