Ruby on rails 使用:path=>;测试嵌套轨道路线'';

Ruby on rails 使用:path=>;测试嵌套轨道路线'';,ruby-on-rails,ruby,ruby-on-rails-4,testing,controller,Ruby On Rails,Ruby,Ruby On Rails 4,Testing,Controller,在我的路线中,我有 resources :users, :path => '', param: :name do resources :locations end 这使我的URL完全符合我的需要,例如 然而,我就是不知道如何测试它们。我查过了,但似乎还不够 setup do @location = locations(:one) @user = users(:one) end test "should get index" do get :index, user_id:

在我的路线中,我有

resources :users, :path => '', param: :name do
  resources :locations
end
这使我的URL完全符合我的需要,例如

然而,我就是不知道如何测试它们。我查过了,但似乎还不够

setup do
  @location = locations(:one)
  @user = users(:one)
end

test "should get index" do
  get :index, user_id: @user.name
  assert_response :success
  assert_not_nil assigns(:locations)
end

有人能给我指出正确的方向吗?或者有更好的(且可测试的)方法来实现我的URL模式吗?

您是否尝试过使用路径帮助器?()例如,
users\u path(@user.name)
而不是
get
。据我所知,路径和url帮助程序仅在控制器和视图中可用,@britoAlso,您可以(应该?)使用RSpec,然后您就可以使用路径帮助程序(请参阅)。我想说使用rspec会比你现在做的更好,更易测试:)我来看看rspec,谢谢!你试过使用路径帮助器吗?()例如,
users\u path(@user.name)
而不是
get
。据我所知,路径和url帮助程序仅在控制器和视图中可用,@britoAlso,您可以(应该?)使用RSpec,然后您就可以使用路径帮助程序(请参阅)。我想说使用rspec会比你现在做的更好,更易测试:)我来看看rspec,谢谢!