JSON.unparse is picky compared to to_json... go figure

This commit is contained in:
Chris Anderson 2008-05-24 13:17:44 -07:00
parent dc6c9276e5
commit b93f6e7677
3 changed files with 5 additions and 5 deletions

View file

@ -39,7 +39,7 @@ class CouchRest
class << self class << self
def put uri, doc = nil def put uri, doc = nil
payload = JSON.unparse doc if doc payload = doc.to_json if doc
JSON.parse(RestClient.put(uri, payload)) JSON.parse(RestClient.put(uri, payload))
end end
@ -48,7 +48,7 @@ class CouchRest
end end
def post uri, doc = nil def post uri, doc = nil
payload = JSON.unparse doc if doc payload = doc.to_json if doc
JSON.parse(RestClient.post(uri, payload)) JSON.parse(RestClient.post(uri, payload))
end end
@ -59,7 +59,7 @@ class CouchRest
def paramify_url url, params = nil def paramify_url url, params = nil
if params if params
query = params.collect do |k,v| query = params.collect do |k,v|
v = JSON.unparse(v) if %w{key startkey endkey}.include?(k.to_s) v = v.to_json if %w{key startkey endkey}.include?(k.to_s)
"#{k}=#{CGI.escape(v.to_s)}" "#{k}=#{CGI.escape(v.to_s)}"
end.join("&") end.join("&")
url = "#{url}?#{query}" url = "#{url}?#{query}"

View file

@ -15,7 +15,7 @@ class CouchRest
def temp_view funcs, params = nil def temp_view funcs, params = nil
url = CouchRest.paramify_url "#{@root}/_temp_view", params url = CouchRest.paramify_url "#{@root}/_temp_view", params
JSON.parse(RestClient.post(url, JSON.unparse(funcs), {"Content-Type" => 'application/json'})) JSON.parse(RestClient.post(url, funcs.to_json, {"Content-Type" => 'application/json'}))
end end
def view name, params = nil def view name, params = nil

View file

@ -22,7 +22,7 @@ describe CouchRest do
it "should be up to date" do it "should be up to date" do
v = @cr.info["version"] v = @cr.info["version"]
vi = v.split(/a/).pop.to_i vi = v.split(/a/).pop.to_i
vi.should be_between 658733, 659600 vi.should be_between(658733, 659864)
end end
end end