mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Replace the JSON round-trip with #stringify.
Let's use a proper method to emulate what round-tripping data structures through the JSON API will do.
This commit is contained in:
parent
2ead5257b2
commit
2e872342dc
2 changed files with 21 additions and 4 deletions
|
@ -232,6 +232,23 @@ module Fog
|
|||
def self.zulu_time
|
||||
Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
end
|
||||
|
||||
def self.stringify(message)
|
||||
case message
|
||||
when Symbol
|
||||
message.to_s
|
||||
when Hash
|
||||
result = Hash.new
|
||||
message.each do |key, value|
|
||||
nk = stringify(key)
|
||||
nv = stringify(value)
|
||||
result[nk] = nv
|
||||
end
|
||||
result
|
||||
else
|
||||
message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,10 +39,10 @@ module Fog
|
|||
|
||||
raise BadRequest.new if body.nil? || body.empty?
|
||||
|
||||
# Round-trip +body+ through the JSON parser to turn Symbols into Strings, as though
|
||||
# it's coming back from the server.
|
||||
encoded = Fog::JSON.decode(Fog::JSON.encode(body))
|
||||
message = queue.add_message(client_id, encoded, ttl)
|
||||
# Ensure that any Symbol keys within +body+ are converted to Strings, just as being
|
||||
# round-tripped through the API will.
|
||||
converted = MockData.stringify(body)
|
||||
message = queue.add_message(client_id, converted, ttl)
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
|
|
Loading…
Add table
Reference in a new issue