Permalink
Browse files

Make hash_from_request_body_with_key always return a hash

It was returning a blank string in the case where the key had no value. Changed
to return an empty hash.
  • Loading branch information...
1 parent 90bcf1c commit c444277caa290a46c87e4e9361a6a341b6e1ea42 @wonnage wonnage committed with Gabe Berke-Williams Nov 27, 2012
Showing with 6 additions and 5 deletions.
  1. +1 −4 lib/fake_braintree/customer.rb
  2. +5 −1 lib/fake_braintree/sinatra_app.rb
@@ -7,10 +7,7 @@ def initialize(customer_hash_from_params, options)
"id" => options[:id],
"merchant_id" => options[:merchant_id]
}
- if customer_hash_from_params.is_a?(Hash)
- @customer_hash.merge!(customer_hash_from_params)
- end
-
+ @customer_hash.merge!(customer_hash_from_params)
set_customer_id
end
@@ -11,7 +11,11 @@ class SinatraApp < Sinatra::Base
helpers do
def hash_from_request_body_with_key(request, key)
- Hash.from_xml(request.body).delete(key)
+ value = Hash.from_xml(request.body).delete(key)
+ if value.is_a?(String) # This happens if there isn't actually nested data under `key`
+ value = {}
+ end
+ value
end
end

0 comments on commit c444277

Please sign in to comment.