aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-10-20 18:00:20 +0000
committerRick Olson <technoweenie@gmail.com>2006-10-20 18:00:20 +0000
commit1d7196b55272d5f900a3080387319686e395b981 (patch)
tree3bb2d99d754ba3b9fbe9d984432c157dc37526f5 /actionpack
parent351a224d90d5d485cb30743f1266ec2624ae7853 (diff)
downloadrails-1d7196b55272d5f900a3080387319686e395b981.tar.gz
rails-1d7196b55272d5f900a3080387319686e395b981.tar.bz2
rails-1d7196b55272d5f900a3080387319686e395b981.zip
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
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG6
-rw-r--r--actionpack/lib/action_controller/routing.rb2
-rw-r--r--actionpack/test/template/url_helper_test.rb57
3 files changed, 63 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 655f91d1bb..8ed01f39e9 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -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]
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index 2f24bf4c34..35eec734d3 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/actionpack/lib/action_controller/routing.rb
@@ -1039,7 +1039,7 @@ module ActionController
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
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index ba813f72ce..a3fd8c0d1b 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -28,7 +28,7 @@ class UrlHelperTest < Test::Unit::TestCase
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 @@ class UrlHelperTest < Test::Unit::TestCase
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