FactoryGirl - reference another association factory
<p>I have defined some different factories for my Plan model  as follows:</p>

<pre><code>FactoryGirl.define do
  factory :plan do
    factory :free_plan do
      name "Free"
      description "Free Plan"
      price 0
      duration 999
      questions 5
    end

    factory :premium_plan do
      name "Premium"
      description "Premium Plan"
      duration 1
      price 3
      questions 1000
    end

    factory :premium_plus_plan do
      name "Premium Plus"
      description "Premium Plus Plan"
      duration 3
      price 7
      questions 1000
    end
  end
end
</code></pre>

<p>Plan model has many subscriptions. How is it possible to reference a specified plan factory from a Subscription factory (the below does snot work):</p>

<pre><code>FactoryGirl.define do
  factory :subscription do
    user
    activated true

    factory :one_month_subscription do
      plan { premium_plan }
      start_date { Time.now }
      end_date { start_date.advance(months: 1)}
    end

    factory :three_months_subscription do
      plan { premium_plus_plan }
      start_date { Time.now }
      end_date { start_date.advance(months: 3)}
    end

    factory :expired_subscription do
      plan { premium_plus_plan }
      start_date { 2.years.ago }
      end_date { start_date.advance(year: 1) }
    end
  end
end
</code></pre>

<p>Any idea ? Thank you.</p>