如何在 minitest 中引用创建方法来测试控制器?
How do I refer to a create method in a minitest to test the controller?
我正在使用 Rails 5 和 minitest。我如何在我的测试中引用 create URL 来测试控制器的创建方法?在我的路线文件中,我有
resources :items
在我的测试文件中,我有
test "do create" do
person = people(:one)
rating = 10
post items_create_url, params: {person_id: person.id, rating: rating}
# Verify we got the proper response
assert_response :success
end
然而,上面的测试正在死于
undefined local variable or method `items_create_url'
错误。在测试中引用我的创建方法的正确方法是什么?
在RESTful路线中,模型被认为是事物的集合。当您创建新项目时,您正在将新项目(数据)发布到现有项目的集合中,因此 Rails 使用:
post items_url, params: {person_id: person.id, rating: rating}
有关路由的更多信息,Rails 指南确实是最好的信息来源:http://guides.rubyonrails.org/routing.html
我正在使用 Rails 5 和 minitest。我如何在我的测试中引用 create URL 来测试控制器的创建方法?在我的路线文件中,我有
resources :items
在我的测试文件中,我有
test "do create" do
person = people(:one)
rating = 10
post items_create_url, params: {person_id: person.id, rating: rating}
# Verify we got the proper response
assert_response :success
end
然而,上面的测试正在死于
undefined local variable or method `items_create_url'
错误。在测试中引用我的创建方法的正确方法是什么?
在RESTful路线中,模型被认为是事物的集合。当您创建新项目时,您正在将新项目(数据)发布到现有项目的集合中,因此 Rails 使用:
post items_url, params: {person_id: person.id, rating: rating}
有关路由的更多信息,Rails 指南确实是最好的信息来源:http://guides.rubyonrails.org/routing.html