Reputation: 19260
I'm using Rails 5 and minitest. How do I refer to a create URL in my test meant to test out the controller's create method? In my routes file, I have
resources :items
And in my test file, I have
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
However, the above test is dying with a
undefined local variable or method `items_create_url'
error. What's the right way to refer to my create method in the test?
Upvotes: 0
Views: 402
Reputation: 27747
In RESTful routes, models are considered to be a collection of things. As you are creating a new item, you are posting a new item (the data) to the collection of existing items, so Rails uses:
post items_url, params: {person_id: person.id, rating: rating}
For more info on routing, the Rails guides really are the best source of info: http://guides.rubyonrails.org/routing.html
Upvotes: 1