2012-09-04 56 views
0

我一直收到的錯誤如下:test_should_get_show(CartsControllerTest):ActionController :: RoutingError:沒有路由匹配{:cart =>「1」,:controller =>「carts」,:action =>「show」}

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在開發環境中的瀏覽器中手動和正常工作。

這可能是什麼原因造成的?

回答

1

替換:

get :show, cart: @cart 

有了:

get :show, id: @cart # or @cart.id 
+0

嗯,這是一個愚蠢的錯誤!謝謝。 –

+0

如果我不立即接受您的回答,我通常會在下次登錄時執行此操作。 –

相關問題