Permalink
Browse files

Remove subdomain with :subdomain => '' on url_for [#2025 state:commit…

…ted]
  • Loading branch information...
1 parent 04f88d1 commit d6fd59c0ae48284cc06fdec8b0ba575e0d401f34 @dcadenas committed Aug 5, 2011
@@ -70,7 +70,7 @@ def host_or_subdomain_and_domain(options)
host = ""
host << (options[:subdomain] || extract_subdomain(options[:host], tld_length))
- host << "."
+ host << "." unless host.blank?
host << (options[:domain] || extract_domain(options[:host], tld_length))
host
end
@@ -116,7 +116,7 @@ def url_options
# If <tt>:only_path</tt> is false, this option must be
# provided either explicitly, or via +default_url_options+.
# * <tt>:subdomain</tt> - Specifies the subdomain of the link, using the +tld_length+
- # to split the domain from the host.
+ # to split the domain from the host. An empty string removes the subdomain.
# * <tt>:domain</tt> - Specifies the domain of the link, using the +tld_length+
# to split the subdomain from the host.
# * <tt>:tld_length</tt> - Number of labels the TLD id composed of, only used if
@@ -67,6 +67,13 @@ def test_subdomain_may_be_changed
)
end
+ def test_subdomain_may_be_removed
+ add_host!
+ assert_equal('http://basecamphq.com/c/a/i',
+ W.new.url_for(:subdomain => '', :controller => 'c', :action => 'a', :id => 'i')
+ )
+ end
+
def test_domain_may_be_changed
add_host!
assert_equal('http://www.37signals.com/c/a/i',
@@ -15,6 +15,7 @@ def url_for(options = {})
assert_equal 'http://www.example.com', url_for
assert_equal 'http://api.example.com', url_for(:subdomain => 'api')
+ assert_equal 'http://example.com', url_for(:subdomain => '')
assert_equal 'http://www.ror.com', url_for(:domain => 'ror.com')
assert_equal 'http://api.ror.co.uk', url_for(:host => 'www.ror.co.uk', :subdomain => 'api', :tld_length => 2)
assert_equal 'http://www.example.com:8080', url_for(:port => 8080)

0 comments on commit d6fd59c

Please sign in to comment.