Permalink
Browse files

Fix .subdomain regression.

  • Loading branch information...
1 parent a93bd11 commit 6b79463ed8d04c7807c0695fcb3d4c11e4be9fa2 @josevalim josevalim committed May 4, 2011
Showing with 10 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_dispatch/http/url.rb
  2. +9 −0 actionpack/test/dispatch/request_test.rb
@@ -165,7 +165,7 @@ def subdomains(tld_length = @@tld_length)
# such as 2 to catch <tt>["www"]</tt> instead of <tt>"www.rubyonrails"</tt>
joshk
joshk May 4, 2011 Contributor

you might want to change the docs as well (minus the array brackets)

# in "www.rubyonrails.co.uk".
def subdomain(tld_length = @@tld_length)
- subdomains(tld_length)
+ subdomains(tld_length).join(".")
end
end
end
@@ -137,30 +137,39 @@ def url_for(options = {})
test "subdomains" do
request = stub_request 'HTTP_HOST' => "www.rubyonrails.org"
assert_equal %w( www ), request.subdomains
+ assert_equal "www", request.subdomain
request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk"
assert_equal %w( www ), request.subdomains(2)
+ assert_equal "www", request.subdomain(2)
request = stub_request 'HTTP_HOST' => "dev.www.rubyonrails.co.uk"
assert_equal %w( dev www ), request.subdomains(2)
+ assert_equal "dev.www", request.subdomain(2)
request = stub_request 'HTTP_HOST' => "dev.www.rubyonrails.co.uk", :tld_length => 2
assert_equal %w( dev www ), request.subdomains
+ assert_equal "dev.www", request.subdomain
request = stub_request 'HTTP_HOST' => "foobar.foobar.com"
assert_equal %w( foobar ), request.subdomains
+ assert_equal "foobar", request.subdomain
request = stub_request 'HTTP_HOST' => "192.168.1.200"
assert_equal [], request.subdomains
+ assert_equal "", request.subdomain
request = stub_request 'HTTP_HOST' => "foo.192.168.1.200"
assert_equal [], request.subdomains
+ assert_equal "", request.subdomain
request = stub_request 'HTTP_HOST' => "192.168.1.200.com"
assert_equal %w( 192 168 1 ), request.subdomains
+ assert_equal "192.168.1", request.subdomain
request = stub_request 'HTTP_HOST' => nil
assert_equal [], request.subdomains
+ assert_equal "", request.subdomain
end
test "standard_port" do

0 comments on commit 6b79463

Please sign in to comment.