[rspec-users] Testing attr_accessible (and/or attr_protected)
Iain E. Davis
iain at somethingelectronic.com
Tue Nov 2 10:39:02 EDT 2010
I failed to mention I'm using Rails 2.3.8 and Rspec-1.3.x. I should
have said that right away.
On Tue, Nov 2, 2010 at 01:33, Alexey Ilyichev <bluesman.alex at gmail.com> wrote:
> An attempt to assign protected attributes leads to the warning in your log
Hmm... Maybe I should actually look at the log once in a while...
> article.update_attributes(:person_id => @person.id)
> article.person_id.should == nil # or whatever it is before update call
On Tue, Nov 2, 2010 at 02:13, Evgeniy Dolzhenko <dolzenko at gmail.com> wrote:
> 1. perform update_attributes for an attribute and then assert that the attribute didn't change
Buh. I wish I had thought of that. Seems rather obvious now...I
confess I was expecting something esoteric and thus didn't stop to
think if there was a simple solution. :)
To me, checking whether the attribute changed is more straight-forward
than implementing a custom matcher, at least at my current level of
experience (novice) with rails and rspec.
I suppose I need to be careful that the attribute change was rejected
for some other reason (bad data, for example). But that's true of any
On Tue, Nov 2, 2010 at 02:20, Wincent Colaiuta <win at wincent.com> wrote:
> I'm the author of that message you linked to from three years ago. Things have changed quite
> a bit since then.
I suspected so! I guess I should have clued in when I didn't find
anything about raising an error in the docs for update_attribute.
Oh! In the same vein, when looking at the docs/source for
update_attribute, I formed the expectation that update_attribute(s)
would return false if it failed. My new guess is that it returns false
if it fails to save the model...irregardless of whether the attribute
Thank you Alexey, Evgeniy, and Wincent!
More information about the rspec-users