Rails 4.0.0。
test "routing balance" do
assert_generates '/users/1/balance', { controller: 'users', action: 'balance', id: '1' }
1) Error:
UsersControllerTest#test_routing_balance:
ActionController::UrlGenerationError: No route matches {:controller=>"users", :action=>"balance", :id=>"1"}
test/controllers/users_controller_test.rb:18:in `block in <class:UsersControllerTest>'
irb(main):229:0> app.user_balance_path 1
=> "/users/1/balance"
http://localhost:3000/users/1/balance
resources :users do
get 'balance', to: :balance
user_balance GET /users/:user_id/balance(.:format) users#balance
test "routing" do
assert_generates '/users/1', { controller: 'users', action: 'show', id: '1' }
http://guides.rubyonrails.org/testing.html#rails-specific-assertions
答案 0 :(得分:1)
尝试在测试中使用'user_id'而不是'id',因为这是您在路线中的内容