Skip to content

Commit

Permalink
Merge pull request #583 from jmortlock/fix-nested-params
Browse files Browse the repository at this point in the history
Correctly handle nested params
  • Loading branch information
jnunemaker authored Mar 20, 2018
2 parents 1a52a13 + c51cb3e commit db8df8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/httparty/hash_conversions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.to_params(hash)
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
Expand Down
7 changes: 7 additions & 0 deletions spec/httparty/hash_conversions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
}
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
Expand Down

0 comments on commit db8df8c

Please sign in to comment.