lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.34 vs lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.35
- old
+ new
@@ -111,11 +111,11 @@
@resource_used = test_values[:suburl] ? @resource[test_values[:suburl]] : @resource
begin
response = case test_values[:method]
- when :post
+ when :post, :patch, :put
unless test_values[:payload]
test_values[:payload] = JSON.generate(test_values[:body]).to_s if test_values[:body]
end
@resource_used.send(test_values[:method].to_s, test_values[:payload], test_values[:params])
else
@@ -148,10 +148,13 @@
# @return [Hash]
def extract_hash(response)
raise ArgumentError("Empty Body. Can't assert on it") if response.body.empty?
case Interpreter.response_type_for response
when :json
- JSON.parse(response.body).transform_keys_to_symbols
+ converted = JSON.parse(response.body)
+ return converted.transform_keys_to_symbols if converted.is_a? Hash
+ return converted.map!(&:transform_keys_to_symbols) if converted.is_a? Array
+ raise 'Incorrect Type prodcued ' + converted.class
when :xml
parser = Nori.new(convert_tags_to: lambda { |tag| tag.snakecase.to_sym })
parser.parse(response.body)
else
raise "Neither XML nor JSON detected. It is #{type}. Don't know how to parse It is #{response.body}"
\ No newline at end of file