Sha256: d0c7bf7581c92025f1ebc2bee2dee4c21de78db9c116bdbe6c9b265f0faca996
Contents?: true
Size: 1.01 KB
Versions: 2
Compression:
Stored size: 1.01 KB
Contents
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 = ProtectedParams.new({ "a" => "b" }) assert_raises(ActiveModel::ForbiddenAttributesError) do Account.new.sanitize_for_mass_assignment(params) end end test "permitted attributes can be used for mass updating" do params = ProtectedParams.new({ "a" => "b" }).permit! assert_equal({ "a" => "b" }, Account.new.sanitize_for_mass_assignment(params)) end test "regular attributes should still be allowed" do assert_equal({ a: "b" }, Account.new.sanitize_for_mass_assignment(a: "b")) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
activejob-lock-0.0.2 | rails/activemodel/test/cases/forbidden_attributes_protection_test.rb |
activejob-lock-0.0.1 | rails/activemodel/test/cases/forbidden_attributes_protection_test.rb |