Dear all,
I have a module ApiAccessControl which is included in all controllers
which deal with the API. It sees if the users is valid, logs etc etc.
I want to see if this module does what it is supposed to but I dont
want to test that in every single controller dealing with the API. So
I created a file api_access_control_spec.rb with this content:
require File.dirname(FILE) + ‘/…/spec_helper’
class ApiAccessControlTestController < ApplicationController
include ApiAccessControl
end
describe ApiAccessControlTestController do
describe “without valid credentials” do
it “should respond with a 401 Unauthorized on the GET ‘index’” do
get “index”
response.response_code.should == 401
end
end
end
This works by the grace that my routes file has a fallback map.connect
‘:controller/:action/:id’. I never use that fallback only for this
particular test. Is there anyway to get rid of this entry in my
routes.rb?
I tried something like this is a before block:
ActionController::Routing::RouteSet.new.add_route(“index”, :controller
=> “api_access_control_test”, :action => “index”)
But that doesn’t seem to work. How do you guys test this sort of
stuff?
Harm