Permalink
Browse files

Fix that optimized named routes should also work as singleton methods…

… on the url_helpers module
  • Loading branch information...
1 parent 9d03e20 commit a29bc1cf7b8580a815523e4c3a79e931f03ab8c2 @jeremy jeremy committed May 6, 2012
Showing with 26 additions and 1 deletion.
  1. +2 −1 actionpack/lib/action_dispatch/routing/route_set.rb
  2. +24 −0 actionpack/test/dispatch/routing_test.rb
@@ -188,7 +188,8 @@ def define_url_helper(route, name, options)
remove_possible_method :#{selector}
def #{selector}(*args)
if #{optimize_helper?(route)} && args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
- options = #{options.inspect}.merge!(url_options)
+ options = #{options.inspect}
+ options.merge!(url_options) if respond_to?(:url_options)
options[:path] = "#{optimized_helper(route)}"
ActionDispatch::Http::URL.url_for(options)
else
@@ -2538,3 +2538,27 @@ def app; Routes end
assert_equal "bar", @request.params[:bar]
end
end
+
+class TestOptimizedNamedRoutes < ActionDispatch::IntegrationTest
+ Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
+ app.draw do
+ ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] }
+ get '/foo' => ok, as: :foo
+ end
+ end
+
+ include Routes.url_helpers
+ def app; Routes end
+
+ test 'enabled when not mounted and default_url_options is empty' do
+ assert Routes.url_helpers.optimize_routes_generation?
+ end
+
+ test 'named route called as singleton method' do
+ assert_equal '/foo', Routes.url_helpers.foo_path
+ end
+
+ test 'named route called on included module' do
+ assert_equal '/foo', foo_path
+ end
+end

0 comments on commit a29bc1c

Please sign in to comment.