Skip to content

Instantly share code, notes, and snippets.

@jrbruce
Created November 24, 2010 02:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrbruce/712968 to your computer and use it in GitHub Desktop.
Save jrbruce/712968 to your computer and use it in GitHub Desktop.
#admin_routes_spec.rb
require "spec_helper"
describe "Admin Routes" do
describe "GET '/admin'" do
it "should block access if not on www" do
{ :get => "http://foo.example.com/admin" }.should_not be_routable
end
it "should allow access if on www" do
{ :get => "http://www.example.com/admin" }.should route_to(:controller => "admin/dashboards", :action => "show")
end
end
end
# routes.rb (excerpt)
namespace :admin do
constraints(RootDomain) do
resource :dashboard, :only => :show
root :to => "dashboards#show"
end
end
# app/lib/root_domain.rb
class RootDomain
def self.matches?(request)
request.subdomain.blank? || request.subdomain == "www"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment