On Wed, May 27, 2009 at 8:51 AM, Denis H. email@example.com
then the ship_address object is persisted but the association is not made
(e.g. @order.ship_address_id is nil).
If I instead create the Address object and then say
@order.update_attributes(:ship_address => address), everything is fine.
Is this some issue with mixing factory-created objects with non? I can’t
imagine that’s an issue…
I don’t think it’s an issue w/FactoryGirl. A belongs_to association in
Rails adds the create_xxxxx association method, which returns a new
object of the associated type that has been instantiated and saved. It
does NOT save the receiver. For example:
This creates a ShipAddress and it updates @order’s in-memory
ship_address_id, but it does not save @order. You have to do that.
Here’s the example the Rails docs gives:
Post#create_author (similar to post.author = Author.new;
Which in this example, the post is never saved, only it’s in-memory
association is set, so you still need to save @order in your example.
rspec-users mailing list
http://www.mutuallyhuman.com (hire me)
http://ideafoundry.info/behavior-driven-development (first rate BDD