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.