diff options
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/template/url_helper_test.rb | 57 |
1 files changed, 56 insertions, 1 deletions
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&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 |