I have two traits in my factory, and I want one of them to be turned on when I create the object, without it defaulting to one (so we randomly select the trait). That's what I'm doing:
FactoryGirl.define do factory :follow_up do first_name { Faker::Name.first_name } last_name { Faker::Name.last_name } phone { Faker::PhoneNumber.cell_phone.gsub(/[^\d]/, '').gsub(/^1/, '2')[0..9] } email { Faker::Internet.email } email_preferred true consent false if [1, 2].sample == 1 by_referral else by_provider end trait :by_referral do association :hospital association :referral source { FollowUp::REFERRAL} end trait :by_provider do association :provider source { FollowUp::PROVIDER } end end end
However, it seems that it ignores this if statement and goes directly to the by_provider attribute. Does anyone know how I will do this?
source share