Ruby on rails 一条匹配的路由覆盖另一条,但不应';T
在routes.rb中,我有:Ruby on rails 一条匹配的路由覆盖另一条,但不应';T,ruby-on-rails,ruby,testing,routing,Ruby On Rails,Ruby,Testing,Routing,在routes.rb中,我有: [some routes] match '/me' => "scores#all_athlete_scores", :constraints => LoggedInChecker devise_scope :user do match '/me' => "devise/sessions#new" end match '/scores/athlete/:id', :to =>"scores#all_athlete_scores", :
[some routes]
match '/me' => "scores#all_athlete_scores", :constraints => LoggedInChecker
devise_scope :user do
match '/me' => "devise/sessions#new"
end
match '/scores/athlete/:id', :to =>"scores#all_athlete_scores", :as => "all_athlete_scores"
[some more routes]
def test_get_all_athlete_scores
[set up]
get :all_athlete_scores, :id => @user
end
如果用户已登录,LoggedInChecker将返回true;如果未登录,则返回false。如果为false,则第二条路由将其拾取并将用户发送到登录页面
在scores_controller_test.rb中,我有:
[some routes]
match '/me' => "scores#all_athlete_scores", :constraints => LoggedInChecker
devise_scope :user do
match '/me' => "devise/sessions#new"
end
match '/scores/athlete/:id', :to =>"scores#all_athlete_scores", :as => "all_athlete_scores"
[some more routes]
def test_get_all_athlete_scores
[set up]
get :all_athlete_scores, :id => @user
end
奇怪的是这个请求。分数控制测试中过滤的参数[:full\u path]是/me?id=@user.id,而不是/scores/atternate/:id'
如果我将routes.rb更改为:
[some routes]
match '/scores/athlete/:id', :to =>"scores#all_athlete_scores", :as => "all_athlete_scores"
match '/me' => "scores#all_athlete_scores", :constraints => LoggedInChecker
devise_scope :user do
match '/me' => "devise/sessions#new"
end
[some more routes]
测试工作正常,需要。过滤的_参数[:完整路径]=/scores/atternate/:id
对此完全困惑-/我不应该在获得所有运动员的分数时被匹配
有什么想法吗?Kareem
我认为困惑在于,你有一个方法和一个命名路线“所有运动员得分”
get :all_athlete_scores, :id => @user
调用方法all_Athletor_scores,而不是您所期望的命名路线
可能应该在这个测试中测试该方法的功能,并将路由测试留给另一个测试
希望有帮助