Permalink
Browse files

Force *_url named routes to show the host in ActionView [Rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5325 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 351a224 commit 1d7196b55272d5f900a3080387319686e395b981 @technoweenie technoweenie committed Oct 20, 2006
View
@@ -1,5 +1,11 @@
*SVN*
+* Force *_url named routes to show the host in ActionView [Rick]
+
+ <%= url_for ... %> # no host
+ <%= foo_path %> # no host
+ <%= foo_url %> # host!
+
* Add support for converting blocks into function arguments to JavaScriptGenerator#call and JavaScriptProxy#call. [Sam Stephenson]
* Add JavaScriptGenerator#literal for wrapping a string in an object whose #to_json is the string itself. [Sam Stephenson]
@@ -1039,7 +1039,7 @@ def hash_access_name(name, kind = :url)
end
def define_named_route_methods(name, route)
- {:url => {}, :path => {:only_path => true}}.each do |kind, opts|
+ {:url => {:only_path => false}, :path => {:only_path => true}}.each do |kind, opts|
hash = route.defaults.merge(:use_route => name).merge(opts)
define_hash_access route, name, kind, hash
define_url_helper route, name, kind, hash
@@ -28,7 +28,7 @@ def test_url_for_escapes_urls
assert_equal "http://www.example.com?a=b&amp;c=d", url_for(:a => 'b', :c => 'd', :escape => true)
assert_equal "http://www.example.com?a=b&c=d", url_for(:a => 'b', :c => 'd', :escape => false)
end
-
+
# todo: missing test cases
def test_button_to_with_straight_url
assert_dom_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com")
@@ -237,3 +237,58 @@ def test_mail_to_with_replace_options
assert_dom_equal "<script type=\"text/javascript\">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)")
end
end
+
+class UrlHelperWithControllerTest < Test::Unit::TestCase
+ class UrlHelperController < ActionController::Base
+ self.template_root = "#{File.dirname(__FILE__)}/../fixtures/"
+
+ def self.controller_path; 'url_helper_with_controller' end
+
+ def show_url_for
+ render :inline => "<%= url_for :controller => 'url_helper_with_controller', :action => 'show_url_for' %>"
+ end
+
+ def show_named_route
+ render :inline => "<%= show_named_route_#{params[:kind]} %>"
+ end
+
+ def rescue_action(e) raise e end
+ end
+
+ include ActionView::Helpers::UrlHelper
+
+ def setup
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ @controller = UrlHelperController.new
+ end
+
+ def test_url_for_shows_only_path
+ get :show_url_for
+ assert_equal '/url_helper_with_controller/show_url_for', @response.body
+ end
+
+ def test_named_route_shows_host_and_path
+ with_url_helper_routing do
+ get :show_named_route, :kind => 'url'
+ assert_equal 'http://test.host/url_helper_with_controller/show_named_route', @response.body
+ end
+ end
+
+ def test_named_route_path_shows_only_path
+ with_url_helper_routing do
+ get :show_named_route, :kind => 'path'
+ assert_equal '/url_helper_with_controller/show_named_route', @response.body
+ end
+ end
+
+ protected
+ def with_url_helper_routing
+ with_routing do |set|
+ set.draw do |map|
+ map.show_named_route 'url_helper_with_controller/show_named_route', :controller => 'url_helper_with_controller', :action => 'show_named_route'
+ end
+ yield
+ end
+ end
+end

0 comments on commit 1d7196b

Please sign in to comment.