Ensure that segments in default_url_options also work with format specified.

This commit is contained in:
José Valim 2010-01-07 17:17:06 +01:00
parent f149eb19d4
commit 3b631df101
2 changed files with 10 additions and 2 deletions

View File

@ -178,7 +178,7 @@ module ActionDispatch
# options = (default ||= {}).merge(options)
#
# keys = []
# keys -= options.keys unless keys.size == args.size
# keys -= options.keys if args.size < keys.size - 1
#
# args = args.zip(keys).inject({}) do |h, (v, k)|
# h[k] = v
@ -202,7 +202,7 @@ module ActionDispatch
options = (default ||= {}).merge(options)
keys = #{route.segment_keys.inspect}
keys -= options.keys unless keys.size == args.size
keys -= options.keys if args.size < keys.size - 1 # take format into account
args = args.zip(keys).inject({}) do |h, (v, k)|
h[k] = v

View File

@ -172,8 +172,16 @@ class DefaultUrlOptionsTest < ActionController::TestCase
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