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

Merge pull request #583 from jmortlock/fix-nested-params

Correctly handle nested params
This commit is contained in:
John Nunemaker 2018-03-20 13:17:29 -04:00 committed by GitHub
commit db8df8c58b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -26,7 +26,7 @@ module HTTParty
def self.normalize_param(key, value)
normalized_keys = normalize_keys(key, value)
normalized_keys.inject('') do |string, (k, v)|
normalized_keys.flatten.each_slice(2).inject('') do |string, (k, v)|
string + "#{k}=#{ERB::Util.url_encode(v.to_s)}&"
end
end

View file

@ -11,6 +11,13 @@ RSpec.describe HTTParty::HashConversions do
}
expect(HTTParty::HashConversions.to_params(hash)).to eq("name=bob&address[street]=111%20ruby%20ave.&address[city]=ruby%20central&address[phones][]=111-111-1111&address[phones][]=222-222-2222")
end
context "nested params" do
it 'creates a params string from a hash' do
hash = { marketing_event: { marketed_resources: [ {type:"product", id: 57474842640 } ] } }
expect(HTTParty::HashConversions.to_params(hash)).to eq("marketing_event[marketed_resources][][type]=product&marketing_event[marketed_resources][][id]=57474842640")
end
end
end
describe ".normalize_param" do