Permalink
Browse files

added current_domain method

  • Loading branch information...
1 parent c01ed8e commit a4fed2d0d7b24c38eeabfccc14bea943f740f6ea @pboling pboling committed Sep 13, 2009
Showing with 39 additions and 2 deletions.
  1. +1 −1 install.sh
  2. +10 −0 lib/subdomain-fu.rb
  3. +27 −0 spec/subdomain_fu_spec.rb
  4. +1 −1 subdomain-fu.gemspec
View
@@ -1,2 +1,2 @@
# I use this to make life easier when installing and testing from source:
-rm -rf subdomain-fu-*.gem && gem build subdomain-fu.gemspec && sudo gem uninstall subdomain-fu && sudo gem install subdomain-fu-0.3.0.gem --no-ri --no-rdoc
+rm -rf subdomain-fu-*.gem && gem build subdomain-fu.gemspec && sudo gem uninstall subdomain-fu && sudo gem install subdomain-fu-0.4.1.gem --no-ri --no-rdoc
View
@@ -137,14 +137,24 @@ def self.current_subdomain(request)
end
end
+ def self.current_domain(request)
+ domain = ""
+ domain << request.subdomains[1..-1].join(".") + "." if request.subdomains.length > 1
+ domain << request.domain + request.port_string
+ end
+
module Controller
def self.included(controller)
controller.helper_method(:current_subdomain)
+ controller.helper_method(:current_domain)
end
protected
def current_subdomain
SubdomainFu.current_subdomain(request)
end
+ def current_domain
+ SubdomainFu.current_domain(request)
+ end
end
end
View
@@ -159,6 +159,33 @@
end
end
+ describe "#current_domain" do
+ it "should return the current domain if there is one" do
+ request = mock("request", :subdomains => [], :domain => "example.com", :port_string => "")
+ SubdomainFu.current_domain(request).should == "example.com"
+ end
+
+ it "should return empty string if there is no domain" do
+ request = mock("request", :subdomains => [], :domain => "", :port_string => "")
+ SubdomainFu.current_domain(request).should == ""
+ end
+
+ it "should return the current domain if there is only one level of subdomains" do
+ request = mock("request", :subdomains => ["www"], :domain => "example.com", :port_string => "")
+ SubdomainFu.current_domain(request).should == "example.com"
+ end
+
+ it "should return everything but the first level of subdomain when there are multiple levels of subdomains" do
+ request = mock("request", :subdomains => ["awesome","rad","cheese","chevy","ford"], :domain => "example.com", :port_string => "")
+ SubdomainFu.current_domain(request).should == "rad.cheese.chevy.ford.example.com"
+ end
+
+ it "should return the domain with port if port is given" do
+ request = mock("request", :subdomains => ["awesome","rad","cheese","chevy","ford"], :domain => "example.com", :port_string => ":3000")
+ SubdomainFu.current_domain(request).should == "rad.cheese.chevy.ford.example.com:3000"
+ 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 }
View
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{subdomain-fu}
- s.version = "0.4.0"
+ s.version = "0.4.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Michael Bleigh"]

0 comments on commit a4fed2d

Please sign in to comment.