diff options
Diffstat (limited to 'actionpack')
22 files changed, 216 insertions, 40 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 3c06c87bb2..17fada156d 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,3 +1,14 @@ +*2.2.1 [RC2 or 2.2 final]* + +* Simplified the logging format for parameters (don't include controller, action, and format as duplicates) [DHH] + +* Remove the logging of the Session ID when the session store is CookieStore [DHH] + +* Fixed regex in redirect_to to fully support URI schemes #1247 [Seth Fitzsimmons] + +* Fixed bug with asset timestamping when using relative_url_root #1265 [Joe Goldwasser] + + *2.2.0 [RC1] (October 24th, 2008)* * Fix incorrect closing CDATA delimiter and that HTML::Node.parse would blow up on unclosed CDATA sections [packagethief] diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 006a3039af..cf86c5eed0 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -801,6 +801,19 @@ module ActionController #:nodoc: # # Renders "Hello from code!" # render :text => proc { |response, output| output.write("Hello from code!") } # + # === Rendering XML + # + # Rendering XML sets the content type to application/xml. + # + # # Renders '<name>David</name>' + # render :xml => {:name => "David"}.to_xml + # + # It's not necessary to call <tt>to_xml</tt> on the object you want to render, since <tt>render</tt> will + # automatically do that for you: + # + # # Also renders '<name>David</name>' + # render :xml => {:name => "David"} + # # === Rendering JSON # # Rendering JSON sets the content type to application/json and optionally wraps the JSON in a callback. It is expected @@ -846,8 +859,14 @@ module ActionController #:nodoc: # page.visual_effect :highlight, 'user_list' # end # - # === Rendering with status and location headers + # === Rendering vanilla JavaScript + # + # In addition to using RJS with render :update, you can also just render vanilla JavaScript with :js. + # + # # Renders "alert('hello')" and sets the mime type to text/javascript + # render :js => "alert('hello')" # + # === Rendering with status and location headers # All renders take the <tt>:status</tt> and <tt>:location</tt> options and turn them into headers. They can even be used together: # # render :xml => post.to_xml, :status => :created, :location => post_url(post) @@ -898,6 +917,10 @@ module ActionController #:nodoc: response.content_type ||= Mime::XML render_for_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, options[:status]) + elsif js = options[:js] + response.content_type ||= Mime::JS + render_for_text(js, options[:status]) + elsif json = options[:json] json = json.to_json unless json.is_a?(String) json = "#{options[:callback]}(#{json})" unless options[:callback].blank? @@ -933,6 +956,7 @@ module ActionController #:nodoc: def render_to_string(options = nil, &block) #:doc: render(options, &block) ensure + response.content_type = nil erase_render_results reset_variables_added_to_assigns end @@ -1056,7 +1080,10 @@ module ActionController #:nodoc: logger.info("Redirected to #{options}") if logger && logger.info? case options - when %r{^\w+://.*} + # The scheme name consist of a letter followed by any combination of + # letters, digits, and the plus ("+"), period ("."), or hyphen ("-") + # characters; and is terminated by a colon (":"). + when %r{^\w[\w\d+.-]*:.*} redirect_to_full_url(options, status) when String redirect_to_full_url(request.protocol + request.host_with_port + options, status) @@ -1201,11 +1228,33 @@ module ActionController #:nodoc: def log_processing if logger && logger.info? - logger.info "\n\nProcessing #{self.class.name}\##{action_name} (for #{request_origin}) [#{request.method.to_s.upcase}]" - logger.info " Session ID: #{@_session.session_id}" if @_session and @_session.respond_to?(:session_id) - logger.info " Parameters: #{respond_to?(:filter_parameters) ? filter_parameters(params).inspect : params.inspect}" + log_processing_for_request_id + log_processing_for_session_id + log_processing_for_parameters end end + + def log_processing_for_request_id + request_id = "\n\nProcessing #{self.class.name}\##{action_name} " + request_id << "to #{params[:format]} " if params[:format] + request_id << "(for #{request_origin}) [#{request.method.to_s.upcase}]" + + logger.info(request_id) + end + + def log_processing_for_session_id + if @_session && @_session.respond_to?(:session_id) && @_session.respond_to?(:dbman) && + !@_session.dbman.is_a?(CGI::Session::CookieStore) + logger.info " Session ID: #{@_session.session_id}" + end + end + + def log_processing_for_parameters + parameters = respond_to?(:filter_parameters) ? filter_parameters(params) : params + parameters = parameters.except(:controller, :action, :format) + + logger.info " Parameters: #{parameters.inspect}" + end def default_render #:nodoc: render diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb index 28f8ce3d53..f3e173004a 100644 --- a/actionpack/lib/action_controller/dispatcher.rb +++ b/actionpack/lib/action_controller/dispatcher.rb @@ -28,6 +28,10 @@ module ActionController end after_dispatch :flush_logger if Base.logger && Base.logger.respond_to?(:flush) + + to_prepare do + I18n.reload! + end end # Backward-compatible class method takes CGI-specific args. Deprecated diff --git a/actionpack/lib/action_controller/routing/optimisations.rb b/actionpack/lib/action_controller/routing/optimisations.rb index 894d4109e4..0a87303bda 100644 --- a/actionpack/lib/action_controller/routing/optimisations.rb +++ b/actionpack/lib/action_controller/routing/optimisations.rb @@ -20,14 +20,20 @@ module ActionController class Optimiser attr_reader :route, :kind + GLOBAL_GUARD_CONDITIONS = [ + "(!defined?(default_url_options) || default_url_options.blank?)", + "(!defined?(controller.default_url_options) || controller.default_url_options.blank?)", + "defined?(request)", + "request" + ] def initialize(route, kind) @route = route @kind = kind end - def guard_condition - 'false' + def guard_conditions + ["false"] end def generation_code @@ -36,6 +42,7 @@ module ActionController def source_code if applicable? + guard_condition = (GLOBAL_GUARD_CONDITIONS + guard_conditions).join(" && ") "return #{generation_code} if #{guard_condition}\n" else "\n" @@ -57,14 +64,14 @@ module ActionController # return a string like "/people/#{@person.to_param}" # rather than triggering the expensive logic in +url_for+. class PositionalArguments < Optimiser - def guard_condition + def guard_conditions number_of_arguments = route.segment_keys.size # if they're using foo_url(:id=>2) it's one # argument, but we don't want to generate /foos/id2 if number_of_arguments == 1 - "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)" + ["args.size == 1", "!args.first.is_a?(Hash)"] else - "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{number_of_arguments}" + ["args.size == #{number_of_arguments}"] end end @@ -98,8 +105,13 @@ module ActionController # above, but it supports additional query parameters as the last # argument class PositionalArgumentsWithAdditionalParams < PositionalArguments - def guard_condition - "(!defined?(default_url_options) || default_url_options.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)" + def guard_conditions + [ + "args.size == #{route.segment_keys.size + 1}", + "!args.last.has_key?(:anchor)", + "!args.last.has_key?(:port)", + "!args.last.has_key?(:host)" + ] end # This case uses almost the same code as positional arguments, diff --git a/actionpack/lib/action_controller/routing/recognition_optimisation.rb b/actionpack/lib/action_controller/routing/recognition_optimisation.rb index 4935432d87..6c47ced6d1 100644 --- a/actionpack/lib/action_controller/routing/recognition_optimisation.rb +++ b/actionpack/lib/action_controller/routing/recognition_optimisation.rb @@ -153,13 +153,7 @@ module ActionController def clear_recognize_optimized! remove_recognize_optimized! - - class << self - def recognize_optimized(path, environment) - write_recognize_optimized! - recognize_optimized(path, environment) - end - end + write_recognize_optimized! end def remove_recognize_optimized! diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index f84c48f102..7a31f0e8d5 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -218,7 +218,7 @@ module ActionController #:nodoc: # Returns the template of the file which was used to # render this response (or nil) def rendered_template - template.send(:_first_render) + template.instance_variable_get(:@_first_render) end # A shortcut to the flash. Returns an empty hash if no session flash exists. diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index e22978fe27..945246a39a 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -222,6 +222,7 @@ module ActionView #:nodoc: def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc: @assigns = assigns_for_first_render @assigns_added = nil + @_render_stack = [] @controller = controller @helpers = ProxyModule.new(self) self.view_paths = view_paths @@ -271,9 +272,13 @@ module ActionView #:nodoc: end end - private - attr_accessor :_first_render, :_last_render + # Access the current template being rendered. + # Returns a ActionView::Template object. + def template + @_render_stack.last + end + private # Evaluates the local assigns and controller ivars, pushes them to the view. def _evaluate_assigns_and_ivars #:nodoc: unless @assigns_added @@ -312,7 +317,7 @@ module ActionView #:nodoc: template elsif template = self.view_paths[template_file_name] template - elsif _first_render && template = self.view_paths["#{template_file_name}.#{_first_render.format_and_extension}"] + elsif @_render_stack.first && template = self.view_paths["#{template_file_name}.#{@_render_stack.first.format_and_extension}"] template elsif template_format == :js && template = self.view_paths["#{template_file_name}.html"] @template_format = :html diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 93d38eb929..8bbe74b7ef 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -588,8 +588,8 @@ module ActionView source += ".#{extension}" if missing_extension?(source) unless source =~ ProtocolRegexp source = "/#{directory}/#{source}" unless source[0] == ?/ - source = prepend_relative_url_root(source) source = rewrite_asset_path(source) + source = prepend_relative_url_root(source) end source = prepend_asset_host(source) source diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index de4c1d7689..dc41ef5305 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -3,12 +3,11 @@ require 'action_view/helpers/tag_helper' module ActionView module Helpers module TranslationHelper - def translate(*args) - args << args.extract_options!.merge(:raise => true) - I18n.translate *args - + def translate(key, options = {}) + options[:raise] = true + I18n.translate(key, options) rescue I18n::MissingTranslationData => e - keys = I18n.send :normalize_translation_keys, e.locale, e.key, e.options[:scope] + keys = I18n.send(:normalize_translation_keys, e.locale, e.key, e.options[:scope]) content_tag('span', keys.join(', '), :class => 'translation_missing') end alias :t :translate diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 7ba42a3b72..2e0eb8766b 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -499,7 +499,7 @@ module ActionView # True if the current request URI was generated by the given +options+. # # ==== Examples - # Let's say we're in the <tt>/shop/checkout</tt> action. + # Let's say we're in the <tt>/shop/checkout?order=desc</tt> action. # # current_page?(:action => 'process') # # => false @@ -507,6 +507,9 @@ module ActionView # current_page?(:controller => 'shop', :action => 'checkout') # # => true # + # current_page?(:controller => 'shop', :action => 'checkout', :order => 'asc) + # # => false + # # current_page?(:action => 'checkout') # # => true # @@ -515,10 +518,18 @@ module ActionView def current_page?(options) url_string = CGI.escapeHTML(url_for(options)) request = @controller.request + # We ignore any extra parameters in the request_uri if the + # submitted url doesn't have any either. This lets the function + # work with things like ?order=asc + if url_string.index("?") + request_uri = request.request_uri + else + request_uri = request.request_uri.split('?').first + end if url_string =~ /^\w+:\/\// - url_string == "#{request.protocol}#{request.host_with_port}#{request.request_uri}" + url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}" else - url_string == request.request_uri + url_string == request_uri end end diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index 373bb92dc4..8841099900 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -181,7 +181,7 @@ module ActionView ActionController::RecordIdentifier.partial_path(object, controller.class.controller_path) template = _pick_partial_template(_partial_path) local_assigns[template.counter_name] = index - result = template.render_partial(self, object, local_assigns, as) + result = template.render_partial(self, object, local_assigns.dup, as) index += 1 result end.join(spacer) diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb index 0134bc988f..c23b8cde89 100644 --- a/actionpack/lib/action_view/renderable.rb +++ b/actionpack/lib/action_view/renderable.rb @@ -25,20 +25,26 @@ module ActionView def render(view, local_assigns = {}) compile(local_assigns) - view.send(:_first_render=, self) unless view.send(:_first_render) - view.send(:_last_render=, self) + stack = view.instance_variable_get(:@_render_stack) + stack.push(self) + + # This is only used for TestResponse to set rendered_template + view.instance_variable_set(:@_first_render, self) unless view.instance_variable_get(:@_first_render) view.send(:_evaluate_assigns_and_ivars) view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type) - view.send(method_name(local_assigns), local_assigns) do |*names| + result = view.send(method_name(local_assigns), local_assigns) do |*names| ivar = :@_proc_for_layout - if view.instance_variable_defined?(ivar) and proc = view.instance_variable_get(ivar) + if !view.instance_variable_defined?(:"@content_for_#{names.first}") && view.instance_variable_defined?(ivar) && (proc = view.instance_variable_get(ivar)) view.capture(*names, &proc) elsif view.instance_variable_defined?(ivar = :"@content_for_#{names.first || :layout}") view.instance_variable_get(ivar) end end + + stack.pop + result end def method_name(local_assigns) diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 2f8bf7b6ee..c55307d645 100644 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -73,6 +73,10 @@ class RedirectController < ActionController::Base redirect_to "http://dev.rubyonrails.org/query?status=new" end + def redirect_to_url_with_complex_scheme + redirect_to "x-test+scheme.complex:redirect" + end + def redirect_to_back redirect_to :back end @@ -198,6 +202,12 @@ class RedirectTest < Test::Unit::TestCase assert_redirected_to "http://dev.rubyonrails.org/query?status=new" end + def test_redirect_to_url_with_complex_scheme + get :redirect_to_url_with_complex_scheme + assert_response :redirect + assert_equal "x-test+scheme.complex:redirect", redirect_to_url + end + def test_redirect_to_back @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from" get :redirect_to_back diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index db2d5d885b..df9376727f 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -154,6 +154,10 @@ class TestController < ActionController::Base render :json => {:hello => 'world'}.to_json end + def render_json_with_render_to_string + render :json => {:hello => render_to_string(:partial => 'partial')} + end + def render_custom_code render :text => "hello world", :status => 404 end @@ -180,6 +184,10 @@ class TestController < ActionController::Base render("test/hello") end + def render_vanilla_js_hello + render :js => "alert('hello')" + end + def render_xml_hello @name = "David" render :template => "test/hello" @@ -772,6 +780,12 @@ class RenderTest < Test::Unit::TestCase assert_equal 'application/json', @response.content_type end + def test_render_json_with_render_to_string + get :render_json_with_render_to_string + assert_equal '{"hello": "partial html"}', @response.body + assert_equal 'application/json', @response.content_type + end + def test_render_custom_code get :render_custom_code assert_response 404 @@ -834,6 +848,12 @@ class RenderTest < Test::Unit::TestCase assert_equal "test", @response.body # name is explicitly set to 'test' inside the controller. end + def test_render_vanilla_js + get :render_vanilla_js_hello + assert_equal "alert('hello')", @response.body + assert_equal "text/javascript", @response.content_type + end + def test_render_xml get :render_xml_hello assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body diff --git a/actionpack/test/fixtures/layouts/_column.html.erb b/actionpack/test/fixtures/layouts/_column.html.erb new file mode 100644 index 0000000000..96db002b8a --- /dev/null +++ b/actionpack/test/fixtures/layouts/_column.html.erb @@ -0,0 +1,2 @@ +<div id="column"><%= yield :column %></div> +<div id="content"><%= yield %></div>
\ No newline at end of file diff --git a/actionpack/test/fixtures/test/_customer.erb b/actionpack/test/fixtures/test/_customer.erb index 872d8c44e6..d8220afeda 100644 --- a/actionpack/test/fixtures/test/_customer.erb +++ b/actionpack/test/fixtures/test/_customer.erb @@ -1 +1 @@ -Hello: <%= customer.name %>
\ No newline at end of file +Hello: <%= customer.name rescue "Anonymous" %>
\ No newline at end of file diff --git a/actionpack/test/fixtures/test/nested_layout.erb b/actionpack/test/fixtures/test/nested_layout.erb new file mode 100644 index 0000000000..7b6dcbb6c7 --- /dev/null +++ b/actionpack/test/fixtures/test/nested_layout.erb @@ -0,0 +1,3 @@ +<% content_for :title, "title" -%> +<% content_for :column do -%>column<% end -%> +<% render :layout => 'layouts/column' do -%>content<% end -%>
\ No newline at end of file diff --git a/actionpack/test/fixtures/test/template.erb b/actionpack/test/fixtures/test/template.erb new file mode 100644 index 0000000000..785afa8f6a --- /dev/null +++ b/actionpack/test/fixtures/test/template.erb @@ -0,0 +1 @@ +<%= template.path %>
\ No newline at end of file diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 6dc1225035..bade96fe17 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -248,6 +248,14 @@ class AssetTagHelperTest < ActionView::TestCase assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png") end + def test_timebased_asset_id_with_relative_url_root + ActionController::Base.relative_url_root = "/collaboration/hieraki" + expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s + assert_equal %(<img alt="Rails" src="#{ActionController::Base.relative_url_root}/images/rails.png?#{expected_time}" />), image_tag("rails.png") + ensure + ActionController::Base.relative_url_root = "" + end + def test_should_skip_asset_id_on_complete_url assert_equal %(<img alt="Rails" src="http://www.example.com/rails.png" />), image_tag("http://www.example.com/rails.png") end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index a4ea22ddcb..476e651757 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -41,6 +41,10 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal "The secret is in the sauce\n", @view.render("test/dot.directory/render_file_with_ivar") end + def test_render_has_access_current_template + assert_equal "test/template.erb", @view.render("test/template.erb") + end + def test_render_update # TODO: You should not have to stub out template because template is self! @view.instance_variable_set(:@template, @view) @@ -111,6 +115,10 @@ class ViewRenderTest < Test::Unit::TestCase assert_nil @view.render(:partial => "test/customer", :collection => nil) end + def test_render_partial_with_nil_values_in_collection + assert_equal "Hello: davidHello: Anonymous", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), nil ]) + end + def test_render_partial_with_empty_array_should_return_nil assert_nil @view.render(:partial => []) end @@ -158,4 +166,14 @@ class ViewRenderTest < Test::Unit::TestCase ActionView::Template.register_template_handler :foo, CustomHandler assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) end + + def test_render_with_layout + assert_equal %(<title></title>\nHello world!\n), + @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield") + end + + def test_render_with_nested_layout + assert_equal %(<title>title</title>\n<div id="column">column</div>\n<div id="content">content</div>\n), + @view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield") + end end diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb index 7b94221ec0..1b28a59288 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -10,8 +10,8 @@ class TranslationHelperTest < Test::Unit::TestCase end def test_delegates_to_i18n_setting_the_raise_option - I18n.expects(:translate).with(:foo, 'en-US', :raise => true) - translate :foo, 'en-US' + I18n.expects(:translate).with(:foo, :locale => 'en-US', :raise => true) + translate :foo, :locale => 'en-US' end def test_returns_missing_translation_message_wrapped_into_span diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 85e967ac1c..2f6fa134b5 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -258,6 +258,16 @@ class UrlHelperTest < ActionView::TestCase 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?order=desc") + @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?order=desc") + @controller.url = "http://www.example.com/weblog/show?order=asc" + assert_equal "<a href=\"http://www.example.com/weblog/show?order=asc\">Showing</a>", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" }) + assert_equal "<a href=\"http://www.example.com/weblog/show?order=asc\">Showing</a>", link_to_unless_current("Showing", "http://www.example.com/weblog/show?order=asc") + @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>", @@ -366,6 +376,19 @@ class UrlHelperWithControllerTest < ActionView::TestCase assert_equal '/url_helper_with_controller/nil_url_for', @response.body end + def test_named_route_should_show_host_and_path_using_controller_default_url_options + class << @controller + def default_url_options(options = nil) + {:host => 'testtwo.host'} + end + end + + with_url_helper_routing do + get :show_named_route, :kind => 'url' + assert_equal 'http://testtwo.host/url_helper_with_controller/show_named_route', @response.body + end + end + protected def with_url_helper_routing with_routing do |set| |