title: FactoryGirl standard way of creating complex factories (model coupling concern)
body: <p>So I'm working with a complex code base, with lots of models of an ERP solution done in Rails 4 with RSpec and FactoryGirl. Fortunately it has lots of tests, not as much as would be ideal, but a reasonable number. One of the struggling points has been the complex factory setups. For example, to create a simple invoice we have to do a lot of work:</p>
  <pre><code>product = create(:product, business: test_business, price: 100)
  activity = create(:activity, business: test_business)
  create(:sales_point, business: test_business, fiscal_number: 1)
  user = create(:user)
  Invoice.create!(business: test_business,
                  sales_point: 1,
                  invoice_type: InvoiceType::INVOICE_B,
                  receptor_fiscal_category: FiscalCategory::BUSINESS_A,
                  details: [InvoiceDetail.new( product: product,
                                               description: product.name,
                                               unitary_amount: 100,
                                               quantity: 1,
                                               amount: 100,
                                               activity: activity)],
                  total_net: 100,
                  total_tax: 21,
                  total_amount: 121,
                  created_by: user,
                  updated_by: user)
  </code></pre>
  <p>And that's only for creating a simple invoice for testing! I know that Thoughtbot, the FactoryGirl creators, actually advocate against having multiple factories for the same model or too much complexity in them. And I can understand why: when you start using too much magic in factories, they get too coupled to your tests and then when you change something <strong>BANG!</strong> hundreds of test start failing.</p>
  <p>So instead of changing stuff, or trying to be 'too smart' we ended up with 5-10 versions of factories for complex models like <code>Invoice</code> (e.g. <code>invoice_by_total_amount</code>, <code>invoice_by_product_list</code>, <code>invoice_cash</code>, etc).</p>
  <p>The question is, <strong>if you have ever worked in big codebases like this</strong> (100~ models), what where the recommended way to deal with this kind of complex setup to create objects for tests? How successful was it?</p>