Permalink
Browse files

Reinstate default_url_options and remove url_options= writer

  • Loading branch information...
1 parent 514d3a4 commit c507e16dba844c7b066d145bfd5c5d23e7a9c5ad @jeremy jeremy committed Mar 9, 2010
@@ -85,43 +85,24 @@ module UrlFor
extend ActiveSupport::Concern
included do
- # Including in a class uses an inheritable hash. Modules get a plain hash.
- if respond_to?(:class_attribute)
- class_attribute :default_url_options
- else
- mattr_accessor :default_url_options
- end
-
- remove_method :default_url_options
-
- self.default_url_options = {}
- end
-
- # def default_url_options(options = nil)
- # self.class.default_url_options
- # end
+ # TODO: with_routing extends @controller with url_helpers, trickling down to including this module which overrides its default_url_options
+ unless method_defined?(:default_url_options)
+ # Including in a class uses an inheritable hash. Modules get a plain hash.
+ if respond_to?(:class_attribute)
+ class_attribute :default_url_options
+ else
+ mattr_accessor :default_url_options
+ remove_method :default_url_options
+ end
- def url_options
- @url_options ||= begin
- # self.class does not respond to default_url_options when the helpers are extended
- # onto a singleton
- self.class.respond_to?(:default_url_options) ? self.class.default_url_options : {}
+ self.default_url_options = {}
end
end
- def url_options=(options)
- defaults = self.class.respond_to?(:default_url_options) ? self.class.default_url_options : {}
- @url_options = defaults.merge(options)
+ def url_options
+ default_url_options
end
- # def merge_options(options) #:nodoc:
- # if respond_to?(:default_url_options) && (defaults = default_url_options(options))
- # defaults.merge(options)
- # else
- # options
- # end
- # end
-
# Generate a url based on the options provided, default_url_options and the
# routes defined in routes.rb. The following options are supported:
#
@@ -145,23 +126,14 @@ def url_options=(options)
# url_for :controller => 'tasks', :action => 'testing', :host=>'somehost.org', :anchor => 'ok', :only_path => true # => '/tasks/testing#ok'
# url_for :controller => 'tasks', :action => 'testing', :trailing_slash=>true # => 'http://somehost.org/tasks/testing/'
# url_for :controller => 'tasks', :action => 'testing', :host=>'somehost.org', :number => '33' # => 'http://somehost.org/tasks/testing?number=33'
- def url_for(options = {})
- options ||= {}
+ def url_for(options = nil)
case options
- when String
- options
- when Hash
- # Handle the deprecated instance level default_url_options
- if respond_to?(:default_url_options, true)
- ActiveSupport::Deprecation.warn "Overriding the #default_url_options method is deprecated. Instead, set self.url_options = { ... } in a before_filter."
- if defaults = default_url_options(options)
- options = defaults.merge(options)
- end
- end
-
- ActionController::UrlRewriter.rewrite(_router, url_options.merge(options))
- else
- polymorphic_url(options)
+ when String
+ options
+ when nil, Hash
+ ActionController::UrlRewriter.rewrite(_router, url_options.merge(options || {}))
+ else
+ polymorphic_url(options)
end
end
end
@@ -181,7 +181,7 @@ def setup
rescue_action_in_public!
end
- def test_default_url_options_are_used_if_set
+ def test_url_options_override
with_routing do |set|
set.draw do |map|
match 'from_view', :to => 'url_options#from_view', :as => :from_view
@@ -206,20 +206,18 @@ def setup
rescue_action_in_public!
end
- def test_default_url_options_are_used_if_set
+ def test_default_url_options_override
with_routing do |set|
set.draw do |map|
match 'from_view', :to => 'default_url_options#from_view', :as => :from_view
match ':controller/:action'
end
- assert_deprecated do
- get :from_view, :route => "from_view_url"
+ get :from_view, :route => "from_view_url"
- assert_equal 'http://www.override.com/from_view?locale=en', @response.body
- assert_equal 'http://www.override.com/from_view?locale=en', @controller.send(:from_view_url)
- assert_equal 'http://www.override.com/default_url_options/new?locale=en', @controller.url_for(:controller => 'default_url_options')
- end
+ assert_equal 'http://www.override.com/from_view?locale=en', @response.body
+ assert_equal 'http://www.override.com/from_view?locale=en', @controller.send(:from_view_url)
+ assert_equal 'http://www.override.com/default_url_options/new?locale=en', @controller.url_for(:controller => 'default_url_options')
end
end
@@ -232,21 +230,19 @@ def test_default_url_options_are_used_in_non_positional_parameters
match ':controller/:action'
end
- assert_deprecated do
- get :from_view, :route => "description_path(1)"
-
- assert_equal '/en/descriptions/1', @response.body
- assert_equal '/en/descriptions', @controller.send(:descriptions_path)
- assert_equal '/pl/descriptions', @controller.send(:descriptions_path, "pl")
- assert_equal '/pl/descriptions', @controller.send(:descriptions_path, :locale => "pl")
- assert_equal '/pl/descriptions.xml', @controller.send(:descriptions_path, "pl", "xml")
- assert_equal '/en/descriptions.xml', @controller.send(:descriptions_path, :format => "xml")
- assert_equal '/en/descriptions/1', @controller.send(:description_path, 1)
- assert_equal '/pl/descriptions/1', @controller.send(:description_path, "pl", 1)
- assert_equal '/pl/descriptions/1', @controller.send(:description_path, 1, :locale => "pl")
- assert_equal '/pl/descriptions/1.xml', @controller.send(:description_path, "pl", 1, "xml")
- assert_equal '/en/descriptions/1.xml', @controller.send(:description_path, 1, :format => "xml")
- end
+ get :from_view, :route => "description_path(1)"
+
+ assert_equal '/en/descriptions/1', @response.body
+ assert_equal '/en/descriptions', @controller.send(:descriptions_path)
+ assert_equal '/pl/descriptions', @controller.send(:descriptions_path, "pl")
+ assert_equal '/pl/descriptions', @controller.send(:descriptions_path, :locale => "pl")
+ assert_equal '/pl/descriptions.xml', @controller.send(:descriptions_path, "pl", "xml")
+ assert_equal '/en/descriptions.xml', @controller.send(:descriptions_path, :format => "xml")
+ assert_equal '/en/descriptions/1', @controller.send(:description_path, 1)
+ assert_equal '/pl/descriptions/1', @controller.send(:description_path, "pl", 1)
+ assert_equal '/pl/descriptions/1', @controller.send(:description_path, 1, :locale => "pl")
+ assert_equal '/pl/descriptions/1.xml', @controller.send(:description_path, "pl", 1, "xml")
+ assert_equal '/en/descriptions/1.xml', @controller.send(:description_path, 1, :format => "xml")
end
end
@@ -437,7 +437,7 @@ def default_url_options(options = nil)
end
with_url_helper_routing do
- assert_deprecated { get :show_named_route, :kind => 'url' }
+ get :show_named_route, :kind => 'url'
assert_equal 'http://testtwo.host/url_helper_controller_test/url_helper/show_named_route', @response.body
end
end

1 comment on commit c507e16

Member

josh commented on c507e16 Mar 9, 2010

thank god

Please sign in to comment.