I have a very simple association set up in FactoryGirl, but it's not working for some reason. The app is for a tour company, so each Tour has a Destination (I'm using ActiveRecord, so the Tour
model belongs_to
a Destination
-- this association is required for all tours). So I set up my factories like this:
# spec/factories.rb
FactoryGirl.define do
factory :destination do
name "Example Destination"
city "Example City"
state "CA"
end
factory :tour do
departure_date { 1.day.from_now }
return_date { 1.day.from_now }
destination
end
end
However, when I call FactoryGirl.attributes_for(:tour)
, it returns:
{:departure_date => Mon, 04 Nov 2013 17:51:26 UTC +00:00,
:return_date => Mon, 04 Nov 2013 17:51:26 UTC +00:00}
No destination_id
! Why?
The destination
factory works just fine.
I tried defining the association the old way association :destination, factory: :destination
, but that didn't help. I can get it to work if I manually define the destination_id
as destination_id FactoryGirl.create(:destination).id
, but I shouldn't have to do that. Any idea why it's not working?