Note that there are some explanatory texts on larger screens.

plurals
  1. PORails testing, how to specify path for post? (No route matches error)
    primarykey
    data
    text
    <p>I try to test one of my REST api controllers which is placed at "controllers/api/v1/bookings_controller.rb". The controller only responds_to json at the moment as you can see here:</p> <pre><code>class Api::V1::BookingsController &lt; ApplicationController respond_to :json before_filter :authenticate_user! before_filter :get_user def create ... end end </code></pre> <p>My functional test is located at "test/functional/api/v1/bookings_controller_test.rb" and looks like following:</p> <pre><code>require 'test_helper' class Api::V1::BookingsControllerTest &lt; ActionController::TestCase include Devise::TestHelpers setup do @booking = bookings(:one) @user = users(:one) sign_in @user end test "should return a bad request" do post :create, :booking =&gt; { }, :format =&gt; 'json' assert_response :bad_request end end </code></pre> <p>The post path for creating a booking looks like this (and works, tested with HTTP Client):</p> <pre><code>api_v1_user_bookings GET /api/v1/users/:user_id/bookings(.:format) api/v1/bookings#index POST /api/v1/users/:user_id/bookings(.:format) api/v1/bookings#create </code></pre> <p>However when I run the test it seems that it uses some default route (see error message below), how can i specify the correct route in my test? Or is there some other mistake I do not see here?</p> <pre><code>test_should_return_a_bad_request(Api::V1::BookingsControllerTest): ActionController::RoutingError: No route matches {:booking=&gt;{}, :format=&gt;"js on", :controller=&gt;"api/v1/bookings", :action=&gt;"create"} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload