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

Hash#to_param is doesn't use sort anymore, some tests added for Hash#to_param

This commit is contained in:
Santiago Pastorino 2010-07-22 05:08:34 +08:00 committed by Aaron Patterson
parent b0c7dee4f2
commit 5c85822008
2 changed files with 26 additions and 1 deletions

View file

@ -44,6 +44,6 @@ class Hash
def to_param(namespace = nil)
collect do |key, value|
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
end.sort * '&'
end * '&'
end
end

View file

@ -2,6 +2,8 @@ require 'abstract_unit'
require 'active_support/core_ext/hash'
require 'bigdecimal'
require 'active_support/core_ext/string/access'
require 'active_support/ordered_hash'
require 'active_support/core_ext/object/conversions'
class HashExtTest < Test::Unit::TestCase
def setup
@ -449,6 +451,29 @@ class IWriteMyOwnXML
end
end
class HashExtToParamTests < Test::Unit::TestCase
class ToParam < String
def to_param
"#{self}-1"
end
end
def test_string_hash
assert_equal '', {}.to_param
assert_equal 'hello=world', { :hello => "world" }.to_param
assert_equal 'hello=10', { "hello" => 10 }.to_param
assert_equal 'hello=world&say_bye=true', ActiveSupport::OrderedHash[:hello, "world", "say_bye", true].to_param
end
def test_number_hash
assert_equal '10=20&30=40&50=60', ActiveSupport::OrderedHash[10, 20, 30, 40, 50, 60].to_param
end
def test_to_param_hash
assert_equal 'custom=param-1&custom2=param2-1', ActiveSupport::OrderedHash[ToParam.new('custom'), ToParam.new('param'), ToParam.new('custom2'), ToParam.new('param2')].to_param
end
end
class HashToXmlTest < Test::Unit::TestCase
def setup
@xml_options = { :root => :person, :skip_instruct => true, :indent => 0 }