From b98fe5dcd1f42e79d8759734728a8ff3d453c82a Mon Sep 17 00:00:00 2001 From: Gabe da Silveira Date: Fri, 14 Nov 2008 01:14:02 -0800 Subject: [PATCH] Make optimized named routes respect all reserved options and tie it into UrlRewriter::RESERVED_OPTIONS so it's DRY --- .../lib/action_controller/routing/optimisations.rb | 8 ++------ .../lib/action_controller/routing/route_set.rb | 1 + actionpack/test/controller/routing_test.rb | 12 +++++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/actionpack/lib/action_controller/routing/optimisations.rb b/actionpack/lib/action_controller/routing/optimisations.rb index 0a87303..8e56f91 100644 --- a/actionpack/lib/action_controller/routing/optimisations.rb +++ b/actionpack/lib/action_controller/routing/optimisations.rb @@ -106,12 +106,8 @@ module ActionController # argument class PositionalArgumentsWithAdditionalParams < PositionalArguments 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)" - ] + ["args.size == #{route.segment_keys.size + 1}"] + + UrlRewriter::RESERVED_OPTIONS.collect{ |key| "!args.last.has_key?(:#{key})" } end # This case uses almost the same code as positional arguments, diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb index ff44849..1b8b52a 100644 --- a/actionpack/lib/action_controller/routing/route_set.rb +++ b/actionpack/lib/action_controller/routing/route_set.rb @@ -168,6 +168,7 @@ module ActionController # @module.module_eval <<-end_eval # We use module_eval to avoid leaks def #{selector}(*args) + #{generate_optimisation_block(route, kind)} opts = if args.empty? || Hash === args.first diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 9699a04..b8a143c 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -706,12 +706,13 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do port = options.delete(:port) || 80 port_string = port == 80 ? '' : ":#{port}" - host = options.delete(:host) || "named.route.test" - anchor = "##{options.delete(:anchor)}" if options.key?(:anchor) + protocol = options.delete(:protocol) || "http" + host = options.delete(:host) || "named.route.test" + anchor = "##{options.delete(:anchor)}" if options.key?(:anchor) path = routes.generate(options) - only_path ? "#{path}#{anchor}" : "http://#{host}#{port_string}#{path}#{anchor}" + only_path ? "#{path}#{anchor}" : "#{protocol}://#{host}#{port_string}#{path}#{anchor}" end def request @@ -1726,6 +1727,11 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do assert_equal "http://some.example.com/people/5", controller.send(:show_url, 5, :host=>"some.example.com") end + def test_named_route_url_method_with_protocol + controller = setup_named_route_test + assert_equal "https://named.route.test/people/5", controller.send(:show_url, 5, :protocol => "https") + end + def test_named_route_url_method_with_ordered_parameters controller = setup_named_route_test assert_equal "http://named.route.test/people/go/7/hello/joe/5", -- 1.6.0.2