Skip to content

Commit

Permalink
SubdomainFu#current_subdomain will no longer recognize mirrors (will …
Browse files Browse the repository at this point in the history
…return nil instead). Included specs for this.
  • Loading branch information
Michael Bleigh committed Jun 18, 2008
1 parent 915de7a commit fc8d2bc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/subdomain-fu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def self.same_subdomain?(subdomain, host)
result
end

def self.current_subdomain(request)
subdomain = request.subdomains(SubdomainFu.tld_size).join(".")
if has_subdomain?(subdomain)
subdomain
else
nil
end
end

module Controller
def self.included(controller)
controller.helper_method(:current_subdomain)
Expand All @@ -78,7 +87,7 @@ def self.included(controller)
protected

def current_subdomain
request.subdomains(SubdomainFu.tld_size).join(".")
SubdomainFu.current_subdomain(request)
end
end
end
22 changes: 22 additions & 0 deletions spec/subdomain_fu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@
end
end

describe "#current_subdomain" do
it "should return the current subdomain if there is one" do
request = mock("request", :subdomains => ["awesome"])
SubdomainFu.current_subdomain(request).should == "awesome"
end

it "should return nil if there's no subdomain" do
request = mock("request", :subdomains => [])
SubdomainFu.current_subdomain(request).should be_nil
end

it "should return nil if the current subdomain is a mirror" do
request = mock("request", :subdomains => ["www"])
SubdomainFu.current_subdomain(request).should be_nil
end

it "should return the whole thing (including a .) if there's multiple subdomains" do
request = mock("request", :subdomains => ["awesome","rad"])
SubdomainFu.current_subdomain(request).should == "awesome.rad"
end
end

describe "#same_subdomain?" do
it { SubdomainFu.same_subdomain?("www","www.localhost").should be_true }
it { SubdomainFu.same_subdomain?("www","localhost").should be_true }
Expand Down

0 comments on commit fc8d2bc

Please sign in to comment.