2012-10-01 38 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