Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure that when UrlWriter is included in multiple classes, the defau…

…lt_url_options of one don't affect the other. [#1277 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit 32eeb3e5211a4a7bfc7a1d0aa0cab1486bed3581 1 parent 7487196
@atnan atnan authored lifo committed
View
9 actionpack/lib/action_controller/url_rewriter.rb
@@ -92,15 +92,12 @@ module ActionController
# end
# end
module UrlWriter
- # The default options for urls written by this writer. Typically a <tt>:host</tt>
- # 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
+
+ # The default options for urls written by this writer. Typically a <tt>:host</tt> pair is provided.
+ base.default_url_options ||= {}
end
# Generate a url based on the options provided, default_url_options and the
View
17 actionpack/test/controller/url_rewriter_test.rb
@@ -303,7 +303,6 @@ def test_path_generation_for_symbol_parameter_keys
def test_named_routes_with_nil_keys
ActionController::Routing::Routes.clear!
- add_host!
ActionController::Routing::Routes.draw do |map|
map.main '', :controller => 'posts'
map.resources :posts
@@ -311,6 +310,8 @@ def test_named_routes_with_nil_keys
end
# We need to create a new class in order to install the new named route.
kls = Class.new { include ActionController::UrlWriter }
+ kls.default_url_options[:host] = 'www.basecamphq.com'
+
controller = kls.new
params = {:action => :index, :controller => :posts, :format => :xml}
assert_equal("http://www.basecamphq.com/posts.xml", controller.send(:url_for, params))
@@ -337,6 +338,20 @@ def test_formatted_url_methods_are_deprecated
ensure
ActionController::Routing::Routes.load!
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)
url.split('?', 2).last.split('&')

1 comment on commit 32eeb3e

@findchris

This commit breaks setting URL options in initializers (or environment files), such as in the following case: ActionController::UrlWriter::default_url_options[:host] = ‘localhost’ ActionController::UrlWriter::default_url_options[:port] = 3000

Lighthouse ticket is here (trying to reopen the original patch ticket): http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1277-patch-ensure-actioncontrollerurlwriterdefault_url_options-is-unique-across-classes#ticket-1277-6

Thanks, Chris

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