diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-01-12 07:02:38 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-01-12 07:02:38 +0000 |
commit | fa619b051b5e12c6b1e8b91a32d6738edafcc3af (patch) | |
tree | 65c2f7f06dfd0af184d212367f6d6d9f69191d91 /actionpack/test/template | |
parent | fe736a54f914b7cf406988f42df6c5c129d821a5 (diff) | |
download | rails-fa619b051b5e12c6b1e8b91a32d6738edafcc3af.tar.gz rails-fa619b051b5e12c6b1e8b91a32d6738edafcc3af.tar.bz2 rails-fa619b051b5e12c6b1e8b91a32d6738edafcc3af.zip |
link_to_unless_current works with full URLs as well as paths. Closes #6891.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5896 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/template')
-rw-r--r-- | actionpack/test/template/url_helper_test.rb | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index a2cae00489..4a772d5069 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../lib/action_view/helpers/url_helper' require File.dirname(__FILE__) + '/../../lib/action_view/helpers/asset_tag_helper' require File.dirname(__FILE__) + '/../../lib/action_view/helpers/tag_helper' -RequestMock = Struct.new("Request", :request_uri) +RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port) class UrlHelperTest < Test::Unit::TestCase include ActionView::Helpers::AssetTagHelper @@ -202,12 +202,16 @@ class UrlHelperTest < Test::Unit::TestCase @controller.request = RequestMock.new("http://www.example.com/weblog/show") @controller.url = "http://www.example.com/weblog/show" assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" }) + assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show") @controller.request = RequestMock.new("http://www.example.com/weblog/show") @controller.url = "http://www.example.com/weblog/list" - assert_equal "<a href=\"http://www.example.com/weblog/list\">Listing</a>", link_to_unless_current("Listing", :action => "list", :controller => "weblog") + assert_equal "<a href=\"http://www.example.com/weblog/list\">Listing</a>", + link_to_unless_current("Listing", :action => "list", :controller => "weblog") + assert_equal "<a href=\"http://www.example.com/weblog/list\">Listing</a>", + link_to_unless_current("Listing", "http://www.example.com/weblog/list") end - + def test_mail_to assert_dom_equal "<a href=\"mailto:david@loudthinking.com\">david@loudthinking.com</a>", mail_to("david@loudthinking.com") assert_dom_equal "<a href=\"mailto:david@loudthinking.com\">David Heinemeier Hansson</a>", mail_to("david@loudthinking.com", "David Heinemeier Hansson") @@ -301,3 +305,62 @@ class UrlHelperWithControllerTest < Test::Unit::TestCase end end end + +class LinkToUnlessCurrentWithControllerTest < Test::Unit::TestCase + class TasksController < ActionController::Base + self.template_root = "#{File.dirname(__FILE__)}/../fixtures/" + + def self.controller_path; 'tasks' end + + def index + render_default + end + + def show + render_default + end + + def rescue_action(e) raise e end + + protected + def render_default + render :inline => + "<%= link_to_unless_current(\"tasks\", tasks_path) %>\n" + + "<%= link_to_unless_current(\"tasks\", tasks_url) %>" + end + end + + include ActionView::Helpers::UrlHelper + + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @controller = TasksController.new + end + + def test_link_to_unless_current_to_current + with_restful_routing do + get :index + assert_equal "tasks\ntasks", @response.body + end + end + + def test_link_to_unless_current_shows_link + with_restful_routing do + get :show, :id => 1 + assert_equal "<a href=\"/tasks\">tasks</a>\n" + + "<a href=\"#{@request.protocol}#{@request.host_with_port}/tasks\">tasks</a>", + @response.body + end + end + + protected + def with_restful_routing + with_routing do |set| + set.draw do |map| + map.resources :tasks + end + yield + end + end +end |