Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 1 stable url subdomain with numeric host #3561

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -64,7 +64,7 @@ def rewrite_authentication(options)
end

def host_or_subdomain_and_domain(options)
return options[:host] unless options[:subdomain] || options[:domain]
return options[:host] unless (options[:subdomain] || options[:domain]) and named_host?(options[:host])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use && instead of and. Rails conventions asks to user the former.


tld_length = options[:tld_length] || @@tld_length

Expand Down
11 changes: 11 additions & 0 deletions actionpack/test/controller/url_for_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def add_host!
W.default_url_options[:host] = 'www.basecamphq.com'
end

def add_numeric_host!
W.default_url_options[:host] = '127.0.0.1'
end

def test_exception_is_thrown_without_host
assert_raise ArgumentError do
W.new.url_for :controller => 'c', :action => 'a', :id => 'i'
Expand Down Expand Up @@ -67,6 +71,13 @@ def test_subdomain_may_be_changed
)
end

def test_subdomain_may_be_accepted_with_numeric_host
add_numeric_host!
assert_equal('http://127.0.0.1/c/a/i',
W.new.url_for(:subdomain => 'api', :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