ruby on rails - Using a 'default' trait in FactoryGirl to avoid unnecessary association creation -


is possible define default trait in factorygirl? if define factory (where both question_response belongs_to question):

factory :question_response   question   work_history    trait :open     question { factorygirl.create :question, question_type: 'open' }   end end 

when factorygirl.create :question_response, :open first create default question , create inside trait, unnecessary operation.

ideally i'd this:

factory :question_response   work_history    trait :default     question { factorygirl.create :question, question_type: 'yes_no' }   end    trait :open     question { factorygirl.create :question, question_type: 'open' }   end end 

and doing factorygirl.create :question use default trait, doesn't seem possible.

when factorygirl.create :question_response, :open first create default question , create inside trait

it's not true. if specify trait question, overwrite factory behavior before creation not create default question.

i checked factorygirl v4.5.0


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -