aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/forbidden_attributes_protection_test.rb
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2012-07-18 01:37:03 -0500
committerGuillermo Iguaran <guilleiguaran@gmail.com>2012-09-16 23:58:19 -0500
commit52aa5343f49abc2adc4c64d44d7a6bbe4de3373b (patch)
treee33e74f94de4f372973af7554aa2f342d7049f7d /activemodel/test/cases/forbidden_attributes_protection_test.rb
parent0168c7a394e1f9a0462a8fc442e3cc3b205bd6ae (diff)
downloadrails-52aa5343f49abc2adc4c64d44d7a6bbe4de3373b.tar.gz
rails-52aa5343f49abc2adc4c64d44d7a6bbe4de3373b.tar.bz2
rails-52aa5343f49abc2adc4c64d44d7a6bbe4de3373b.zip
Change AMo::ForbiddenAttributesProtection tests to use a subclass of Hash instead of monkey patch permitted? method in regular hashes
Diffstat (limited to 'activemodel/test/cases/forbidden_attributes_protection_test.rb')
-rw-r--r--activemodel/test/cases/forbidden_attributes_protection_test.rb26
1 files changed, 18 insertions, 8 deletions
diff --git a/activemodel/test/cases/forbidden_attributes_protection_test.rb b/activemodel/test/cases/forbidden_attributes_protection_test.rb
index 680f222a30..fab28ced0e 100644
--- a/activemodel/test/cases/forbidden_attributes_protection_test.rb
+++ b/activemodel/test/cases/forbidden_attributes_protection_test.rb
@@ -1,22 +1,32 @@
require 'cases/helper'
+require 'active_support/core_ext/hash/indifferent_access'
require 'models/account'
+class ProtectedParams < ActiveSupport::HashWithIndifferentAccess
+ attr_accessor :permitted
+ alias :permitted? :permitted
+
+ def initialize(attributes)
+ super(attributes)
+ @permitted = false
+ end
+
+ def permit!
+ @permitted = true
+ self
+ end
+end
+
class ActiveModelMassUpdateProtectionTest < ActiveSupport::TestCase
test "forbidden attributes cannot be used for mass updating" do
- params = { "a" => "b" }
- class << params
- define_method(:permitted?) { false }
- end
+ params = ProtectedParams.new({ "a" => "b" })
assert_raises(ActiveModel::ForbiddenAttributes) do
Account.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
+ params = ProtectedParams.new({ "a" => "b" }).permit!
assert_nothing_raised do
assert_equal({ "a" => "b" },
Account.new.sanitize_for_mass_assignment(params))