Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8863339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:57:14+00:00 2026-06-14T15:57:14+00:00

I try to test one of my REST api controllers which is placed at

  • 0

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:

class Api::V1::BookingsController < ApplicationController
  respond_to :json  
  before_filter :authenticate_user!
  before_filter :get_user

  def create
    ...
  end 
end

My functional test is located at “test/functional/api/v1/bookings_controller_test.rb” and looks like following:

require 'test_helper'

class Api::V1::BookingsControllerTest < 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 => { }, :format  => 'json'
    assert_response :bad_request
  end

end

The post path for creating a booking looks like this (and works, tested with HTTP Client):

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

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?

test_should_return_a_bad_request(Api::V1::BookingsControllerTest):
ActionController::RoutingError: No route matches {:booking=>{}, :format=>"js
on", :controller=>"api/v1/bookings", :action=>"create"}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:57:16+00:00Added an answer on June 14, 2026 at 3:57 pm

    Your route expects a user_id parameter. Add it to your post:

    post :create, :user_id => @user.id, :booking => {}, :format => :json
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to test one of my app in which I used Three20 sdk.
I was doing a little test to try Ruby's pty and I can't get
I am trying ot write an integration test for one of my controller classes
When I try a test program with just these two lines char array[256]; char**
Whenever I try to test my code with JUnit, I receive a NullPointerException -
I keep getting 21002 'java.lang.NullPointerException' errors from Apple when I try to test my
I am doing the below test to try and learn more about LINQ to
the code below gives compilation error when I try to create test t[2]; because
i have problem with maven. When i try to compile test classes ( mvn
What test text do you try and type into your web forms to check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.