Testing your subdomain based rails application
I was looking for a way to set the request host when testing an application I am currently working on. It has ‘basecamp-style’ subdomains; I wanted to test these.
Insert the following snippet at the bottom of test_helper.rb to set the host to ‘test.local.host’
# This is a hack on rails to allow testing of subdomain based systems.
require 'active_support/test_case'
module ActionController
class TestCase < ActiveSupport::TestCase
def setup_controller_request_and_response
@controller = self.class.controller_class.new
@controller.request = @request = TestRequest.new
@response = TestResponse.new
@request.host = "test.local.host"
@controller.params = {}
@controller.send(:initialize_current_url)
end
end
end