小编Jef*_*gal的帖子

Rails 3上嵌套路由的功能测试

我有一个带有以下嵌套路由的Rails 3应用程序:

resources :games do
  collection do
    get :all
    get :unassigned
  end
  resources :messages
  resources :comments
end
Run Code Online (Sandbox Code Playgroud)

游戏有很多评论,游戏也有很多消息.

我期待"/ games/1/comments"路由到注释控制器上的索引操作,并设置:game_id => 1在params哈希中.

在应用程序中一切正常.但是,我的路线测试失败了,我无法弄清楚原因.

当我尝试这个:

assert_routing({:path => "/games/1/messages", :method => :get},
  { :controller => "messages", :action => "index", :game_id => 1})
Run Code Online (Sandbox Code Playgroud)

我明白了:

  2) Failure:
test_route_one(MessagesControllerTest)
    [actionpack (3.0.3) lib/action_dispatch/testing/assertions/routing.rb:52:in `assert_recognizes'
     actionpack (3.0.3) lib/action_dispatch/testing/assertions/routing.rb:120:in `assert_routing'
     test/functional/messages_controller_test.rb:106:in `test_route_one'
     activesupport (3.0.3) lib/active_support/testing/setup_and_teardown.rb:67:in `__send__'
     activesupport (3.0.3) lib/active_support/testing/setup_and_teardown.rb:67:in `run'
     activesupport (3.0.3) lib/active_support/callbacks.rb:438:in `_run_setup_callbacks'
     activesupport (3.0.3) lib/active_support/testing/setup_and_teardown.rb:65:in `run']:
The recognized options <{"action"=>"index", "game_id"=>"1", "controller"=>"messages"}> 
did not …
Run Code Online (Sandbox Code Playgroud)

routing unit-testing ruby-on-rails ruby-on-rails-3

2
推荐指数
1
解决办法
1709
查看次数