From fa619b051b5e12c6b1e8b91a32d6738edafcc3af Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 12 Jan 2007 07:02:38 +0000 Subject: 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 --- actionpack/test/template/url_helper_test.rb | 69 +++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) (limited to 'actionpack/test/template') 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 "Listing", link_to_unless_current("Listing", :action => "list", :controller => "weblog") + assert_equal "Listing", + link_to_unless_current("Listing", :action => "list", :controller => "weblog") + assert_equal "Listing", + link_to_unless_current("Listing", "http://www.example.com/weblog/list") end - + def test_mail_to assert_dom_equal "david@loudthinking.com", mail_to("david@loudthinking.com") assert_dom_equal "David Heinemeier Hansson", 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 "tasks\n" + + "tasks", + @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 -- cgit v1.2.3