title: FactoryGirl association model trouble: "SystemStackError: stack level too deep"
body: <p>I am using Ruby on Rails 3.0.9, RSpec-rails 2 and FactoryGirl. I am trying to state a Factory association model but I am in trouble.</p>
  
  <p>I have a <code>factories/user.rb</code> file like the following:</p>
  
  <pre><code>FactoryGirl.define do
    factory :user, :class =&gt; User do
      attribute_1
      attribute_2
      ...
  
      association :account, :factory =&gt; :users_account, :method =&gt; :build, :email =&gt; 'foo@bar.com'
    end
  end
  </code></pre>
  
  <p>and a <code>factories/users/account.rb</code> file like the following:</p>
  
  <pre><code>FactoryGirl.define do
    factory :users_account, :class =&gt; Users::Account do
      sequence(:email) {|n| "foo#{n}@bar.com" }
      ...
    end
  end
  </code></pre>
  
  <p>The above example works as expected in my spec files, but <em>if</em> in the <code>factory :users_account</code> statement I add the <code>association :user</code> code so to have</p>
  
  <pre><code>FactoryGirl.define do
    factory :users_account, :class =&gt; Users::Account do
      sequence(:email) {|n| "foo#{n}@bar.com" }
      ...
      association      :user
    end
  end
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Failure/Error: Unable to find matching line from backtrace
  SystemStackError:
    stack level too deep
  </code></pre>
  
  <p><strong>How can I solve that problem so to access associated models from both sides\factories</strong> (that is, in my spec files I would like to use RoR association model methods like <code>user.account</code> and <code>account.user</code>)<strong>?</strong></p>
  
  <p>P.S.: I read the <a href="https://stackoverflow.com/questions/2238580/factory-girl-and-has-one">Factory Girl and has_one</a> question and my case is very close to the case explained in the linked question. That is, I have an <code>has_one</code> association too (between <code>User</code> and <code>Users::Account</code> classes).</p>