rails/rails — comment on commit 06a3a8a458e70c1b6531ac53c57a302b162fd736
File:  line 0
By pixeltrix:

@eval write a custom [TestSanitizer][1] that doesn't remove anything from the attribute hash and [configure][2] it in your test environment or you can do it on a test by test basis:

``` ruby
class TestSanitizer < ActiveModel::MassAssignmentSecurity::Sanitizer
def sanitize(attributes, authorizer)
attributes # you may want to do something else here
end
end

class MyTestCase < ActiveSupport::TestCase
def test_case
without_attribute_protection do
# your test code
end
end

def without_attribute_protection
ActiveRecord::Base.mass_assignment_sanitizer = TestSanitizer.new
yield
ensure
ActiveRecord::Base.mass_assignment_sanitizer = :logger
end
end
```

[1]: https://github.com/rails/rails/blob/master/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb
[2]: https://github.com/rails/rails/blob/master/activemodel/lib/active_model/mass_assignment_security.rb#L53