title: how to use traits for associated factories?
body: <p>I need to write a test for associated models.</p>
  
  <p>spec/factories/users.rb:</p>
  
  <pre><code>FactoryGirl.define do
    factory :user do
      sequence(:name){ |i| "us#{i}" }
      sequence(:email){ |i| "us#{i}@ad.ad" }
      password 'qwerty'
      password_confirmation{ |u| u.password } 
      info Faker::Lorem.paragraph(7)
  
      trait :user_status do
        status_id 0
      end
  
      trait :manager_status do
        status_id 1
      end
  
      trait :admin_status do
        status_id 2
      end    
    end 
  end
  </code></pre>
  
  <p>but file spec/factories/users.rb is empty.</p>
  
  <p>schema:</p>
  
  <pre><code>create_table "statuses", force: :cascade do |t|
    t.string "title"
  end
  
  create_table "users", force: :cascade do |t|
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.integer  "status_id",              default: 0
    t.string   "name"  
  end
  </code></pre>
  
  <p>the page index.html.erb contains the below code:</p>
  
  <pre><code>....
  ...
  &lt;div class="status"&gt;&lt;%= user.status.title if user.status_id %&gt;&lt;/div&gt;
  ....
  ..
  </code></pre>
  
  <p>when i run a test:</p>
  
  <pre><code>it 'check response status code for index page' do
    visit users_path
    expect(response).to be_success 
  end 
  </code></pre>
  
  <p>console displays follow error messages:</p>
  
  <blockquote>
  <pre><code> Failure/Error: visit users_path
   ActionView::Template::Error:
     undefined method `title' for nil:NilClass
  </code></pre>
  </blockquote>
  
  <p>How to write factories for 'user' and 'status' with a trait?</p>