2012-10-01 39 views
1

後,這是我的路線路線錯誤升級軌和旅程路由器

match "/:type/:brand/:model/:plate" => "site/vehicles#show", 
    :constraints => {:plate => /[a-z]{3}\d{4}/}, :as => :vehicle 

它經過的路由測試

# the route test passess  
it "routes to #show" do 
    {:get => '/carro/volksvagen/gol-2-0/abc1234'}.should route_to(
    "site/vehicles#show", 
    :type => "carro", 
    :brand => "volksvagen", 
    :model => "gol-2-0", 
    :plate => "abc1234" 
) 
end 

但升級軌(3.2.0 => 3.2.8後)也更新了旅程(1.0.0 => 1.0.4),下面的CONTROLLER測試(恕我直言不應該檢查路線,它顯然沒有回到rails 3.2.0中)開始失敗。

describe "#show" do 
    it "should be success" do 
    get :show, :plate => @vehicle.plate 
    response.should be_success 
    end 
end 

它提出

Site::VehiclesController#show should be success 
ActionController::RoutingError: 
    No route matches {:plate=>"ABC1672", :controller=>"site/vehicles", 
             :action=>"show"} 

即使我完成所有的路線瓦爾

describe "#show" do 
    it "should be success" do 
    get :show, :plate => @vehicle.plate, :model => 'model', 
     :type => 'type', :brand => 'brand' 
    response.should be_success 
    end 
end 

我得到:

# No route matches {:plate=>"ABC1586", :model=>"model", :type=>"type", 
    :brand=>"brand", :controller=>"site/vehicles", :action=>"show"} 

的應用仍然有效,但我會不知道什麼時候停止,因爲我的測試是fai林志玲。

任何人解決/有類似的問題?

我知道'不升級rails'可以避免出現類似問題中提到的錯誤,但我不認爲這是一個解決方案。

Routing error when updating to Rails 3.2.6 or Rspec 2.11.0

預先感謝您。

編輯:

vehicle /:type/:brand/:model/:plate(.:format) site/vehicles#show {:plate=>/[a-z]{3}\d{4}/} 
+0

出於好奇,你爲什麼接受POST,PUT和DELETE請求到同一個URL? – coreyward

+0

因爲我是新手=)建議? – Marcelo

+0

使用'get'而不是'match',或使用':via'選項。就我個人而言,我認爲導遊應該全面使用'match'作爲主要路線動詞。 http://guides.rubyonrails.org/routing.html#http-verb-constraints – coreyward

回答

1

我覺得你的問題是在你的正則表達式和測試數據之間的不匹配。在您的錯誤信息,我看到:

No route matches {:plate=>"ABC1586", :model=>"model", :type=>"type", 
:brand=>"brand", :controller=>"site/vehicles", :action=>"show"} 

但路線有板下面的正則表達式:

:plate => /[a-z]{3}\d{4}/ 

,要求所有小寫字母;大寫字母不匹配。所以你需要修復你的測試數據,或者修復你的路由中的正則表達式。

+0

Kudos!非常感謝你!我確定我有/我修飾符。 – Marcelo