Introduce monger.errors.ok?
This commit is contained in:
parent
a3aa236655
commit
a073d7ed20
2 changed files with 36 additions and 0 deletions
16
src/monger/errors.clj
Normal file
16
src/monger/errors.clj
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
(ns monger.errors
|
||||
(:import (com.mongodb DBObject WriteResult CommandResult)
|
||||
(clojure.lang IPersistentMap))
|
||||
(:require [monger convertion]))
|
||||
|
||||
|
||||
;;
|
||||
;; API
|
||||
;;
|
||||
|
||||
(defn ^boolean ok?
|
||||
[^DBObject result]
|
||||
(.contains [true "true" 1] (.get result "ok")))
|
||||
|
||||
|
||||
|
||||
20
test/monger/test/errors.clj
Normal file
20
test/monger/test/errors.clj
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(ns monger.test.errors
|
||||
(:import (com.mongodb BasicDBObject))
|
||||
(:require [monger core collection convertion])
|
||||
(:use [clojure.test]))
|
||||
|
||||
|
||||
;;
|
||||
;; ok?
|
||||
;;
|
||||
|
||||
(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"))]
|
||||
(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))))
|
||||
|
||||
Loading…
Reference in a new issue