Skip to content
This repository
Browse code

Deprecated redirect_to_path and redirect_to_url in favor of letting r…

…edirect_to do the right thing when passed either a path or url. Introduced r as a unified method for render (still under construction)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1349 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 0367317dd62ecd177d57d469a4d57974b75e425b 1 parent dab360e
David Heinemeier Hansson authored May 22, 2005
2  actionpack/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Deprecated redirect_to_path and redirect_to_url in favor of letting redirect_to do the right thing when passed either a path or url.
  4
+
3 5
 * Fixed use of an integer as return code for renders, so render_text "hello world", 404 now works #1327
4 6
 
5 7
 * Fixed assert_redirect_to to work with redirect_to_path #869 [Nicholas Seckar]
103  actionpack/lib/action_controller/base.rb
@@ -439,6 +439,52 @@ def action_name
439 439
       end
440 440
 
441 441
     protected
  442
+      # A unified replacement for the individual renders (work-in-progress).
  443
+      def r(options = {}, &block)
  444
+        raise DoubleRenderError, "Can only render or redirect once per action" if performed?
  445
+        add_variables_to_assigns
  446
+        options[:status] = (options[:status] || DEFAULT_RENDER_STATUS_CODE).to_s
  447
+
  448
+        if options[:text]
  449
+          @response.headers["Status"] = options[:status]
  450
+          @response.body = block_given? ? block : options[:text]
  451
+          @performed_render = true
  452
+          return options[:text]
  453
+
  454
+        elsif options[:file]
  455
+          assert_existance_of_template_file(options[:file]) if options[:use_full_path]
  456
+          logger.info("Rendering #{options[:file]} (#{options[:status]})") unless logger.nil?
  457
+          r(options.merge({ :text => @template.render_file(options[:file], options[:use_full_path])}))
  458
+
  459
+        elsif options[:template]
  460
+          r(options.merge({ :file => options[:template], :use_full_path => true }))
  461
+
  462
+        elsif options[:inline]
  463
+          r(options.merge({ :text => @template.render_template(options[:type] || :rhtml, options[:inline]) }))
  464
+
  465
+        elsif options[:action]
  466
+          r(options.merge({ :template => default_template_name(options[:action]) }))
  467
+
  468
+        elsif options[:partial] && options[:collection]
  469
+          r(options.merge({ 
  470
+            :text => (
  471
+              @template.render_partial_collection(
  472
+                options[:partial], options[:collection], options[:spacer_template], options[:local_assigns]
  473
+              ) || ''
  474
+            )
  475
+          }))
  476
+
  477
+        elsif options[:partial]
  478
+          r(options.merge({ :text => @template.render_partial(options[:partial], options[:object], options[:local_assigns]) }))
  479
+          
  480
+        elsif options[:nothing]
  481
+          r(options.merge({ :text => "" }))
  482
+
  483
+        else
  484
+          r(options.merge({ :template => default_template_name }))
  485
+        end
  486
+      end
  487
+    
442 488
       # Renders the template specified by <tt>template_name</tt>, which defaults to the name of the current controller and action.
443 489
       # So calling +render+ in WeblogController#show will attempt to render "#{template_root}/weblog/show.rhtml" or 
444 490
       # "#{template_root}/weblog/show.rxml" (in that order). The template_root is set on the ActionController::Base class and is 
@@ -480,7 +526,7 @@ def render_template(template, status = nil, type = "rhtml") #:doc:
480 526
       def render_text(text = nil, status = nil, &block) #:doc:
481 527
         raise DoubleRenderError, "Can only render or redirect once per action" if performed?
482 528
         add_variables_to_assigns
483  
-        @response.headers["Status"] = status.to_s || DEFAULT_RENDER_STATUS_CODE
  529
+        @response.headers["Status"] = (status || DEFAULT_RENDER_STATUS_CODE).to_s
484 530
         @response.body = block_given? ? block : text
485 531
         @performed_render = true
486 532
       end
@@ -645,32 +691,51 @@ def rewrite_options(options)
645 691
       def default_url_options(options) #:doc:
646 692
       end
647 693
       
648  
-      # Redirects the browser to an URL that has been rewritten according to the hash of +options+ using a "302 Moved" HTTP header.
649  
-      # See url_for for a description of the valid options.
  694
+      # Redirects the browser to the target specified in +options+. This parameter can take one of three forms:
  695
+      #
  696
+      # * <tt>Hash</tt>: The URL will be generated by calling url_for with the +options+.
  697
+      # * <tt>String starting with protocol:// (like http://)</tt>: Is passed straight through as the target for redirection.
  698
+      # * <tt>String not containing a protocol</tt>: The current current protocol and host is prepended to the string.
  699
+      # 
  700
+      # Examples:
  701
+      #   redirect_to :action => "show", :id => 5
  702
+      #   redirect_to "http://www.rubyonrails.org"
  703
+      #   redirect_to "/images/screenshot.jpg"
  704
+      #
  705
+      # The redirection happens as a "302 Moved" header.
650 706
       def redirect_to(options = {}, *parameters_for_method_reference) #:doc:
651  
-        if parameters_for_method_reference.empty?
652  
-          @response.redirected_to = options
653  
-          redirect_to_url(url_for(options))
654  
-        else
655  
-          @response.redirected_to, @response.redirected_to_method_params = options, parameters_for_method_reference
656  
-          redirect_to_url(url_for(options, *parameters_for_method_reference))
  707
+        case options
  708
