[rspec-users] Testing attr_accessible (and/or attr_protected)

Iain E. Davis iain at somethingelectronic.com
Mon Nov 1 20:36:38 EDT 2010

I've been puzzling over how to test that attr_accessible has been set
for the correct columns; but the tests I've come up with so far seem
to fail to fail when I expect. I came across this old message from
this list:


Which seemed like a plausible example, but my attempt (modeled on the
example) doesn't work:

describe Article, 'protected attributes' do
     it 'should deny mass-assignment to the user_id' do
       lambda { article.update_attributes(:person_id =>  @person.id)
}.should raise_error

The lambda doesn't raise an error, even though the attr_accessible
doesn't include person_id.

Where am I stumbling here? Is it my beginner's knowledge of rails, or
beginner's knowledge of Ruby?



More information about the rspec-users mailing list