4

The following is my fabricator:

Fabricator(:my_fabricator) do
  my_first_association
  my_second_association
end

The problem here is that I need to pass my_first_association to my_second_association. Couldn't find anything related in the docs.

Patsy Issa
  • 11,113
  • 4
  • 55
  • 74

1 Answers1

3

If you pass a block value you can inspect the attributes hash of the object being generated.

Fabricator(:my_fabricator) do
  my_first_association
  my_second_association do |attrs|
    Fabricate.build(:my_second_association, my_first_association: attrs[:my_first_association])
  end
end
Paul Elliott
  • 1,174
  • 8
  • 9
  • Works like a charm cheers, would you be interested in a pr to add this to the website? – Patsy Issa Apr 12 '16 at 07:54
  • 1
    That would be great! The docsite has a separate repo. Please feel free to open issues/PRs for anything you think needs addressing. https://github.com/paulelliott/fabrication-site – Paul Elliott Apr 12 '16 at 17:41