These are 2 simple models:
class Post < ActiveRecord::Base
has_one :asset, :dependent => :destroy
validates :asset, presence: true
end
class Asset < ActiveRecord::Base
belongs_to :post
end
I'm trying to create a factory like this:
factory :post do
# fields...
asset { FactoryGirl.create(:asset) }
end
factory :asset do
# fields...
post
end
But, running the spec it enters a loop.
I've also tryied this:
factory :post do
# fields...
before(:create) do |post, evaluator|
FactoryGirl.create_list(:asset, 1, post: post)
end
end
But ended up in "Validation failed: Asset can't be blank".
How do I represent my situation?
post
on:asset
instead of the other way around? Seems weird sincePost
is the one requiring anAsset
during creation. – Arathorn