title: rspec assigns(has_many association) not working
body: <p>I'm a noob to testing in rails and did not follow TDD so I'm testing after the fact. I know my code works when I sanity check it, but I can not get this simple test to work and I have no idea why. I'm trying to learn more about testing so I can become a better rails developer and could use your help.</p>
  
  <p>I'm using the "show" action of the "companies" controller as a dashboard. One thing I do is display all their payments on the dashboard (which is shown in the controller code). I'm simply trying to test that @payments is assigned properly when you get the show action. </p>
  
  <p>This is the failure message I keep getting:</p>
  
  <pre><code>  1) CompaniesController GET show reacts to authenticated users sets @payments                                                                                                                                                                                              
   Failure/Error: expect(assigns(:payments)).to match_array([payment1, payment2])                                                                                                                                                                                         
     expected a collection that can be converted to an array with `#to_ary` or `#to_a`, but got nil                                                                                                                                                                       
   # ./spec/controllers/companies_controller_spec.rb:20:in `block (4 levels) in &lt;top (required)&gt;'    
  </code></pre>
  
  <p>Test:
  (The "sets @payments" test is the only one that's failing)</p>
  
  <pre><code>require 'rails_helper'
  
  describe CompaniesController do 
  
  describe "GET show" do
  
      context "reacts to authenticated users" do
          log_in_user
  
          it "sets @company" do
              company = Fabricate(:company)
              get :show, id: company.id
              expect(assigns(:company)).to eq(company)
          end
  
          it "sets @payments" do
              company = Fabricate(:company) 
              payment1, payment2 = Fabricate(:payment, company: company), Fabricate(:payment, company: company)
              get :show, id: company.id
              expect(assigns(:payments)).to match_array([payment1, payment2])
          end
        end
      end
    end
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>class CompaniesController &lt; ApplicationController
    before_action :authenticate_user!, if: :user_signed_in?
    before_filter :correct_user, only: [:edit, :update, :show, :destroy]
  
    def show
      @user = current_user
      @company = @user.company
      @payments = @company.payments.order(id: :desc).page params[:page]
      @payments_count = @company.payments.all
      @refunds_count = @company.refunds.all
      @refunded_amount = @refunds_count.sum(:amount)
      @revenue = @company.payments.all.sum(:amount) - @refunded_amount
      @refund = Refund.new
    end
  end
  </code></pre>