Apparently MongoDB returns "ok" as 1.0
This commit is contained in:
parent
a073d7ed20
commit
97f537d176
2 changed files with 19 additions and 8 deletions
|
|
@ -1,5 +1,5 @@
|
|||
(ns monger.errors
|
||||
(:import (com.mongodb DBObject WriteResult CommandResult)
|
||||
(:import (com.mongodb DBObject WriteResult)
|
||||
(clojure.lang IPersistentMap))
|
||||
(:require [monger convertion]))
|
||||
|
||||
|
|
@ -8,9 +8,17 @@
|
|||
;; API
|
||||
;;
|
||||
|
||||
(defn ^boolean ok?
|
||||
[^DBObject result]
|
||||
(.contains [true "true" 1] (.get result "ok")))
|
||||
(defprotocol MongoCommandResult
|
||||
(ok? [input] "Returns true if command result is a success"))
|
||||
|
||||
(extend-protocol MongoCommandResult
|
||||
DBObject
|
||||
(ok?
|
||||
[^DBObject result]
|
||||
(.contains [true "true" 1 1.0] (.get result "ok")))
|
||||
|
||||
WriteResult
|
||||
(ok?
|
||||
[^WriteResult result]
|
||||
(ok? (.getLastError result))))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,23 @@
|
|||
(ns monger.test.errors
|
||||
(:import (com.mongodb BasicDBObject))
|
||||
(:import (com.mongodb BasicDBObject WriteResult WriteConcern))
|
||||
(:require [monger core collection convertion])
|
||||
(:use [clojure.test]))
|
||||
|
||||
|
||||
;;
|
||||
;; ok?
|
||||
;; MongoCommandResult
|
||||
;;
|
||||
|
||||
|
||||
(deftest test-ok?
|
||||
(let [result-that-is-not-ok-1 (doto (BasicDBObject.) (.put "ok" 0))
|
||||
result-that-is-not-ok-2 (doto (BasicDBObject.) (.put "ok" "false"))
|
||||
result-that-is-ok-1 (doto (BasicDBObject.) (.put "ok" 1))
|
||||
result-that-is-ok-2 (doto (BasicDBObject.) (.put "ok" "true"))]
|
||||
result-that-is-ok-2 (doto (BasicDBObject.) (.put "ok" "true"))
|
||||
result-that-is-ok-3 (doto (BasicDBObject.) (.put "ok" 1.0))]
|
||||
(is (not (monger.errors/ok? result-that-is-not-ok-1)))
|
||||
(is (not (monger.errors/ok? result-that-is-not-ok-2)))
|
||||
(is (monger.errors/ok? result-that-is-ok-1))
|
||||
(is (monger.errors/ok? result-that-is-ok-2))))
|
||||
(is (monger.errors/ok? result-that-is-ok-2))
|
||||
(is (monger.errors/ok? result-that-is-ok-3))))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue