From 6d682702c3267889bb55070dd16163ef954536e7 Mon Sep 17 00:00:00 2001 From: Nathan de Vries Date: Mon, 27 Oct 2008 22:52:45 +1100 Subject: [PATCH] Ensure that when ActionController::UrlWriter is included in multiple classes, the default_url_options of one don't affect the other. --- actionpack/lib/action_controller/url_rewriter.rb | 6 +----- actionpack/test/controller/url_rewriter_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index d86e2db..65fb489 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -92,15 +92,11 @@ module ActionController # end # end module UrlWriter - # The default options for urls written by this writer. Typically a :host - # pair is provided. - mattr_accessor :default_url_options - self.default_url_options = {} def self.included(base) #:nodoc: ActionController::Routing::Routes.install_helpers(base) base.mattr_accessor :default_url_options - base.default_url_options ||= default_url_options + base.default_url_options ||= {} end # Generate a url based on the options provided, default_url_options and the diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index 64e9a08..2086a05 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -301,6 +301,19 @@ class UrlWriterTests < Test::Unit::TestCase def test_path_generation_for_symbol_parameter_keys assert_generates("/image", :controller=> :image) end + + def test_multiple_includes_maintain_distinct_options + first_class = Class.new { include ActionController::UrlWriter } + second_class = Class.new { include ActionController::UrlWriter } + + first_host, second_host = 'firsthost.com', 'secondhost.com' + + first_class.default_url_options[:host] = first_host + second_class.default_url_options[:host] = second_host + + assert_equal first_class.default_url_options[:host], first_host + assert_equal second_class.default_url_options[:host], second_host + end private def extract_params(url) -- 1.5.6.4