0

The error I keep getting is as follows:

 test_should_get_show(CartsControllerTest):
    ActionController::RoutingError: No route matches {:cart=>"1", :controller=>"carts", :action=>"show"}

When I run the following code:

 def setup
    @cart = FactoryGirl.create(:cart)
  end

  test "should get show" do
    sign_in(FactoryGirl.create(:user, admin: true))
    session[:cart_id] = @cart.id 
    get :show, cart: @cart
    assert_response :success
    assert_not_nil assigns(:product_requests)
  end

My cart factory:

FactoryGirl.define do
  factory :cart do
    factory :cart_with_1_row do
      after(:create) do |cart|
        FactoryGirl.create(:cart_row, cart: cart)
      end
    end
  end
end

However, in my rake routes I have:

cart GET /carts/:id(.:format) carts#show

I can also go to http://localhost:3000/carts/1 manually in the browser in the development environment and it works fine.

What could be causing this?

Noah Clark
  • 8,101
  • 14
  • 74
  • 116

1 Answers1

1

Replace:

get :show, cart: @cart

With:

get :show, id: @cart  # or @cart.id
apneadiving
  • 114,565
  • 26
  • 219
  • 213