diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2012-07-13 03:51:13 -0500 |
---|---|---|
committer | Guillermo Iguaran <guilleiguaran@gmail.com> | 2012-09-16 23:58:19 -0500 |
commit | a8f6d5c6450a7fe058348a7f10a908352bb6c7fc (patch) | |
tree | 245439153ec40c6840ece2b13ecc41572fe56d33 /activemodel/test/cases | |
parent | 885005461b3cc0d073ec08495dc3bf06d0bebf2a (diff) | |
download | rails-a8f6d5c6450a7fe058348a7f10a908352bb6c7fc.tar.gz rails-a8f6d5c6450a7fe058348a7f10a908352bb6c7fc.tar.bz2 rails-a8f6d5c6450a7fe058348a7f10a908352bb6c7fc.zip |
Integrate ActiveModel::ForbiddenAttributesProtection from StrongParameters gem
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r-- | activemodel/test/cases/forbidden_attributes_protection_test.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/activemodel/test/cases/forbidden_attributes_protection_test.rb b/activemodel/test/cases/forbidden_attributes_protection_test.rb new file mode 100644 index 0000000000..d3088b4fc2 --- /dev/null +++ b/activemodel/test/cases/forbidden_attributes_protection_test.rb @@ -0,0 +1,32 @@ +require 'cases/helper' +require 'models/mass_assignment_specific' + +class ActiveModelMassUpdateProtectionTest < ActiveSupport::TestCase + test "forbidden attributes cannot be used for mass updating" do + params = { "a" => "b" } + class << params + define_method(:permitted?) { false } + end + assert_raises(ActiveModel::ForbiddenAttributes) do + SpecialPerson.new.sanitize_for_mass_assignment(params) + end + end + + test "permitted attributes can be used for mass updating" do + params = { "a" => "b" } + class << params + define_method(:permitted?) { true } + end + assert_nothing_raised do + assert_equal({ "a" => "b" }, + SpecialPerson.new.sanitize_for_mass_assignment(params)) + end + end + + test "regular attributes should still be allowed" do + assert_nothing_raised do + assert_equal({ a: "b" }, + SpecialPerson.new.sanitize_for_mass_assignment(a: "b")) + end + end +end |