should_protect_attributes problem

0 views
Skip to first unread message

osh

unread,
Apr 18, 2008, 3:04:07 PM4/18/08
to shoulda
I recently found some tests using #should_protect_attributes failing.
The tests were incorrectly claiming that some protected attributes
were not being protected.

I changed line 110 in r465 from this:
assert protected_attributes.include?(attribute.to_s), ...
to this:
assert protected_attributes.include?(attribute), ...

Made me wonder what I was doing wrong. Within my models I declare my
protected attributes as symbols, which is why the test failed. I think
the original version of the test macro would work if protected
attributes were declared within the model as strings.

osh

Tammer Saleh

unread,
Apr 18, 2008, 4:08:08 PM4/18/08
to sho...@googlegroups.com
That's a good catch. I think it would be better to normalize the
protected_attributes array into strings, and force the attribute to a
string as well. That way, you can call it with symbols or strings,
and it doesn't matter which type you used in your model definition.

Someone submitted a patch a while ago to account for attr_accessible
as well, which I think got lost in the shuffle somewhere. It may
still be in lighthouse.

Tammer

Reply all
Reply to author
Forward
0 new messages