An attempt to assign protected attributes leads to the warning in your log
and not doing actual assignment.
You can test it like this:
describe Article, 'protected attributes' do
it 'should deny mass-assignment to the user_id' do
RAILS_DEFAULT_LOGGER.should_receive(:warn) # I ain't sure if it is
actually a warning, and I would just skip this check
article.update_attributes(:person_id => @person.id)
article.person_id.should == nil # or whatever it is before update call
end
end
On Tue, Nov 2, 2010 at 3:36 AM, Iain E. Davis
<[email protected]>wrote:
> 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:
>
> http://www.mail-archive.com/[email protected]/msg01570.html
>
> 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
> end
> end
>
> 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?
>
> Thanks,
>
> Iain
> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users