mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Correctly handle nested params
This commit is contained in:
parent
1a52a134c4
commit
c51cb3e2d7
2 changed files with 8 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue