尝试运行测试时获取UrlGenerationError

时间:2015-02-06 20:56:43

标签: ruby-on-rails ajax testunit

  

1)错误:   SummariesControllerTest#test_should_get_edit:   ActionController :: UrlGenerationError:没有路由匹配{:action =>"编辑",:controller =>"摘要",:summary =>" 298486374" ,:summary_id =>" 298486374"}       test / controllers / summaries_controller_test.rb:23:在`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

enter image description here

路线在那里,动作也出现了错误,是否有人看到我的错误?谢谢你的帮助。

2 个答案:

答案 0 :(得分:0)

你有一个拼写错误(在单词" update"):

xhr :patch, :udpate, id: @summary.id, summary: { text: @summary.text }

应该是:

xhr :patch, :update, id: @summary.id, summary: { text: @summary.text }

答案 1 :(得分:0)

test "should update summary" do
  xhr :patch, :udpate, id: @summary.id, summary: { text: @summary.text }
  assert_response :success
end

嘿谢谢你的回复,路线没有问题,但我确实要传递id:@ summary.id,因为它需要列表。我改变了测试并且通过了。