Im running RSPEC tests on my Ruby on Rails Controller, here is the controller action I am testing:
CONTROLLER CODE:
class Customers::AccountsController < ApplicationController
before_action :set_customer
def index
@accounts = @customer.accounts
respond_to do |format|
format.html
format.json
end
def set_customer
@customer = current_member.company.customers.find(params[:customer_id])
end
Here is my RSPEC Test Code:
before do
@member = FactoryGirl.create(:member)
@company = FactoryGirl.create(:company, owner_id: @member.id)
@customer=FactoryGirl.create(:customer_john_human,company_id:@company.id)
end
describe "GET INDEX" do
it "gets the index html page" do
get :index, {:customer_id=>@customer.id, :format=>:json}
end
end
THE ERROR:
ActiveRecord::RecordNotFound:
Couldn't find Customer with 'id'=1 [WHERE (`customers`.`company_id` IS NOT NULL) AND `customers`.`company_id` = ?]
# ./app/controllers/customers/accounts_controller.rb:87:in `set_customer'
# ./spec/support/engine_controller.rb:25:in `process_action'
# ./spec/support/engine_controller.rb:3:in `get'
# ./spec/controllers/customers/accounts_controller_spec.rb:21:in `block (3 levels) in <top (required)>'
I am unsure what 'customer.company_id = ?' means, - if i do :
puts @customer.inspect
i get the following output:
#<Customer id: 2, user_id: nil, title: nil, first_name: "John", last_name: "Kusu", created_at: "2015-04-27 18:42:00", updated_at: "2015-04-27 18:42:00", deleted_at: nil, company_name: nil, company_id: 6>
As far as i can tell, company_id is defined and set as 6. I am not sure why I am getting this error?
Aucun commentaire:
Enregistrer un commentaire