diff --git a/ChangeLog.md b/ChangeLog.md index 7afa757..ac8c9ed 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,8 @@ ## Changes between 1.0.0-beta8 and 1.0.0-rc1 -No changes yet. +### monger.result/ok? now works on Clojure maps + +`monger.result/ok?` has been implemented for Clojure maps. diff --git a/project.clj b/project.clj index 6d594d8..494fb16 100644 --- a/project.clj +++ b/project.clj @@ -13,7 +13,8 @@ :indexing :indexing :external :external :cache :cache - :gridfs :gridfs + :gridfs :gridfs + :command :command :performance :performance ;; as in, edge mongodb server :edge-features :edge-features diff --git a/src/monger/result.clj b/src/monger/result.clj index 079df68..ddcc874 100644 --- a/src/monger/result.clj +++ b/src/monger/result.clj @@ -8,10 +8,20 @@ ;; You must not remove this notice, or any other, from this software. (ns monger.result - (:import [com.mongodb DBObject WriteResult MapReduceOutput]) + (:import [com.mongodb DBObject WriteResult MapReduceOutput] + clojure.lang.IPersistentMap) (:require monger.conversion)) +;; +;; Implementation +;; + +(defn- okayish? + [value] + (contains? #{true "true" 1 1.0} value)) + + ;; ;; API ;; @@ -25,7 +35,7 @@ DBObject (ok? [^DBObject result] - (.contains [true "true" 1 1.0] (.get result "ok"))) + (okayish? (.get result "ok"))) (has-error? [^DBObject result] ;; yes, this is exactly the logic MongoDB Java driver uses. @@ -50,4 +60,10 @@ MapReduceOutput (ok? [^MapReduceOutput result] - (ok? ^DBObject (.getRaw result)))) + (ok? ^DBObject (.getRaw result))) + + IPersistentMap + (ok? + [^IPersistentMap m] + (okayish? (or (get m :ok) + (get m "ok"))))) diff --git a/test/monger/test/command_test.clj b/test/monger/test/command_test.clj index 6eb8b03..3c21e85 100644 --- a/test/monger/test/command_test.clj +++ b/test/monger/test/command_test.clj @@ -1,19 +1,21 @@ (ns monger.test.command-test - (:require [monger.command :as mcom] + (:require [monger.core :as mg] + [monger.command :as mcom] [monger.test.helper :as helper] [monger.collection :as mc]) (:use clojure.test - monger.result)) + [monger.result :only [ok?]] + [monger.conversion :only [from-db-object]])) (helper/connect!) -(deftest test-db-stats +(deftest ^{:command true} test-db-stats (let [stats (mcom/db-stats)] (is (ok? stats)) (is (= "monger-test" (get stats "db"))))) -(deftest test-collection-stats +(deftest ^{:command true} test-collection-stats (let [collection "stat_test" _ (mc/insert collection {:name "Clojure"}) check (mc/count collection) @@ -22,20 +24,27 @@ (is (= "monger-test.stat_test" (get stats "ns"))) (is (= check (get stats "count"))))) -(deftest test-reindex-collection +(deftest ^{:command true} test-reindex-collection (let [_ (mc/insert "test" {:name "Clojure"}) result (mcom/reindex-collection "test")] (is (ok? result)) (is (get result "indexes")))) -(deftest test-server-status +(deftest ^{:command true} test-server-status (let [status (mcom/server-status)] (is (ok? status)) (is (not-empty status)) (is (get status "serverUsed")))) -(deftest test-top +(deftest ^{:command true} test-top (let [result (mcom/top)] (is (ok? result)) (is (not-empty result)) (is (get result "serverUsed")))) + +(deftest ^{:command true} test-running-is-master-as-an-arbitrary-command + (let [raw (mg/command {:isMaster 1}) + result (from-db-object raw true)] + (is (ok? result)) + (is (ok? raw)) + (is (:ismaster result))))