title: Factory Girl: How to associate a record to another record without creating a new record?
body: <p>I'm using Factory Girl/Rspec2/Rails 3.</p>
  
  <p>In <em>factories.rb</em>, I have:</p>
  
  <pre><code>Factory.define :user do |user|
    user.name       'Some guy'
    user.email      'some_guy@somewhere.org'
    user.password   'password'
  end
  
  Factory.define :org_admin, :parent =&gt; :user do |user|
    user.email 'org_admin@somehwere.org'
  end
  
  Factory.define :user_with_membership_request, :parent =&gt; :user do |user|
    user.email 'user_with_membership_request@somehwere.org'
  end
  
  Factory.define :organization do |org|
    org.name        'MEC'
    org.description 'Mountain Equipment Co-op'
  end
  
  Factory.define :membership do |membership|
    membership.user { Factory(:user) }
    membership.organization { Factory(:organization) }
  end
  
  Factory.define :admin_membership, :parent =&gt; :membership do |membership|
    membership.user { Factory(:org_admin) }
    membership.is_admin true
    membership.status 'active'
  end
  
  Factory.define :membership_request, :parent =&gt; :membership do |membership|
    membership.user { Factory(:user_with_membership_request) }
    membership.status 'requested'
  end
  </code></pre>
  
  <p>and then in my rspec test I have:</p>
  
  <pre><code>  it 'should accept the membership request' do
      @org_admin = Factory(:org_admin)
      test_sign_in(@org_admin)
      @organization = Factory(:organization)
      @membership_request = Factory(:membership_request)
  
      put :update, :organization_id =&gt; @organization.id, :id =&gt; @membership_request.id, :acceptance =&gt; 'approve'
      ...
    end
  </code></pre>
  
  <p>When I run the test, I get:</p>
  
  <pre><code> Failure/Error: @membership_request = Factory(:membership_request)
   Validation failed: Name has already been taken
  </code></pre>
  
  <p>I understand the reason for the failure is because FactoryGirl is creating another organization (with the same name).</p>
  
  <p>But what I'd like to do is create several memberships all associated with the same organization. How do I do that?</p>
  
  <p>Thanks.</p>
  
  <p>Sean</p>