+          when %r{^\w+://.*}
  709
+            raise DoubleRenderError, "Can only render or redirect once per action" if performed?
  710
+            logger.info("Redirected to #{url}") unless logger.nil?
  711
+            @response.redirect(options)
  712
+            @performed_redirect = true
  713
+
  714
+          when String
  715
+            redirect_to(request.protocol + request.host_with_port + options)
  716
+
  717
+          else
  718
+            if parameters_for_method_reference.empty?
  719
+              response.redirected_to = options
  720
+              redirect_to(url_for(options))
  721
+            else
  722
+              response.redirected_to, response.redirected_to_method_params = options, parameters_for_method_reference
  723
+              redirect_to(url_for(options, *parameters_for_method_reference))
  724
+            end
657 725
         end
658 726
       end
659 727
       
660  
-      # Redirects the browser to the specified <tt>path</tt> within the current host (specified with a leading /). Used to sidestep
661  
-      # the URL rewriting and go directly to a known path. Example: <tt>redirect_to_path "/images/screenshot.jpg"</tt>.
  728
+      # Deprecated in favor of calling redirect_to directly with the path.
662 729
       def redirect_to_path(path) #:doc:
663  
-        redirect_to_url(@request.protocol + @request.host_with_port + path)
  730
+        redirect_to(path)
664 731
       end
665 732
 
666  
-      # Redirects the browser to the specified <tt>url</tt>. Used to redirect outside of the current application. Example:
667  
-      # <tt>redirect_to_url "http://www.rubyonrails.org"</tt>. If the resource has moved permanently, it's possible to pass true as the
668  
-      # second parameter and the browser will get "301 Moved Permanently" instead of "302 Found".
  733
+      # Deprecated in favor of calling redirect_to directly with the url. If the resource has moved permanently, it's possible to pass
  734
+      # true as the second parameter and the browser will get "301 Moved Permanently" instead of "302 Found". This can also be done through
  735
+      # just setting the headers["Status"] to "301 Moved Permanently" before using the redirect_to.
669 736
       def redirect_to_url(url, permanently = false) #:doc:
670  
-        raise DoubleRenderError, "Can only render or redirect once per action" if performed?
671  
-        logger.info("Redirected to #{url}") unless logger.nil?
672  
-        @response.redirect(url, permanently)
673  
-        @performed_redirect = true
  737
+        headers["Status"] = "301 Moved Permanently" if permanently
  738
+        redirect_to(url)
674 739
       end
675 740
 
676 741
       # Resets the session by clearing out all the objects stored within and initializing a new session object.
34  actionpack/lib/action_controller/layout.rb
@@ -5,6 +5,10 @@ def self.append_features(base)
5 5
       base.class_eval do
6 6
         alias_method :render_without_layout, :render
7 7
         alias_method :render, :render_with_layout
  8
+
  9
+        alias_method :r_without_layout, :r
  10
+        alias_method :r, :r_with_layout
  11
+
8 12
         class << self
9 13
           alias_method :inherited_without_layout, :inherited
10 14
         end
@@ -212,8 +216,33 @@ def render_with_layout(template_name = default_template_name, status = nil, layo
212 216
       end
213 217
     end
214 218
 
  219
+    def r_with_layout(options = {})
  220
+      if (layout = active_layout_for_r(options)) && options[:text]
  221
+        add_variables_to_assigns
  222
+        logger.info("Rendering #{template_name} within #{layout}") unless logger.nil?
  223
+
  224
+        @content_for_layout = r_without_layout(options)
  225
+        add_variables_to_assigns
  226
+
  227
+        erase_render_results
  228
+        r_without_layout(options.merge({ :text => @template.render_file(layout, true)}))
  229
+      else
  230
+        r_without_layout(options)
  231
+      end
  232
+    end
  233
+
215 234
     private
216  
-      
  235
+      def active_layout_for_r(options = {})
  236
+        case options[:layout]
  237
+          when FalseClass
  238
+            nil
  239
+          when NilClass
  240
+            active_layout if action_has_layout?
  241
+          else
  242
+            active_layout(options[:layout])
  243
+        end
  244
+      end
  245
+    
217 246
       def action_has_layout?
218 247
         conditions = self.class.layout_conditions
219 248
         case
@@ -225,6 +254,5 @@ def action_has_layout?
225 254
             true
226 255
         end
227 256
       end
228  
-
229 257
   end
230  
-end
  258
+end
37  actionpack/lib/action_controller/request.rb
... ...
@@ -1,6 +1,8 @@
1 1
 module ActionController
2 2
   # These methods are available in both the production and test Request objects.
3 3
   class AbstractRequest
  4
+    cattr_accessor :relative_url_root
  5
+    
4 6
     # Returns both GET and POST parameters in a single hash.
5 7
     def parameters
6 8
       @parameters ||= request_parameters.merge(query_parameters).merge(path_parameters).with_indifferent_access
@@ -57,6 +59,16 @@ def xml_post?
57 59
     def yaml_post?
58 60
       post_format == :yaml && post?
59 61
     end
  62
+
  63
+
  64
+    # Returns true if the request's "X-Requested-With" header contains
  65
+    # "XMLHttpRequest". (The Prototype Javascript library sends this header with
  66
+    # every Ajax request.)
  67
+    def xml_http_request?
  68
+      env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
  69
+    end
  70
+    alias xhr? :xml_http_request?
  71
+
60 72
     
61 73
     
62 74
     # Determine originating IP address.  REMOTE_ADDR is the standard
@@ -120,20 +132,15 @@ def ssl?
120 132
       protocol == 'https://'
121 133
     end
122 134
   
123  
-    # returns the interpreted path to requested resource after
124  
-    # all the installation directory of this application was taken into account
  135
+    # Returns the interpreted path to requested resource after all the installation directory of this application was taken into account
125 136
     def path
126  
-      uri = request_uri
127  
-      path = uri ? uri.split('?').first : ''
128  
-
129  
-      # cut off the part of the url which leads to the installation directory of this app
130  
-      path[relative_url_root.length..-1]
  137
+      path = (uri = request_uri) ? uri.split('?').first : ''
  138
+      path[relative_url_root.length..-1] # cut off the part of the url which leads to the installation directory of this app
131 139
     end    
132 140
     
133  
-    # returns the path minus the web server relative 
134  
-    # installation directory
135  
-    def relative_url_root
136  
-      @@relative_url_root ||= File.dirname(env["SCRIPT_NAME"].to_s).gsub /(^\.$|^\/$)/, ''
  141
+    # Returns the path minus the web server relative installation directory
  142
+    def relative_url_root(force_reload = false)
  143
+      @@relative_url_root ||= File.dirname(env["SCRIPT_NAME"].to_s).gsub(/(^\.$|^\/$)/, '')
137 144
     end
138 145
 
139 146
     def port
@@ -158,14 +165,6 @@ def path_parameters
158 165
       @path_parameters ||= {}
159 166
     end
160 167
     
161  
-    # Returns true if the request's "X-Requested-With" header contains
162  
-    # "XMLHttpRequest". (The Prototype Javascript library sends this header with
163  
-    # every Ajax request.)
164  
-    def xml_http_request?
165  
-      env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
166  
-    end
167  
-    alias xhr? :xml_http_request?
168  
-    
169 168
     #--
170 169
     # Must be implemented in the concrete request
171 170
     #++
2  actionpack/lib/action_controller/response.rb
@@ -8,7 +8,7 @@ def initialize
8 8
     end
9 9
 
10 10
     def redirect(to_url, permanently = false)
11  
-      @headers["Status"]   = permanently ? "301 Moved Permanently" : "302 Found"
  11
+      @headers["Status"]   ||= "302 Found"
12 12
       @headers["location"] = to_url
13 13
 
14 14
       @body = "<html><body>You are being <a href=\"#{to_url}\">redirected</a>.</body></html>"
4  actionpack/test/controller/action_pack_assertions_test.rb
@@ -13,7 +13,7 @@ def hello_world() render "test/hello_world"; end
13 13
   def hello_xml_world() render "test/hello_xml_world"; end
14 14
  
15 15
   # a redirect to an internal location
16  
-  def redirect_internal() redirect_to "nothing"; end
  16
+  def redirect_internal() redirect_to "/nothing"; end
17 17
 
18 18
   def redirect_to_action() redirect_to :action => "flash_me", :id => 1, :params => { "panda" => "fun" }; end
19 19
 
@@ -270,7 +270,7 @@ def test_rendered_action
270 270
   # check the redirection location
271 271
   def test_redirection_location
272 272
     process :redirect_internal
273  
-    assert_equal 'nothing', @response.redirect_url
  273
+    assert_equal 'http://test.host/nothing', @response.redirect_url
274 274
 
275 275
     process :redirect_external
276 276
     assert_equal 'http://www.rubyonrails.org', @response.redirect_url
237  actionpack/test/controller/new_render_test.rb
... ...
@@ -0,0 +1,237 @@
  1
+require File.dirname(__FILE__) + '/../abstract_unit'
  2
+
  3
+Customer = Struct.new("Customer", :name)
  4
+
  5
+module Fun
  6
+  class GamesController < ActionController::Base
  7
+    def hello_world
  8
+    end
  9
+  end
  10
+end
  11
+
  12
+
  13
+class TestController < ActionController::Base
  14
+  layout :determine_layout
  15
+
  16
+  def hello_world
  17
+  end
  18
+
  19
+  def render_hello_world
  20
+    r :template => "test/hello_world"
  21
+  end
  22
+
  23
+  def render_hello_world_from_variable
  24
+    @person = "david"
  25
+    r :text => "hello #{@person}"
  26
+  end
  27
+
  28
+  def render_action_hello_world
  29
+    r :action => "hello_world"
  30
+  end
  31
+  
  32
+  def render_text_hello_world
  33
+    r :text => "hello world"
  34
+  end
  35
+
  36
+  def render_custom_code
  37
+    r :text => "hello world", :status => "404 Moved"
  38
+  end
  39
+  
  40
+  def render_xml_hello
  41
+    @name = "David"
  42
+    r :template => "test/hello"
  43
+  end
  44
+
  45
+  def greeting
  46
+    # let's just rely on the template
  47
+  end
  48
+
  49
+  def layout_test
  50
+    r :action => "hello_world"
  51
+  end
  52
+
  53
+  def layout_test_with_different_layout
  54
+    r :action => "hello_world", :layout => "standard"
  55
+  end
  56
+  
  57
+  def rendering_without_layout
  58
+    r :action => "hello_world", :layout => false
  59
+  end
  60
+  
  61
+  def builder_layout_test
  62
+    r :action => "hello"
  63
+  end
  64
+
  65
+  def partials_list
  66
+    @customers = [ Customer.new("david"), Customer.new("mary") ]
  67
+    r :action => "list"
  68
+  end
  69
+
  70
+  def partial_only
  71
+    render_partial
  72
+  end
  73
+
  74
+  def hello_in_a_string
  75
+    @customers = [ Customer.new("david"), Customer.new("mary") ]
  76
+    r :text =>  "How's there? #{render_to_string("test/list")}"
  77
+  end
  78
+  
  79
+  def accessing_params_in_template
  80
+    r :inline =>  "Hello: <%= params[:name] %>"
  81
+  end
  82
+
  83
+  def rescue_action(e) raise end
  84
+    
  85
+  private
  86
+    def determine_layout
  87
+      case action_name 
  88
+        when "layout_test", "rendering_without_layout"
  89
+          "layouts/standard"
  90
+        when "builder_layout_test"
  91
+          "layouts/builder"
  92
+      end
  93
+    end
  94
+end
  95
+
  96
+TestController.template_root = File.dirname(__FILE__) + "/../fixtures/"
  97
+Fun::GamesController.template_root = File.dirname(__FILE__) + "/../fixtures/"
  98
+
  99
+class TestLayoutController < ActionController::Base
  100
+  layout "layouts/standard"
  101
+  
  102
+  def hello_world
  103
+  end
  104
+  
  105
+  def hello_world_outside_layout
  106
+  end
  107
+
  108
+  def rescue_action(e)
  109
+    raise unless ActionController::MissingTemplate === e
  110
+  end
  111
+end
  112
+
  113
+class RenderTest < Test::Unit::TestCase
  114
+  def setup
  115
+    @request    = ActionController::TestRequest.new
  116
+    @response   = ActionController::TestResponse.new
  117
+
  118
+    @request.host = "www.nextangle.com"
  119
+  end
  120
+
  121
+  def test_simple_show
  122
+    @request.action = "hello_world"
  123
+    response = process_request
  124
+    assert_equal "200 OK", response.headers["Status"]
  125
+    assert_equal "test/hello_world", response.template.first_render
  126
+  end
  127
+
  128
+  def test_do_with_render
  129
+    @request.action = "render_hello_world"
  130
+    assert_equal "test/hello_world", process_request.template.first_render
  131
+  end
  132
+
  133
+  def test_do_with_render_from_variable
  134
+    @request.action = "render_hello_world_from_variable"
  135
+    assert_equal "hello david", process_request.body
  136
+  end
  137
+
  138
+  def test_do_with_render_action
  139
+    @request.action = "render_action_hello_world"
  140
+    assert_equal "test/hello_world", process_request.template.first_render
  141
+  end
  142
+
  143
+  def test_do_with_render_text
  144
+    @request.action = "render_text_hello_world"
  145
+    assert_equal "hello world", process_request.body
  146
+  end
  147
+
  148
+  def test_do_with_render_custom_code
  149
+    @request.action = "render_custom_code"
  150
+    assert_equal "404 Moved", process_request.headers["Status"]
  151
+  end
  152
+
  153
+  def test_attempt_to_access_object_method
  154
+    @request.action = "clone"
  155
+    assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { process_request }
  156
+  end
  157
+
  158
+  def test_private_methods
  159
+    @request.action = "determine_layout"
  160
+    assert_raises(ActionController::UnknownAction, "No action responded to [determine_layout]") { process_request }
  161
+  end
  162
+
  163
+  def test_access_to_request_in_view
  164
+    ActionController::Base.view_controller_internals = false
  165
+
  166
+    @request.action = "hello_world"
  167
+    response = process_request
  168
+    assert_nil response.template.assigns["request"]
  169
+
  170
+    ActionController::Base.view_controller_internals = true
  171
+
  172
+    @request.action = "hello_world"
  173
+    response = process_request
  174
+    assert_kind_of ActionController::AbstractRequest, response.template.assigns["request"]
  175
+  end
  176
+  
  177
+  def test_render_xml
  178
+    @request.action = "render_xml_hello"
  179
+    assert_equal "<html>\n  <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", process_request.body
  180
+  end
  181
+
  182
+  def test_render_xml_with_default
  183
+    @request.action = "greeting"
  184
+    assert_equal "<p>This is grand!</p>\n", process_request.body
  185
+  end
  186
+
  187
+  def test_layout_rendering
  188
+    @request.action = "layout_test"
  189
+    assert_equal "<html>Hello world!</html>", process_request.body
  190
+  end
  191
+
  192
+  def test_layout_test_with_different_layout
  193
+    @request.action = "layout_test_with_different_layout"
  194
+    assert_equal "<html>Hello world!</html>", process_request.body
  195
+  end
  196
+
  197
+  def test_rendering_without_layout
  198
+    @request.action = "rendering_without_layout"
  199
+    assert_equal "Hello world!", process_request.body
  200
+  end
  201
+
  202
+  def test_render_xml_with_layouts
  203
+    @request.action = "builder_layout_test"
  204
+    assert_equal "<wrapper>\n<html>\n  <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", process_request.body
  205
+  end
  206
+
  207
+  def test_partials_list
  208
+    @request.action = "partials_list"
  209
+    assert_equal "Hello: davidHello: mary", process_request.body
  210
+  end
  211
+
  212
+  def test_partial_only
  213
+    @request.action = "partial_only"
  214
+    assert_equal "only partial", process_request.body
  215
+  end
  216
+
  217
+  def test_render_to_string
  218
+    @request.action = "hello_in_a_string"
  219
+    assert_equal "How's there? Hello: davidHello: mary", process_request.body
  220
+  end
  221
+
  222
+  def test_nested_rendering
  223
+    @request.action = "hello_world"
  224
+    assert_equal "Living in a nested world", Fun::GamesController.process(@request, @response).body
  225
+  end
  226
+
  227
+  def test_accessing_params_in_template
  228
+    @request.action = "accessing_params_in_template"
  229
+    @request.query_parameters[:name] = "David"
  230
+    assert_equal "Hello: David", process_request.body
  231
+  end
  232
+
  233
+  private
  234
+    def process_request
  235
+      TestController.process(@request, @response)
  236
+    end
  237
+end
22  actionpack/test/controller/request_test.rb
@@ -65,7 +65,7 @@ def test_port_string
65 65
     assert_equal ":8080", @request.port_string
66 66
   end
67 67
   
68  
-    def test_relative_url_root
  68
+  def test_relative_url_root
69 69
     @request.env['SCRIPT_NAME'] = nil
70 70
     assert_equal "", @request.relative_url_root
71 71
 
@@ -75,92 +75,108 @@ def test_relative_url_root
75 75
     @request.env['SCRIPT_NAME'] = "/myapp.rb"
76 76
     assert_equal "", @request.relative_url_root
77 77
 
  78
+    @request.relative_url_root = nil
78 79
     @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
79 80
     assert_equal "/hieraki", @request.relative_url_root
80 81
 
  82
+    @request.relative_url_root = nil
81 83
     @request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi"
82 84
     assert_equal "/collaboration/hieraki", @request.relative_url_root    
83 85
   end
84 86
   
85 87
   def test_request_uri
  88
+    @request.relative_url_root = nil
86 89
     @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri?mapped=1"
87 90
     assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
88 91
     assert_equal "/path/of/some/uri", @request.path
89 92
     
  93
+    @request.relative_url_root = nil
90 94
     @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri"
91 95
     assert_equal "/path/of/some/uri", @request.request_uri
92 96
     assert_equal "/path/of/some/uri", @request.path
93 97
 
  98
+    @request.relative_url_root = nil
94 99
     @request.set_REQUEST_URI "/path/of/some/uri"
95 100
     assert_equal "/path/of/some/uri", @request.request_uri
96 101
     assert_equal "/path/of/some/uri", @request.path
97 102
 
  103
+    @request.relative_url_root = nil
98 104
     @request.set_REQUEST_URI "/"
99 105
     assert_equal "/", @request.request_uri
100 106
     assert_equal "/", @request.path
101 107
 
  108
+    @request.relative_url_root = nil
102 109
     @request.set_REQUEST_URI "/?m=b"
103 110
     assert_equal "/?m=b", @request.request_uri
104 111
     assert_equal "/", @request.path
105 112
     
  113
+    @request.relative_url_root = nil
106 114
     @request.set_REQUEST_URI "/"
107 115
     @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
108 116
     assert_equal "/", @request.request_uri
109 117
     assert_equal "/", @request.path    
110 118
 
  119
+    @request.relative_url_root = nil
111 120
     @request.set_REQUEST_URI "/hieraki/"
112 121
     @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
113 122
     assert_equal "/hieraki/", @request.request_uri
114 123
     assert_equal "/", @request.path    
115 124
 
  125
+    @request.relative_url_root = nil
116 126
     @request.set_REQUEST_URI "/collaboration/hieraki/books/edit/2"
117 127
     @request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi"
118 128
     assert_equal "/collaboration/hieraki/books/edit/2", @request.request_uri
119 129
     assert_equal "/books/edit/2", @request.path
120 130
   
121 131
     # The following tests are for when REQUEST_URI is not supplied (as in IIS)
  132
+    @request.relative_url_root = nil
122 133
     @request.set_REQUEST_URI nil
123 134
     @request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
124 135
     @request.env['SCRIPT_NAME'] = nil #"/path/dispatch.rb"
125 136
     assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
126 137
     assert_equal "/path/of/some/uri", @request.path
127 138
 
  139
+    @request.relative_url_root = nil
128 140
     @request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
129 141
     @request.env['SCRIPT_NAME'] = "/path/dispatch.rb"
130 142
     assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
131 143
     assert_equal "/of/some/uri", @request.path
132 144
 
  145
+    @request.relative_url_root = nil
133 146
     @request.env['PATH_INFO'] = "/path/of/some/uri"
134 147
     @request.env['SCRIPT_NAME'] = nil
135 148
     assert_equal "/path/of/some/uri", @request.request_uri
136 149
     assert_equal "/path/of/some/uri", @request.path
137 150
 
  151
+    @request.relative_url_root = nil
138 152
     @request.env['PATH_INFO'] = "/"
139 153
     assert_equal "/", @request.request_uri
140 154
     assert_equal "/", @request.path
141 155
 
  156
+    @request.relative_url_root = nil
142 157
     @request.env['PATH_INFO'] = "/?m=b"
143 158
     assert_equal "/?m=b", @request.request_uri
144 159
     assert_equal "/", @request.path
145 160
     
  161
+    @request.relative_url_root = nil
146 162
     @request.env['PATH_INFO'] = "/"
147 163
     @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
148 164
     assert_equal "/", @request.request_uri
149 165
     assert_equal "/", @request.path    
150 166
 
  167
+    @request.relative_url_root = nil
151 168
     @request.env['PATH_INFO'] = "/hieraki/"
152 169
     @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
153 170
     assert_equal "/hieraki/", @request.request_uri
154 171
     assert_equal "/", @request.path    
155 172
 
156 173
     # This test ensures that Rails uses REQUEST_URI over PATH_INFO
  174
+    @request.relative_url_root = nil
157 175
     @request.env['REQUEST_URI'] = "/some/path"
158 176
     @request.env['PATH_INFO'] = "/another/path"
159 177
     @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
160 178
     assert_equal "/some/path", @request.request_uri
161 179
     assert_equal "/some/path", @request.path
162  
-
163  
-
164 180
   end
165 181
   
166 182
 
5  actionpack/test/template/form_options_helper_test.rb
... ...
@@ -1,5 +1,4 @@
1  
-require 'test/unit'
2  
-require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_options_helper'
  1
+require File.dirname(__FILE__) + '/../abstract_unit'
3 2
 
4 3
 class MockTimeZone
5 4
   attr_reader :name
@@ -260,7 +259,7 @@ def test_country_select
260 259
     assert_equal(
261 260
       "<select id=\"post_origin\" name=\"post[origin]\"><option value=\"Afghanistan\">Afghanistan</option>\n<option value=\"Albania\">Albania</option>\n<option value=\"Algeria\">Algeria</option>\n<option value=\"American Samoa\">American Samoa</option>\n<option value=\"Andorra\">Andorra</option>\n<option value=\"Angola\">Angola</option>\n<option value=\"Anguilla\">Anguilla</option>\n<option value=\"Antarctica\">Antarctica</option>\n<option value=\"Antigua And Barbuda\">Antigua And Barbuda</option>\n<option value=\"Argentina\">Argentina</option>\n<option value=\"Armenia\">Armenia</option>\n<option value=\"Aruba\">Aruba</option>\n<option value=\"Australia\">Australia</option>\n<option value=\"Austria\">Austria</option>\n<option value=\"Azerbaijan\">Azerbaijan</option>\n<option value=\"Bahamas\">Bahamas</option>\n<option value=\"Bahrain\">Bahrain</option>\n<option value=\"Bangladesh\">Bangladesh</option>\n<option value=\"Barbados\">Barbados</option>\n<option value=\"Belarus\">Belarus</option>\n<option value=\"Belgium\">Belgium</option>\n<option value=\"Belize\">Belize</option>\n<option value=\"Benin\">Benin</option>\n<option value=\"Bermuda\">Bermuda</option>\n<option value=\"Bhutan\">Bhutan</option>\n<option value=\"Bolivia\">Bolivia</option>\n<option value=\"Bosnia and Herzegowina\">Bosnia and Herzegowina</option>\n<option value=\"Botswana\">Botswana</option>\n<option value=\"Bouvet Island\">Bouvet Island</option>\n<option value=\"Brazil\">Brazil</option>\n<option value=\"British Indian Ocean Territory\">British Indian Ocean Territory</option>\n<option value=\"Brunei Darussalam\">Brunei Darussalam</option>\n<option value=\"Bulgaria\">Bulgaria</option>\n<option value=\"Burkina Faso\">Burkina Faso</option>\n<option value=\"Burma\">Burma</option>\n<option value=\"Burundi\">Burundi</option>\n<option value=\"Cambodia\">Cambodia</option>\n<option value=\"Cameroon\">Cameroon</option>\n<option value=\"Canada\">Canada</option>\n<option value=\"Cape Verde\">Cape Verde</option>\n<option value=\"Cayman Islands\">Cayman Islands</option>\n<option value=\"Central African Republic\">Central African Republic</option>\n<option value=\"Chad\">Chad</option>\n<option value=\"Chile\">Chile</option>\n<option value=\"China\">China</option>\n<option value=\"Christmas Island\">Christmas Island</option>\n<option value=\"Cocos (Keeling) Islands\">Cocos (Keeling) Islands</option>\n<option value=\"Colombia\">Colombia</option>\n<option value=\"Comoros\">Comoros</option>\n<option value=\"Congo\">Congo</option>\n<option value=\"Congo, the Democratic Republic of the\">Congo, the Democratic Republic of the</option>\n<option value=\"Cook Islands\">Cook Islands</option>\n<option value=\"Costa Rica\">Costa Rica</option>\n<option value=\"Cote d'Ivoire\">Cote d'Ivoire</option>\n<option value=\"Croatia\">Croatia</option>\n<option value=\"Cyprus\">Cyprus</option>\n<option value=\"Czech Republic\">Czech Republic</option>\n<option value=\"Denmark\" selected=\"selected\">Denmark</option>\n<option value=\"Djibouti\">Djibouti</option>\n<option value=\"Dominica\">Dominica</option>\n<option value=\"Dominican Republic\">Dominican Republic</option>\n<option value=\"East Timor\">East Timor</option>\n<option value=\"Ecuador\">Ecuador</option>\n<option value=\"Egypt\">Egypt</option>\n<option value=\"El Salvador\">El Salvador</option>\n<option value=\"England\">England" +
262 261
       "</option>\n<option value=\"Equatorial Guinea\">Equatorial Guinea</option>\n<option value=\"Eritrea\">Eritrea</option>\n<option value=\"Espana\">Espana</option>\n<option value=\"Estonia\">Estonia</option>\n<option value=\"Ethiopia\">Ethiopia</option>\n<option value=\"Falkland Islands\">Falkland Islands</option>\n<option value=\"Faroe Islands\">Faroe Islands</option>\n<option value=\"Fiji\">Fiji</option>\n<option value=\"Finland\">Finland</option>\n<option value=\"France\">France</option>\n<option value=\"French Guiana\">French Guiana</option>\n<option value=\"French Polynesia\">French Polynesia</option>\n<option value=\"French Southern Territories\">French Southern Territories</option>\n<option value=\"Gabon\">Gabon</option>\n<option value=\"Gambia\">Gambia</option>\n<option value=\"Georgia\">Georgia</option>\n<option value=\"Germany\">Germany</option>\n<option value=\"Ghana\">Ghana</option>\n<option value=\"Gibraltar\">Gibraltar</option>\n<option value=\"Great Britain\">Great Britain</option>\n<option value=\"Greece\">Greece</option>\n<option value=\"Greenland\">Greenland</option>\n<option value=\"Grenada\">Grenada</option>\n<option value=\"Guadeloupe\">Guadeloupe</option>\n<option value=\"Guam\">Guam</option>\n<option value=\"Guatemala\">Guatemala</option>\n<option value=\"Guinea\">Guinea</option>\n<option value=\"Guinea-Bissau\">Guinea-Bissau</option>\n<option value=\"Guyana\">Guyana</option>\n<option value=\"Haiti\">Haiti</option>\n<option value=\"Heard and Mc Donald Islands\">Heard and Mc Donald Islands</option>\n<option value=\"Honduras\">Honduras</option>\n<option value=\"Hong Kong\">Hong Kong</option>\n<option value=\"Hungary\">Hungary</option>\n<option value=\"Iceland\">Iceland</option>\n<option value=\"India\">India</option>\n<option value=\"Indonesia\">Indonesia</option>\n<option value=\"Ireland\">Ireland</option>\n<option value=\"Israel\">Israel</option>\n<option value=\"Italy\">Italy</option>\n<option value=\"Iran\">Iran</option>\n<option value=\"Irak\">Irak</option>\n<option value=\"Jamaica\">Jamaica</option>\n<option value=\"Japan\">Japan</option>\n<option value=\"Jordan\">Jordan</option>\n<option value=\"Kazakhstan\">Kazakhstan</option>\n<option value=\"Kenya\">Kenya</option>\n<option value=\"Kiribati\">Kiribati</option>\n<option value=\"Korea, Republic of\">Korea, Republic of</option>\n<option value=\"Korea (South)\">Korea (South)</option>\n<option value=\"Kuwait\">Kuwait</option>\n<option value=\"Kyrgyzstan\">Kyrgyzstan</option>\n<option value=\"Lao People's Democratic Republic\">Lao People's Democratic Republic</option>\n<option value=\"Latvia\">Latvia</option>\n<option value=\"Lebanon\">Lebanon</option>\n<option value=\"Lesotho\">Lesotho</option>\n<option value=\"Liberia\">Liberia</option>\n<option value=\"Liechtenstein\">Liechtenstein</option>\n<option value=\"Lithuania\">Lithuania</option>\n<option value=\"Luxembourg\">Luxembourg</option>\n<option value=\"Macau\">Macau</option>\n<option value=\"Macedonia\">Macedonia</option>\n<option value=\"Madagascar\">Madagascar</option>\n<option value=\"Malawi\">Malawi</option>\n<option value=\"Malaysia\">Malaysia</option>\n<option value=\"Maldives\">Maldives</option>\n<option value=\"Mali\">Mali</option>\n<option value=\"Malta\">Malta</option>\n<option value=\"Marshall Islands\">Marshall Islands</option>\n<option value=\"Martinique\">Martinique</option>\n<option value=\"Mauritania\">Mauritania</option>\n<option value=\"Mauritius\">Mauritius</option>\n<option value=\"Mayotte\">Mayotte</option>\n<option value=\"Mexico\">Mexico</option>\n<option value=\"Micronesia, Federated States of\">Micronesia, Federated States of</option>\n<option value=\"Moldova, Republic of\">Moldova, Republic of</option>\n<option value=\"Monaco\">Monaco</option>\n<option value=\"Mongolia\">Mongolia</option>\n<option value=\"Montserrat\">Montserrat</option>\n<option value=\"Morocco\">Morocco</option>\n<option value=\"Mozambique\">Mozambique</option>\n<option value=\"Myanmar\">Myanmar</option>\n<option value=\"Namibia\">Namibia</option>\n<option value=\"Nauru\">Nauru</option>\n<option value=\"Nepal\">Nepal</option>\n<option value=\"Netherlands\">Netherlands</option>\n<option value=\"Netherlands Antilles\">Netherlands Antilles</option>\n<option value=\"New Caledonia\">New Caledonia</option>" +
263  
-      "\n<option value=\"New Zealand\">New Zealand</option>\n<option value=\"Nicaragua\">Nicaragua</option>\n<option value=\"Niger\">Niger</option>\n<option value=\"Nigeria\">Nigeria</option>\n<option value=\"Niue\">Niue</option>\n<option value=\"Norfolk Island\">Norfolk Island</option>\n<option value=\"Northern Ireland\">Northern Ireland</option>\n<option value=\"Northern Mariana Islands\">Northern Mariana Islands</option>\n<option value=\"Norway\">Norway</option>\n<option value=\"Oman\">Oman</option>\n<option value=\"Pakistan\">Pakistan</option>\n<option value=\"Palau\">Palau</option>\n<option value=\"Panama\">Panama</option>\n<option value=\"Papua New Guinea\">Papua New Guinea</option>\n<option value=\"Paraguay\">Paraguay</option>\n<option value=\"Peru\">Peru</option>\n<option value=\"Philippines\">Philippines</option>\n<option value=\"Pitcairn\">Pitcairn</option>\n<option value=\"Poland\">Poland</option>\n<option value=\"Portugal\">Portugal</option>\n<option value=\"Puerto Rico\">Puerto Rico</option>\n<option value=\"Qatar\">Qatar</option>\n<option value=\"Reunion\">Reunion</option>\n<option value=\"Romania\">Romania</option>\n<option value=\"Russia\">Russia</option>\n<option value=\"Rwanda\">Rwanda</option>\n<option value=\"Saint Kitts and Nevis\">Saint Kitts and Nevis</option>\n<option value=\"Saint Lucia\">Saint Lucia</option>\n<option value=\"Saint Vincent and the Grenadines\">Saint Vincent and the Grenadines</option>\n<option value=\"Samoa (Independent)\">Samoa (Independent)</option>\n<option value=\"San Marino\">San Marino</option>\n<option value=\"Sao Tome and Principe\">Sao Tome and Principe</option>\n<option value=\"Saudi Arabia\">Saudi Arabia</option>\n<option value=\"Scotland\">Scotland</option>\n<option value=\"Senegal\">Senegal</option>\n<option value=\"Seychelles\">Seychelles</option>\n<option value=\"Sierra Leone\">Sierra Leone</option>\n<option value=\"Singapore\">Singapore</option>\n<option value=\"Slovakia\">Slovakia</option>\n<option value=\"Slovenia\">Slovenia</option>\n<option value=\"Solomon Islands\">Solomon Islands</option>\n<option value=\"Somalia\">Somalia</option>\n<option value=\"South Africa\">South Africa</option>\n<option value=\"South Georgia and the South Sandwich Islands\">South Georgia and the South Sandwich Islands</option>\n<option value=\"South Korea\">South Korea</option>\n<option value=\"Spain\">Spain</option>\n<option value=\"Sri Lanka\">Sri Lanka</option>\n<option value=\"St. Helena\">St. Helena</option>\n<option value=\"St. Pierre and Miquelon\">St. Pierre and Miquelon</option>\n<option value=\"Suriname\">Suriname</option>\n<option value=\"Svalbard and Jan Mayen Islands\">Svalbard and Jan Mayen Islands</option>\n<option value=\"Swaziland\">Swaziland</option>\n<option value=\"Sweden\">Sweden</option>\n<option value=\"Switzerland\">Switzerland</option>\n<option value=\"Taiwan\">Taiwan</option>\n<option value=\"Tajikistan\">Tajikistan</option>\n<option value=\"Tanzania\">Tanzania</option>\n<option value=\"Thailand\">Thailand</option>\n<option value=\"Togo\">Togo</option>\n<option value=\"Tokelau\">Tokelau</option>\n<option value=\"Tonga\">Tonga</option>\n<option value=\"Trinidad\">Trinidad</option>\n<option value=\"Trinidad and Tobago\">Trinidad and Tobago</option>\n<option value=\"Tunisia\">Tunisia</option>\n<option value=\"Turkey\">Turkey</option>\n<option value=\"Turkmenistan\">" +
  262
+      "\n<option value=\"New Zealand\">New Zealand</option>\n<option value=\"Nicaragua\">Nicaragua</option>\n<option value=\"Niger\">Niger</option>\n<option value=\"Nigeria\">Nigeria</option>\n<option value=\"Niue\">Niue</option>\n<option value=\"Norfolk Island\">Norfolk Island</option>\n<option value=\"Northern Ireland\">Northern Ireland</option>\n<option value=\"Northern Mariana Islands\">Northern Mariana Islands</option>\n<option value=\"Norway\">Norway</option>\n<option value=\"Oman\">Oman</option>\n<option value=\"Pakistan\">Pakistan</option>\n<option value=\"Palau\">Palau</option>\n<option value=\"Panama\">Panama</option>\n<option value=\"Papua New Guinea\">Papua New Guinea</option>\n<option value=\"Paraguay\">Paraguay</option>\n<option value=\"Peru\">Peru</option>\n<option value=\"Philippines\">Philippines</option>\n<option value=\"Pitcairn\">Pitcairn</option>\n<option value=\"Poland\">Poland</option>\n<option value=\"Portugal\">Portugal</option>\n<option value=\"Puerto Rico\">Puerto Rico</option>\n<option value=\"Qatar\">Qatar</option>\n<option value=\"Reunion\">Reunion</option>\n<option value=\"Romania\">Romania</option>\n<option value=\"Russia\">Russia</option>\n<option value=\"Rwanda\">Rwanda</option>\n<option value=\"Saint Kitts and Nevis\">Saint Kitts and Nevis</option>\n<option value=\"Saint Lucia\">Saint Lucia</option>\n<option value=\"Saint Vincent and the Grenadines\">Saint Vincent and the Grenadines</option>\n<option value=\"Samoa (Independent)\">Samoa (Independent)</option>\n<option value=\"San Marino\">San Marino</option>\n<option value=\"Sao Tome and Principe\">Sao Tome and Principe</option>\n<option value=\"Saudi Arabia\">Saudi Arabia</option>\n<option value=\"Scotland\">Scotland</option>\n<option value=\"Senegal\">Senegal</option>\n<option value=\"Serbia and Montenegro\">Serbia and Montenegro</option>\n<option value=\"Seychelles\">Seychelles</option>\n<option value=\"Sierra Leone\">Sierra Leone</option>\n<option value=\"Singapore\">Singapore</option>\n<option value=\"Slovakia\">Slovakia</option>\n<option value=\"Slovenia\">Slovenia</option>\n<option value=\"Solomon Islands\">Solomon Islands</option>\n<option value=\"Somalia\">Somalia</option>\n<option value=\"South Africa\">South Africa</option>\n<option value=\"South Georgia and the South Sandwich Islands\">South Georgia and the South Sandwich Islands</option>\n<option value=\"South Korea\">South Korea</option>\n<option value=\"Spain\">Spain</option>\n<option value=\"Sri Lanka\">Sri Lanka</option>\n<option value=\"St. Helena\">St. Helena</option>\n<option value=\"St. Pierre and Miquelon\">St. Pierre and Miquelon</option>\n<option value=\"Suriname\">Suriname</option>\n<option value=\"Svalbard and Jan Mayen Islands\">Svalbard and Jan Mayen Islands</option>\n<option value=\"Swaziland\">Swaziland</option>\n<option value=\"Sweden\">Sweden</option>\n<option value=\"Switzerland\">Switzerland</option>\n<option value=\"Taiwan\">Taiwan</option>\n<option value=\"Tajikistan\">Tajikistan</option>\n<option value=\"Tanzania\">Tanzania</option>\n<option value=\"Thailand\">Thailand</option>\n<option value=\"Togo\">Togo</option>\n<option value=\"Tokelau\">Tokelau</option>\n<option value=\"Tonga\">Tonga</option>\n<option value=\"Trinidad\">Trinidad</option>\n<option value=\"Trinidad and Tobago\">Trinidad and Tobago</option>\n<option value=\"Tunisia\">Tunisia</option>\n<option value=\"Turkey\">Turkey</option>\n<option value=\"Turkmenistan\">" +
264 263
       "Turkmenistan</option>\n<option value=\"Turks and Caicos Islands\">Turks and Caicos Islands</option>\n<option value=\"Tuvalu\">Tuvalu</option>\n<option value=\"Uganda\">Uganda</option>\n<option value=\"Ukraine\">Ukraine</option>\n<option value=\"United Arab Emirates\">United Arab Emirates</option>\n<option value=\"United Kingdom\">United Kingdom</option>\n<option value=\"United States\">United States</option>\n<option value=\"United States Minor Outlying Islands\">United States Minor Outlying Islands</option>\n<option value=\"Uruguay\">Uruguay</option>\n<option value=\"Uzbekistan\">Uzbekistan</option>\n<option value=\"Vanuatu\">Vanuatu</option>\n<option value=\"Vatican City State (Holy See)\">Vatican City State (Holy See)</option>\n<option value=\"Venezuela\">Venezuela</option>\n<option value=\"Viet Nam\">Viet Nam</option>\n<option value=\"Virgin Islands (British)\">Virgin Islands (British)</option>\n<option value=\"Virgin Islands (U.S.)\">Virgin Islands (U.S.)</option>\n<option value=\"Wales\">Wales</option>\n<option value=\"Wallis and Futuna Islands\">Wallis and Futuna Islands</option>\n<option value=\"Western Sahara\">Western Sahara</option>\n<option value=\"Yemen\">Yemen</option>\n<option value=\"Zambia\">Zambia</option>\n<option value=\"Zimbabwe\">Zimbabwe</option></select>",
265 264
       country_select("post", "origin")
266 265
     )

0 notes on commit 0367317

Please sign in to comment.
Something went wrong with that request. Please try again.