spec/hash_spec.rb in extlib-0.9.15 vs spec/hash_spec.rb in extlib-0.9.16
- old
+ new
@@ -139,16 +139,16 @@
Hash.from_xml(xml)['tag'].should == 10
end
it "should typecast a true boolean" do
xml = "<tag type='boolean'>true</tag>"
- Hash.from_xml(xml)['tag'].should be_true
+ Hash.from_xml(xml)['tag'].should be(true)
end
it "should typecast a false boolean" do
["false"].each do |w|
- Hash.from_xml("<tag type='boolean'>#{w}</tag>")['tag'].should be_false
+ Hash.from_xml("<tag type='boolean'>#{w}</tag>")['tag'].should be(false)
end
end
it "should typecast a datetime" do
xml = "<tag type='datetime'>2007-12-31 10:32</tag>"
@@ -252,11 +252,11 @@
'title' => nil,
'id' => nil,
'approved' => nil,
'written_on' => nil,
'viewed_at' => nil,
- 'content' => nil,
+ 'content' => { 'type' => 'yaml' },
'parent_id' => nil
}
Hash.from_xml(topic_xml)["topic"].should == expected_topic_hash
end
@@ -290,16 +290,16 @@
'written_on' => Date.new(2003, 7, 16),
'viewed_at' => Time.utc(2003, 7, 16, 9, 28),
# Changed this line where the key is :message. The yaml specifies this as a symbol, and who am I to change what you specify
# The line in ActiveSupport is
# 'content' => { 'message' => "Have a nice day", 1 => "should be an integer", "array" => [{ "should-have-dashes" => true, "should_have_underscores" => true }] },
- 'content' => { :message => "Have a nice day", 1 => "should be an integer", "array" => [{ "should-have-dashes" => true, "should_have_underscores" => true }] },
+ 'content' => "--- \n1: should be an integer\n:message: Have a nice day\narray: \n- should-have-dashes: true\n should_have_underscores: true\n",
'author_email_address' => "david@loudthinking.com",
'parent_id' => nil,
'ad_revenue' => BigDecimal("1.50"),
'optimum_viewing_angle' => 135.0,
- 'resident' => :yes
+ 'resident' => 'yes'
}
Hash.from_xml(topic_xml)["topic"].each do |k,v|
v.should == expected_topic_hash[k]
end
@@ -507,21 +507,29 @@
end
describe Hash, 'to_params' do
{
{ "foo" => "bar", "baz" => "bat" } => "foo=bar&baz=bat",
- { "foo" => [ "bar", "baz" ] } => "foo[]=bar&foo[]=baz",
- { "foo" => [ {"bar" => "1"}, {"bar" => 2} ] } => "foo[][bar]=1&foo[][bar]=2",
- { "foo" => { "bar" => [ {"baz" => 1}, {"baz" => "2"} ] } } => "foo[bar][][baz]=1&foo[bar][][baz]=2",
- { "foo" => {"1" => "bar", "2" => "baz"} } => "foo[1]=bar&foo[2]=baz"
+ { "foo" => [ "bar", "baz" ] } => "foo%5B%5D=bar&foo%5B%5D=baz",
+ { "foo" => [ {"bar" => "1"}, {"bar" => 2} ] } => "foo%5B%5D%5Bbar%5D=1&foo%5B%5D%5Bbar%5D=2",
+ { "foo" => { "bar" => [ {"baz" => 1}, {"baz" => "2"} ] } } => "foo%5Bbar%5D%5B%5D%5Bbaz%5D=1&foo%5Bbar%5D%5B%5D%5Bbaz%5D=2",
+ { "foo" => {"1" => "bar", "2" => "baz"} } => "foo%5B1%5D=bar&foo%5B2%5D=baz"
}.each do |hash, params|
it "should covert hash: #{hash.inspect} to params: #{params.inspect}" do
hash.to_params.split('&').sort.should == params.split('&').sort
end
end
it 'should not leave a trailing &' do
{ :name => 'Bob', :address => { :street => '111 Ruby Ave.', :city => 'Ruby Central', :phones => ['111-111-1111', '222-222-2222'] } }.to_params.should_not match(/&$/)
+ end
+
+ it 'should encode query keys' do
+ { 'First & Last' => 'Alice Smith' }.to_params.should == "First%20%26%20Last=Alice%20Smith"
+ end
+
+ it 'should encode query values' do
+ { :name => 'Alice & Bob' }.to_params.should == "name=Alice%20%26%20Bob"
end
end
describe Hash, 'to_mash' do
before :each do