Search code examples
ruby-on-railsrspec-rails

How to make rspec with multiple parameters?


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.


Solution

  • 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