association with lazy attributes

25 views
Skip to first unread message

oli...@ifi.ch

unread,
Apr 22, 2013, 4:22:03 AM4/22/13
to factor...@googlegroups.com

I'm trying to have a factory build an Offering object with a child object Rating that will receive the item_id from it's parent.

FactoryGirl.define do
  factory :offering do
    item_id nil
    element_id nil
    association :rating, factory: :rating, strategy: :build, :item => item_id
  end
end


The Offering is created with

offering = FactoryGirl.create :offering, item_id: 21, element_id: 211

But when run, it aborts with an error

Failure/Error: offering = FactoryGirl.create :offering, item_id: 21, element_id: 211
 ArgumentError:
   Trait not registered: item_id


I assume the error occurs because the item_id in the association definition is not "lazy" and therefor undefined.
How can I solve this?

Best Regards,
Oliver

Reply all
Reply to author
Forward
0 new messages