0

私が取得し続けるエラーは次のとおりです。

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

次のコードを実行すると:

 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

私のカート工場:

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

ただし、私のレーキルートには次のものがあります。

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

http://localhost:3000/carts/1開発環境のブラウザーで手動でアクセスすることもでき、正常に動作します。

何が原因でしょうか?

4

1 に答える 1

1

交換:

get :show, cart: @cart

と:

get :show, id: @cart  # or @cart.id
于 2012-09-04T19:47:03.907 に答える