尝试 运行 测试时出现 UrlGenerationError
Getting UrlGenerationErrorr when trying to run test
1) Error:
SummariesControllerTest#test_should_get_edit:
ActionController::UrlGenerationError: No route matches {:action=>"edit", :controller=>"summaries", :summary=>"298486374", :summary_id=>"298486374"}
test/controllers/summaries_controller_test.rb:23:in `block in '
这是导致错误的测试
test "should update summary" do
xhr :patch, :udpate, id: @summary.id, summary: { text: @summary.text }
assert_response :success
end
控制器动作:
def update
@listing = Listing.find(summary_params[:listing_id])
@summary = Summary.find(params[:id])
@summary.update_attributes(listing_id: summary_params[:listing_id], text: summary_params[:text], id: params[:id])
end
和路线:
Rails.application.routes.draw do
resources :listings
resources :summaries
resources :highlights
end
路线有,动作也有,但出现错误,有人看到我的错误吗?谢谢你的帮助。
你有一个错字(单词"update"):
xhr :patch, :udpate, id: @summary.id, summary: { text: @summary.text }
应该是:
xhr :patch, :update, id: @summary.id, summary: { text: @summary.text }
test "should update summary" do
xhr :patch, :udpate, id: @summary.id, summary: { text: @summary.text }
assert_response :success
end
嘿,谢谢你的回复,路线没有问题,但我确实必须传递 id: @summary.id 因为它需要它来进行列表。我改了测试通过了
1) Error: SummariesControllerTest#test_should_get_edit: ActionController::UrlGenerationError: No route matches {:action=>"edit", :controller=>"summaries", :summary=>"298486374", :summary_id=>"298486374"} test/controllers/summaries_controller_test.rb:23:in `block in '
这是导致错误的测试
test "should update summary" do
xhr :patch, :udpate, id: @summary.id, summary: { text: @summary.text }
assert_response :success
end
控制器动作:
def update
@listing = Listing.find(summary_params[:listing_id])
@summary = Summary.find(params[:id])
@summary.update_attributes(listing_id: summary_params[:listing_id], text: summary_params[:text], id: params[:id])
end
和路线:
Rails.application.routes.draw do
resources :listings
resources :summaries
resources :highlights
end
路线有,动作也有,但出现错误,有人看到我的错误吗?谢谢你的帮助。
你有一个错字(单词"update"):
xhr :patch, :udpate, id: @summary.id, summary: { text: @summary.text }
应该是:
xhr :patch, :update, id: @summary.id, summary: { text: @summary.text }
test "should update summary" do
xhr :patch, :udpate, id: @summary.id, summary: { text: @summary.text }
assert_response :success
end
嘿,谢谢你的回复,路线没有问题,但我确实必须传递 id: @summary.id 因为它需要它来进行列表。我改了测试通过了