mongoid/mongoid — Issue #1699: Mass assignment to attr_protected does not raise an error
Author: mrinterweb
Created: 2012-02-09 21:49:32+00:00
State: open

According to http://mongoid.org/docs/documents/access.html "Attempt to set attributes a person, raising an error."
I am inferring that when mass assignment happens on a protected attributes happens, an error should be raised. Maybe I'm reading this wrong or the documentation is out dated. What I am seeing is that the protected attribute assignment silently fails.

This is what I see:

class Foo
include Mongoid::Document

field :open
field :secret

attr_protected :secret
end

Foo.new(open: 'blerg', secret: 'foo')
=> #

By the documentation attr_accessible is supposed to silently fail, and attr_protected should raise an error. I would prefer attr_protected mass assignment to raise and error.