Skip to content

Instantly share code, notes, and snippets.

@alistairholt
Created August 11, 2009 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alistairholt/62b19d8e8d26e392a4b4 to your computer and use it in GitHub Desktop.
Save alistairholt/62b19d8e8d26e392a4b4 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
before_filter :set_current_account
private
def set_current_account
unless current_account
render :text => "Account doesn't exist", :status => "404 Not Found"
end
end
def account_subdomain
request.subdomains.first
end
def current_account
return @current_account if defined?(@current_account)
@current_account = Account.find_by_subdomain(account_subdomain)
end
end
class FooControllerTest < ActionController::TestCase
fixtures :accounts
context "A valid account subdomain" do
setup do
@request.host = "foobar.domain.com"
end
should "set an Account instance from the subdomain" do
get :index
assert_equal accounts(:foobar), current_account
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment