Yeah, it works as expected:

describe AccountsController do

  let(:admin) { create(:admin) }
  let(:client) { create(:client) }

  before(:each) { sign_in admin }

  describe "POST create" do
    it "creates a new account" do
      #account =  build(:account, client: client)
      expect{
        post :create, account: { client_id: client.id }
      }.to change(Account, :count).by(1)
    end

    it "redirects to the client #show page" do
      post :create, account: { client_id: client.id }
      response.should redirect_to client
    end
  end
end

I believed that 

1) the use of FactoryGirl build:

account =  build(:account, client: client)

would solve the problem.

2) that passing client in the hash will solve the client_id problem (I did 
the same in models specs, for example):

let(:client) { create(:client) }
before { @account = build(:account, client: client) }

Thanks for your help, David.




-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rspec/-/4c9zveJMC0AJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to