I am trying to create a model named global_list. It will take a list which is associated with a user and a global_id which is associated with an item. I need to create a user (a list is created in a callback for this object) and an item (where a global_identification is created as a callback to item creation). Neither of the following solutions work in trying to create these associated objects before. Should they? Is there a better way to handle this? I have tried creating accessors for liked_item_list_id but that also didn't work.
FactoryGirl.define do
factory :global_list do
before(:create) {
user=FactoryGirl.create(:user)
mi=FactoryGirl.create(:item)
}
list_id user.liked_list_id
global_id mi.global_id
end
end
Will a block help?
FactoryGirl.define do
factory :global_list do
before(:create) {
user=FactoryGirl.create(:user)
mi=FactoryGirl.create(:item)
}
list_id { List.first.id }
global_id { 3 } # 3 will be created at this point { mil.global_id } doesn't work
end
end
I'm starting to think this is not possible with FactoryGirl. Any help would be appreciated?