diff --git a/src/monger/errors.clj b/src/monger/errors.clj new file mode 100644 index 0000000..5a8f104 --- /dev/null +++ b/src/monger/errors.clj @@ -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"))) + + + diff --git a/test/monger/test/errors.clj b/test/monger/test/errors.clj new file mode 100644 index 0000000..866cf16 --- /dev/null +++ b/test/monger/test/errors.clj @@ -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)))) +