Skip to content

Commit

Permalink
Remove subdomain with :subdomain => '' on url_for [rails#2025 state:c…
Browse files Browse the repository at this point in the history
…ommitted]
  • Loading branch information
dcadenas committed Aug 5, 2011
1 parent 04f88d1 commit d6fd59c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/http/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/routing/url_for.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/url_for_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions actionpack/test/dispatch/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d6fd59c

Please sign in to comment.