On Wed, Nov 21, 2012 at 10:04 AM, Javix <[email protected]> wrote: > When defined the spec as follows: > > require 'spec_helper' > > 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: attributes_for(:account, client: client) > }.to change(Account, :count).by(1) > end > > it "redirects to the client #show page" do > response.should redirect_to client > end > end > end > > I got the below errors: > > AccountsController > POST create > creates a new account (FAILED - 1) > redirects to the client #show page (FAILED - 2) > > Failures: > > 1) AccountsController POST create creates a new account > Failure/Error: post :create, account: attributes_for(:account, client: > client) > ActiveRecord::RecordNotFound: > Couldn't find Client without an ID
I'd start by investigating this error message. Try printing out params from the find_client method and make sure it's got what you expect. > # C:in `find' > # ./app/controllers/accounts_controller.rb:37:in `find_client' > # ./spec/controllers/accounts_controller_spec.rb:14:in `block (4 > levels) in <top (required)>' > # ./spec/controllers/accounts_controller_spec.rb:13:in `block (3 > levels) in <top (required)>' > > 2) AccountsController POST create redirects to the client #show page > Failure/Error: response.should redirect_to client > Expected response to be a <:redirect>, but was <200> > # ./spec/controllers/accounts_controller_spec.rb:19:in `block (3 > levels) in <top (required)>' > > Finished in 3.89 seconds > 2 examples, 2 failures > > Failed examples: > > rspec ./spec/controllers/accounts_controller_spec.rb:11 # AccountsController > POST create creates a new account > rspec ./spec/controllers/accounts_controller_spec.rb:18 # AccountsController > POST create redirects to the client #show page > > Any idea ? Thansk and regards > > -- > 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/-/lgSio-qEqhQJ. > > For more options, visit https://groups.google.com/groups/opt_out. > > -- 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]. For more options, visit https://groups.google.com/groups/opt_out.
