Reputation: 2399
I am a beginner in Rails and using old version 4.0 with Rspec. I want to test on the controller where my route is following.
/properties/:property_id/build
I can test /properties/1 by writing the following
get :show, id: properties
expect(response).to have_http_status(:success)
But not sure how can I write property's id number to build controller whose route is above. It means to show the method I have to put properties id and build but later on for update I have to put two parameters.
Upvotes: 2
Views: 2244
Reputation: 2399
I am a beginner so I think I got the incorrect understanding of Routing and controller tests. As it was still giving an error and after discussing with another programmer. I finally resolved using the following pattern.
get :new, property_id: property.id
Upvotes: 0
Reputation: 1902
You can pass property_id
with params like
get :build, params: { property_id: property.id } #You pass additional parameters with this.
Here property_id is :property_id
in /properties/:property_id/build
Upvotes: 3
Reputation: 942
If its a get
request then,
get :build, params: {id: properties, second_param: "something" }
(assuming properties
is the Property
object from your example and the second param is second_param
)
Upvotes: 1