public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Ensure that default_url_options, if defined, are used in named routes.

Signed-off-by: Michael Koziarski <michael@koziarski.com>

[#22 state:resolved]
chuyeow (author)
Sat Apr 19 21:57:36 -0700 2008
NZKoz (committer)
Sat May 03 17:49:44 -0700 2008
commit  6a6b4392c16c665eb713705f2b38e959a658eeef
tree    e5769a86f89bcfb084726be42bad07d365dee5ac
parent  437f918646fd141fd57350f55a8890b18ebfb148
...
532
533
534
535
 
536
537
 
538
539
540
...
532
533
534
 
535
536
 
537
538
539
540
0
@@ -532,9 +532,9 @@ module ActionController #:nodoc:
0
 
0
       # Returns a URL that has been rewritten according to the options hash and the defined Routes.
0
       # (For doing a complete redirect, use redirect_to).
0
-      #  
0
+      #
0
       # <tt>url_for</tt> is used to:
0
-      #  
0
+      #
0
       # All keys given to url_for are forwarded to the Route module, save for the following:
0
       # * <tt>:anchor</tt> -- specifies the anchor name to be appended to the path. For example,
0
       #   <tt>url_for :controller => 'posts', :action => 'show', :id => 10, :anchor => 'comments'</tt>
...
61
62
63
64
 
65
66
 
67
68
69
...
98
99
100
101
 
102
103
104
...
61
62
63
 
64
65
 
66
67
68
69
...
98
99
100
 
101
102
103
104
0
@@ -61,9 +61,9 @@ module ActionController
0
           # if they're using foo_url(:id=>2) it's one 
0
           # argument, but we don't want to generate /foos/id2
0
           if number_of_arguments == 1
0
-            "defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)"
0
+            "(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)"
0
           else
0
-            "defined?(request) && request && args.size == #{number_of_arguments}"
0
+            "(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == #{number_of_arguments}"
0
           end
0
         end
0
 
0
@@ -98,7 +98,7 @@ module ActionController
0
       # argument
0
       class PositionalArgumentsWithAdditionalParams < PositionalArguments
0
         def guard_condition
0
-          "defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
0
+          "(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
0
         end
0
 
0
         # This case uses almost the same code as positional arguments, 
...
48
49
50
 
 
 
 
 
 
 
 
 
51
52
53
...
134
135
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
...
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
0
@@ -48,6 +48,15 @@ protected
0
   
0
 end
0
 
0
+class DefaultUrlOptionsController < ActionController::Base
0
+  def default_url_options_action
0
+  end
0
+
0
+  def default_url_options(options)
0
+    { :host => 'www.override.com', :action => 'new', :bacon => 'chunky' }
0
+  end
0
+end
0
+
0
 class ControllerClassTests < Test::Unit::TestCase
0
   def test_controller_path
0
     assert_equal 'empty', EmptyController.controller_path
0
@@ -134,3 +143,28 @@ class PerformActionTest < Test::Unit::TestCase
0
     assert_response 404
0
   end
0
 end
0
+
0
+class DefaultUrlOptionsTest < Test::Unit::TestCase
0
+  def setup
0
+    @controller = DefaultUrlOptionsController.new
0
+
0
+    @request    = ActionController::TestRequest.new
0
+    @response   = ActionController::TestResponse.new
0
+
0
+    @request.host = 'www.example.com'
0
+  end
0
+
0
+  def test_default_url_options_are_used_if_set
0
+    ActionController::Routing::Routes.draw do |map|
0
+      map.default_url_options 'default_url_options', :controller => 'default_url_options'
0
+      map.connect ':controller/:action/:id'
0
+    end
0
+
0
+    get :default_url_options_action # Make a dummy request so that the controller is initialized properly.
0
+
0
+    assert_equal 'http://www.override.com/default_url_options/new?bacon=chunky', @controller.url_for(:controller => 'default_url_options')
0
+    assert_equal 'http://www.override.com/default_url_options?bacon=chunky', @controller.send(:default_url_options_url)
0
+  ensure
0
+    ActionController::Routing::Routes.load!
0
+  end
0
+end
0
\ No newline at end of file

Comments