I am using Ruby 1.9.3 with Rails 3.2 (old, I know).
I am having trouble with one controller test. The routes work just fine, the only problem is the test.
The test is placed in project_root/test/functional/api/ubiquo/work_hours_controller_test.rb
And is defined like this:
# encoding: utf-8
require 'test_helper'
class Api::Ubiquo::WorkHoursControllerTest < ActionController::TestCase
setup :prepare
test "check_already_logged_in_ubiquo: error if not logged in" do
get :check_already_logged_in_ubiquo, format: :json
assert_response :unauthorized
end
def prepare
# I tried both specifying the controller like this and also letting Rails do it
@controller = Api::Ubiquo::WorkHoursController.new
end
end
The controller is placed in project_root/app/controllers/api/ubiquo/work_hours_controller.rb
and is defined like this. (I simplified it to debug)
class Api::Ubiquo::WorkHoursController < Api::Ubiquo::BaseController
def check_already_logged_in_ubiquo
respond_to do |format|
format.json { render json: { message: 'Not logged in' }, status: :unauthorized }
end
end
end
rellevant part of routes.rb
:
scope :path => "api", :format => 'json' do
get 'ubiquo/check_already_logged_in_ubiquo', to: 'api/ubiquo/work_hours#check_already_logged_in_ubiquo'
# I also tried this:
# namespace :ubiquo do
# get 'check_already_logged_in_ubiquo', to: 'api/ubiquo/work_hours#check_already_logged_in_ubiquo'
# end
end
rake routes
returns the correct route (with works when running the app)
ubiquo_check_already_logged_in_ubiquo GET /api/ubiquo/check_already_logged_in_ubiquo(.:format) api/ubiquo/work_hours#check_already_logged_in_ubiquo {:format=>"json"}
The error I get is:
ActionController::RoutingError: No route matches {:format=>:json, :controller=>"api/ubiquo/work_hours", :action=>"check_already_logged_in_ubiquo"}
I have also tried defining the test as class CustomWorkHoursControllerTest < ActionController::TestCase
(without the modules Api::Ubiquo) and then the error does not fire but request just returns 406. In no case the debugger reaches the controller.
All other controller tests are working just fine, including those in /api, just not those in /api/ubiquo.
I really don’t know what else to try.