【发布时间】:2016-02-01 05:25:17
【问题描述】:
我已经在这几个小时了,仍然无法弄清楚。我对嵌套资源控制器上的 2 个操作进行了 2 个测试。 requests 是父资源路由,response 是嵌套资源路由。
这两个测试给了我一个no route matches 错误。没有意义。在第一个测试中,它尝试运行update 操作而不是edit。这是我的测试:
test "should get edit" do
assert_routing edit_request_response_path(@myresponse.request_id, @myresponse), { :controller => "responses", :action => "edit", :request_id => @myresponse.request_id.to_s, :id => @myresponse.id.to_s }
get :edit, params: { id: @myresponse, request_id: @myresponse.request_id }
assert_response :success
end
test "should update response" do
post :update, :request_id => @myresponse.request_id, response: { body: @myresponse.body, request_id: @myresponse.request_id, status: @myresponse.status, subject: @myresponse.subject, user_id: @myresponse.user_id }
assert_redirected_to response_path(assigns(:response))
end
以下是错误:
3) Error:
ResponsesControllerTest#test_should_get_edit:
ActionController::UrlGenerationError: No route matches {:action=>"edit", :controller=>"responses", :params=>{:id=>"980190962", :request_id=>"999788447"}}
test/controllers/responses_controller_test.rb:43:in `block in <class:ResponsesControllerTest>'
4) Error:
ResponsesControllerTest#test_should_update_response:
ActionController::UrlGenerationError: No route matches {:action=>"update", :controller=>"responses", :request_id=>"999788447", :response=>{:body=>"This is the body", :request_id=>"999788447", :status=>"draft", :subject=>"This is the subject", :user_id=>"175178709"}}
test/controllers/responses_controller_test.rb:48:in `block in <class:ResponsesControllerTest>'
【问题讨论】:
标签: ruby-on-rails ruby unit-testing ruby-on-rails-4 testing