1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix that optimized named routes should also work as singleton methods on the url_helpers module

This commit is contained in:
Jeremy Kemper 2012-05-06 12:44:03 -07:00
parent 9d03e20b19
commit a29bc1cf7b
2 changed files with 26 additions and 1 deletions

View file

@ -188,7 +188,8 @@ module ActionDispatch
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

View file

@ -2538,3 +2538,27 @@ class TestConstraintsAccessingParameters < ActionDispatch::IntegrationTest
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