Permalink
Browse files

Fixed that setting the :host option in url_for would automatically tu…

…rn off :only_path (since :host would otherwise not be shown) (closes #9586) [Bounga]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7542 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent a7764d8 commit 39de84d96739012d2b2d8fd76976bbd798cd2573 @dhh dhh committed Sep 22, 2007
View
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that setting the :host option in url_for would automatically turn off :only_path (since :host would otherwise not be shown) #9586 [Bounga]
+
* Added FormHelper#label #8641 [jcoglan]
* Added AtomFeedHelper (slightly improved from the atom_feed_helper plugin) [DHH]
@@ -20,7 +20,7 @@ module UrlHelper
#
# ==== Options
# * <tt>:anchor</tt> -- specifies the anchor name to be appended to the path.
- # * <tt>:only_path</tt> -- if true, returns the relative URL (omitting the protocol, host name, and port) (<tt>true</tt> by default)
+ # * <tt>:only_path</tt> -- if true, returns the relative URL (omitting the protocol, host name, and port) (<tt>true</tt> by default unless <tt>:host</tt> is specified)
# * <tt>:trailing_slash</tt> -- if true, adds a trailing slash, as in "/archive/2005/". Note that this
# is currently not recommended since it breaks caching.
# * <tt>:host</tt> -- overrides the default (current) host if provided
@@ -65,7 +65,8 @@ module UrlHelper
def url_for(options = {})
case options
when Hash
- options = { :only_path => true }.update(options.symbolize_keys)
+ show_path = options[:host].nil? ? true : false
+ options = { :only_path => show_path }.update(options.symbolize_keys)
escape = options.key?(:escape) ? options.delete(:escape) : true
url = @controller.send(:url_for, options)
when String
@@ -82,6 +82,24 @@ def test_button_to_with_method_get
def test_link_tag_with_straight_url
assert_dom_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", "http://www.example.com")
end
+
+ def test_link_tag_without_host_option
+ ActionController::Base.class_eval { attr_accessor :url }
+ url = {:controller => 'weblog', :action => 'show'}
+ @controller = ActionController::Base.new
+ @controller.request = ActionController::TestRequest.new
+ @controller.url = ActionController::UrlRewriter.new(@controller.request, url)
+ assert_dom_equal(%q{<a href="/weblog/show">Test Link</a>}, link_to('Test Link', url))
+ end
+
+ def test_link_tag_with_host_option
+ ActionController::Base.class_eval { attr_accessor :url }
+ url = {:controller => 'weblog', :action => 'show', :host => 'www.example.com'}
+ @controller = ActionController::Base.new
+ @controller.request = ActionController::TestRequest.new
+ @controller.url = ActionController::UrlRewriter.new(@controller.request, url)
+ assert_dom_equal(%q{<a href="http://www.example.com/weblog/show">Test Link</a>}, link_to('Test Link', url))
+ end
def test_link_tag_with_query
assert_dom_equal "<a href=\"http://www.example.com?q1=v1&amp;q2=v2\">Hello</a>", link_to("Hello", "http://www.example.com?q1=v1&amp;q2=v2")
@@ -175,7 +193,7 @@ def test_link_tag_using_post_javascript_and_confirm
def test_link_tag_using_post_javascript_and_popup
assert_raises(ActionView::ActionViewError) { link_to("Hello", "http://www.example.com", :popup => true, :method => :post, :confirm => "Are you serious?") }
end
-
+
def test_link_to_unless
assert_equal "Showing", link_to_unless(true, "Showing", :action => "show", :controller => "weblog")
assert_dom_equal "<a href=\"http://www.example.com\">Listing</a>", link_to_unless(false, "Listing", :action => "list", :controller => "weblog")

0 comments on commit 39de84d

Please sign in to comment.