diff options
Diffstat (limited to 'activerecord/test/cases/forbidden_attributes_protection_test.rb')
-rw-r--r-- | activerecord/test/cases/forbidden_attributes_protection_test.rb | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/activerecord/test/cases/forbidden_attributes_protection_test.rb b/activerecord/test/cases/forbidden_attributes_protection_test.rb index 91921469b8..75c3493527 100644 --- a/activerecord/test/cases/forbidden_attributes_protection_test.rb +++ b/activerecord/test/cases/forbidden_attributes_protection_test.rb @@ -1,11 +1,11 @@ -require 'cases/helper' -require 'active_support/core_ext/hash/indifferent_access' +require "cases/helper" +require "active_support/core_ext/hash/indifferent_access" -require 'models/company' -require 'models/person' -require 'models/ship' -require 'models/ship_part' -require 'models/treasure' +require "models/company" +require "models/person" +require "models/ship" +require "models/ship_part" +require "models/treasure" class ProtectedParams attr_accessor :permitted @@ -44,40 +44,40 @@ end class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase def test_forbidden_attributes_cannot_be_used_for_mass_assignment - params = ProtectedParams.new(first_name: 'Guille', gender: 'm') + params = ProtectedParams.new(first_name: "Guille", gender: "m") assert_raises(ActiveModel::ForbiddenAttributesError) do Person.new(params) end end def test_permitted_attributes_can_be_used_for_mass_assignment - params = ProtectedParams.new(first_name: 'Guille', gender: 'm') + params = ProtectedParams.new(first_name: "Guille", gender: "m") params.permit! person = Person.new(params) - assert_equal 'Guille', person.first_name - assert_equal 'm', person.gender + assert_equal "Guille", person.first_name + assert_equal "m", person.gender end def test_forbidden_attributes_cannot_be_used_for_sti_inheritance_column - params = ProtectedParams.new(type: 'Client') + params = ProtectedParams.new(type: "Client") assert_raises(ActiveModel::ForbiddenAttributesError) do Company.new(params) end end def test_permitted_attributes_can_be_used_for_sti_inheritance_column - params = ProtectedParams.new(type: 'Client') + params = ProtectedParams.new(type: "Client") params.permit! person = Company.new(params) assert_equal person.class, Client end def test_regular_hash_should_still_be_used_for_mass_assignment - person = Person.new(first_name: 'Guille', gender: 'm') + person = Person.new(first_name: "Guille", gender: "m") - assert_equal 'Guille', person.first_name - assert_equal 'm', person.gender + assert_equal "Guille", person.first_name + assert_equal "m", person.gender end def test_blank_attributes_should_not_raise @@ -86,7 +86,7 @@ class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase end def test_create_with_checks_permitted - params = ProtectedParams.new(first_name: 'Guille', gender: 'm') + params = ProtectedParams.new(first_name: "Guille", gender: "m") assert_raises(ActiveModel::ForbiddenAttributesError) do Person.create_with(params).create! @@ -94,21 +94,21 @@ class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase end def test_create_with_works_with_permitted_params - params = ProtectedParams.new(first_name: 'Guille').permit! + params = ProtectedParams.new(first_name: "Guille").permit! person = Person.create_with(params).create! - assert_equal 'Guille', person.first_name + assert_equal "Guille", person.first_name end def test_create_with_works_with_params_values - params = ProtectedParams.new(first_name: 'Guille') + params = ProtectedParams.new(first_name: "Guille") person = Person.create_with(first_name: params[:first_name]).create! - assert_equal 'Guille', person.first_name + assert_equal "Guille", person.first_name end def test_where_checks_permitted - params = ProtectedParams.new(first_name: 'Guille', gender: 'm') + params = ProtectedParams.new(first_name: "Guille", gender: "m") assert_raises(ActiveModel::ForbiddenAttributesError) do Person.where(params).create! @@ -116,21 +116,21 @@ class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase end def test_where_works_with_permitted_params - params = ProtectedParams.new(first_name: 'Guille').permit! + params = ProtectedParams.new(first_name: "Guille").permit! person = Person.where(params).create! - assert_equal 'Guille', person.first_name + assert_equal "Guille", person.first_name end def test_where_works_with_params_values - params = ProtectedParams.new(first_name: 'Guille') + params = ProtectedParams.new(first_name: "Guille") person = Person.where(first_name: params[:first_name]).create! - assert_equal 'Guille', person.first_name + assert_equal "Guille", person.first_name end def test_where_not_checks_permitted - params = ProtectedParams.new(first_name: 'Guille', gender: 'm') + params = ProtectedParams.new(first_name: "Guille", gender: "m") assert_raises(ActiveModel::ForbiddenAttributesError) do Person.where().not(params) @@ -138,9 +138,9 @@ class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase end def test_where_not_works_with_permitted_params - params = ProtectedParams.new(first_name: 'Guille').permit! + params = ProtectedParams.new(first_name: "Guille").permit! Person.create!(params) - assert_empty Person.where.not(params).select {|p| p.first_name == 'Guille' } + assert_empty Person.where.not(params).select { |p| p.first_name == "Guille" } end def test_strong_params_style_objects_work_with_singular_associations @@ -161,5 +161,4 @@ class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase assert_equal "Necklace", part.trinkets[0].name assert_equal "Spoon", part.trinkets[1].name end - end |