我自学写控制器测试,并正在此得到这个错误:Rails的控制器测试:ActionController的:: UrlGenerationError:没有路由匹配
ERROR["test_should_update_post", PostsControllerTest, 2015-10-11 12:12:31 -0400]
test_should_update_post#PostsControllerTest (1444579951.69s)
ActionController::UrlGenerationError: ActionController::UrlGenerationError: No route matches {:action=>"update", :controller=>"posts", :post=>{:title=>"My Post", :body=>"Updated Ipsum"}}
test/controllers/posts_controller_test.rb:51:in `block (2 levels) in <class:PostsControllerTest>'
test/controllers/posts_controller_test.rb:50:in `block in <class:PostsControllerTest>’
这是我的测试:
test "should update post" do
assert_difference('Post.count') do
put :update, post: {title: 'My Post', body: 'Updated Ipsum'}
end
assert_redirected_to post_path(assigns(:post))
end
这是我的YAML:
entry_one:
title: "Foobar"
body: "Ipsum This"
entry_two:
title: "Barfoo"
body: "This Ipsum"
,这是我的控制器:
def update
@post = Post.find(params[:id])
if @post.update(post_params)
redirect_to @post, notice: 'Event updated successfully'
else
render :edit
end
end
您能否指出我需要解决的问题?
我可以从错误告诉我们,行数,它的东西做的线: assert_difference('Post.count') do
和put :update, post: {title: 'My Post', body: 'Updated Ipsum’}
非常感谢。作为'@ post.id',我在''中通过我的夹具。这解决了问题。 –
Storycoder