title: How to get the created FactoryGirl objects?
body: <p>I have these models:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :company_users, :dependent =&gt; :delete_all
  
  class Company &lt; ActiveRecord::Base
    has_many :company_users, :dependent =&gt; :delete_all
    has_many :users, :through =&gt; :company_users
  
  class CompanyUser &lt; ActiveRecord::Base
    belongs_to :company
    belongs_to :user
  </code></pre>
  
  <p>I use this helper function to create and login:</p>
  
  <pre><code>def create_company_admin
    company_user = FactoryGirl.create(:company_user, :has_shopper, :has_company, :admin)
    user = User.first
    login_as user, scope: :user
    company_user
  end
  </code></pre>
  
  <p>And this is the actual test</p>
  
  <pre><code>feature 'user listing' do
    background do
      company_user = create_company_admin
    end
    scenario 'getting user list' do
      visit '/companies'
      page.has_content? company_user.user.name
    end
  end
  </code></pre>
  
  <p>This works until where he calls: company_user.user.name which doesn't seem to exist.  There I get undefined local variable or method `company_user'</p>
  
  <p>This is the factory:</p>
  
  <pre><code>factory :company_user, class: CompanyUser do
    authorized true
  
    trait :admin do
      admin true
    end
  
    trait :not_admin do
      admin false
    end
  
    trait :has_shopper do
      association :user, factory: :shopper
    end
  
    trait :has_company do
      association :company, factory: :company
    end
  end
  </code></pre>
  
  <p>Edit:</p>
  
  <p>This is the factory of shopper (which is a kind of user)</p>
  
  <pre><code>factory :shopper, class: User do
    username "user"
    email "mail@mai.co"
    password "password1"
    after(:create) do |u|
      u.skip_confirmation!
      u.save!
    end
  end
  </code></pre>
  
  <p>How do I get the user, company and company_user in the test?</p>