1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Moved character encoding test from core_extensions_spec.rb into hash_spec.rb and deleted now redundant core_extensions_spac.rb

Signed-off-by: John Nunemaker <nunemaker@gmail.com>
This commit is contained in:
Julian Russell 2009-02-01 18:54:57 +08:00 committed by John Nunemaker
parent 3db19cbee5
commit 98230a5837
2 changed files with 5 additions and 30 deletions

View file

@ -1,30 +0,0 @@
require File.join(File.dirname(__FILE__), 'spec_helper')
describe "Core Extensions" do
describe Hash do
describe "#to_params" do
def should_be_same_params(query_string, expected)
query_string.split(/&/).sort.should == expected.split(/&/).sort
end
it "should encode characters in URL parameters" do
{:q => "?&\" +"}.to_params.should == "q=%3F%26%22%20%2B"
end
it "should handle multiple parameters" do
should_be_same_params({:q1 => "p1", :q2 => "p2"}.to_params, "q1=p1&q2=p2")
end
it "should handle nested hashes like rails does" do
should_be_same_params({
:name => "Bob",
:address => {
:street => '111 Ruby Ave.',
:city => 'Ruby Central',
:phones => ['111-111-1111', '222-222-2222']
}
}.to_params, "name=Bob&address[city]=Ruby%20Central&address[phones][]=111-111-1111&address[phones][]=222-222-2222&address[street]=111%20Ruby%20Ave.")
end
end
end
end

View file

@ -41,4 +41,9 @@ describe Hash, 'to_params' do
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 URL encode unsafe characters' do
{:q => "?&\" +"}.to_params.should == "q=%3F%26%22%20%2B"
end
end