Factory-girl and update_attributes

817 views
Skip to first unread message

kronos

unread,
Nov 30, 2009, 10:25:04 AM11/30/09
to factory_girl
Why update_atributes method doesn't work with model created with
factory-girl?
For example:
@instance = Factory.create(:running_instance)
@instance.update_attributes(:field => value)
field doesn't change his value! update_attributes! doesn't work too.
Where I am wrong?

Nathan Sutton

unread,
Nov 30, 2009, 10:38:47 AM11/30/09
to factor...@googlegroups.com
Two ideas:

1) That attribute is protected (attr_accessible or attr_protected). Check in your model for attr_protected or attr_accessible.

2) Updating that attribute makes the model invalid. #update_attributes! would throw an exception in this case though, I think. Try:

@instance = Factory(:running_instance)
@instance.update_attributes(:field => value)
puts @instance.errors.full_messages

Let us know if that works.

Nate

kronos

unread,
Nov 30, 2009, 3:10:02 PM11/30/09
to factory_girl


On Nov 30, 6:38 pm, Nathan Sutton <nathan.sut...@gmail.com> wrote:
> Two ideas:
>
> 1) That attribute is protected (attr_accessible or attr_protected). Check in your model for attr_protected or attr_accessible.
>

This is true. Sorry for that, my fault.

Nathan Sutton

unread,
Nov 30, 2009, 3:11:37 PM11/30/09
to factor...@googlegroups.com
No apologies necessary. Using attr_accessible and attr_protected are good things (especially the former).

Reply all
Reply to author
Forward
0 new messages