Reputation: 1381
I have factory Rule
which is parent for my other factories
parent is regular model
class Rule < ActiveRecord::Base
belongs_to :fee
end
class Fee < ActiveRecord::Base
has_many :rules
end
FactoryGirl.define do
factory :rule do
type { rule_classes.sample }
name { SecureRandom.hex }
data '["name"]'
association :fee, factory: :fee
end
my children rule models looks like AirlineRule < Rule
factory :airlines_rule, parent: :rule, class: 'AirlinesRule' do
data "airlines": ["KL","PN"]
end
but now i want to create Fee's
factory fee_with_all_rules
is it possible?
i have tried
factory :fee_with_all_rules do
association :fee, factory: [:airlines_rule, :connections_rule]
end
but it doesn't work
Upvotes: 1
Views: 299
Reputation: 3722
you can use after(:build)
after(:build) { |fee| FactoryGirl.build(:airlines_rule, fee: fee) }
try something like this
Upvotes: 1