mercredi 12 septembre 2018

FactoryBot Eventable ID

I have a factory that looks like:

factory :order_with_approval do                                                                                                                                                                                            
   status      'approved'                                                                                                                                                                                                                
   association :approval, factory: :approval                                                                                                                                                                   
 end 

Now, I need the approval model to take the order id and set it as the eventable id. I've been able to figure this out in the other direction by doing:

factory :cancellation do                                                                                                                                                                                
  reason 'a reason'                                                                                                                                                                                                                     
  cancellation_date Date.current                                                                                                                                                                                                        
  association :eventable, factory: :order                                                                                                                                                                                               
end 

So what might work is if I can pass in something other than a new factory into the association. What I'd like to do is pass in the parent factory. Is that possible? Can I achieve this some other way?

Aucun commentaire:

Enregistrer un commentaire