monger.convertion => monger.conversion
This commit is contained in:
parent
30ed15e67f
commit
6d12e34465
8 changed files with 33 additions and 34 deletions
|
|
@ -11,7 +11,7 @@
|
|||
(:refer-clojure :exclude [find remove count drop])
|
||||
(:import (com.mongodb Mongo DB DBCollection WriteResult DBObject WriteConcern DBCursor) (java.util List Map) (clojure.lang IPersistentMap ISeq))
|
||||
(:require [monger core result])
|
||||
(:use [monger.convertion]))
|
||||
(:use [monger.conversion]))
|
||||
|
||||
;;
|
||||
;; API
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
;; THE SOFTWARE.
|
||||
|
||||
(ns monger.convertion
|
||||
(ns monger.conversion
|
||||
(:import (com.mongodb DBObject BasicDBObject BasicDBList DBCursor)
|
||||
(clojure.lang IPersistentMap Keyword)
|
||||
(java.util List Map)))
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
is in the monger.collection namespace."}
|
||||
monger.core
|
||||
(:refer-clojure :exclude [count])
|
||||
(:use [monger.convertion])
|
||||
(:use [monger.conversion])
|
||||
(:import (com.mongodb Mongo DB WriteConcern DBObject DBCursor)
|
||||
(java.util Map)))
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
(ns monger.result
|
||||
(:import (com.mongodb DBObject WriteResult)
|
||||
(clojure.lang IPersistentMap))
|
||||
(:require [monger convertion]))
|
||||
(:require [monger conversion]))
|
||||
|
||||
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
(ns monger.test.collection
|
||||
(:import [com.mongodb WriteResult WriteConcern DBCursor DBObject CommandResult$CommandFailure]
|
||||
[java.util Date])
|
||||
(:require [monger core collection result util convertion]
|
||||
(:require [monger core collection result util conversion]
|
||||
[clojure stacktrace])
|
||||
(:use [clojure.test]))
|
||||
|
||||
|
|
@ -59,8 +59,8 @@
|
|||
|
||||
(deftest insert-a-basic-db-object-without-id-and-with-default-write-concern
|
||||
(let [collection "people"
|
||||
doc (monger.convertion/to-db-object { :name "Joe", :age 30 })]
|
||||
(is (nil? (monger.util/get-id doc)))
|
||||
doc (monger.conversion/to-db-object { :name "Joe", :age 30 })]
|
||||
(is (nil? (.get ^DBObject doc "_id")))
|
||||
(monger.collection/insert "people" doc)
|
||||
(is (not (nil? (monger.util/get-id doc))))))
|
||||
|
||||
|
|
@ -155,8 +155,8 @@
|
|||
(monger.collection/insert collection doc)
|
||||
(def #^DBObject found-one (monger.collection/find-one collection { :language "Clojure" }))
|
||||
(is (= (:_id doc) (monger.util/get-id found-one)))
|
||||
(is (= (monger.convertion/from-db-object found-one true) doc))
|
||||
(is (= (monger.convertion/to-db-object doc) found-one))))
|
||||
(is (= (monger.conversion/from-db-object found-one true) doc))
|
||||
(is (= (monger.conversion/to-db-object doc) found-one))))
|
||||
|
||||
|
||||
(deftest find-one-full-document-as-map-when-collection-has-matches
|
||||
|
|
@ -283,7 +283,7 @@
|
|||
(is (= 1 (.count scala-libs)))
|
||||
(is (= 3 (.count clojure-libs)))
|
||||
(doseq [i clojure-libs]
|
||||
(let [doc (monger.convertion/from-db-object i true)]
|
||||
(let [doc (monger.conversion/from-db-object i true)]
|
||||
(is (= (:language doc) "Clojure"))))
|
||||
(is (empty? (monger.collection/find collection { :language "Erlang" } [:name]))))))
|
||||
|
||||
|
|
@ -328,7 +328,7 @@
|
|||
|
||||
(deftest save-a-new-basic-db-object
|
||||
(let [collection "people"
|
||||
doc (monger.convertion/to-db-object { :name "Joe", :age 30 })]
|
||||
doc (monger.conversion/to-db-object { :name "Joe", :age 30 })]
|
||||
(is (nil? (monger.util/get-id doc)))
|
||||
(monger.collection/save "people" doc)
|
||||
(is (not (nil? (monger.util/get-id doc))))))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
(ns monger.test.convertion
|
||||
(:require [monger core collection convertion])
|
||||
(ns monger.test.conversion
|
||||
(:require [monger core collection conversion])
|
||||
(:import (com.mongodb DBObject BasicDBObject BasicDBList) (java.util List ArrayList))
|
||||
(:use [clojure.test]))
|
||||
|
||||
|
|
@ -10,28 +10,28 @@
|
|||
|
||||
(deftest convert-nil-to-dbobject
|
||||
(let [input nil
|
||||
output (monger.convertion/to-db-object input)]
|
||||
output (monger.conversion/to-db-object input)]
|
||||
(is (nil? output))))
|
||||
|
||||
(deftest convert-integer-to-dbobject
|
||||
(let [input 1
|
||||
output (monger.convertion/to-db-object input)]
|
||||
output (monger.conversion/to-db-object input)]
|
||||
(is (= input output))))
|
||||
|
||||
(deftest convert-float-to-dbobject
|
||||
(let [input 11.12
|
||||
output (monger.convertion/to-db-object input)]
|
||||
output (monger.conversion/to-db-object input)]
|
||||
(is (= input output))))
|
||||
|
||||
(deftest convert-string-to-dbobject
|
||||
(let [input "MongoDB"
|
||||
output (monger.convertion/to-db-object input)]
|
||||
output (monger.conversion/to-db-object input)]
|
||||
(is (= input output))))
|
||||
|
||||
|
||||
(deftest convert-map-to-dbobject
|
||||
(let [input { :int 1, :string "Mongo", :float 22.23 }
|
||||
output #^DBObject (monger.convertion/to-db-object input)]
|
||||
output #^DBObject (monger.conversion/to-db-object input)]
|
||||
(is (= 1 (.get output "int")))
|
||||
(is (= "Mongo" (.get output "string")))
|
||||
(is (= 22.23 (.get output "float")))))
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
(deftest convert-nested-map-to-dbobject
|
||||
(let [input { :int 1, :string "Mongo", :float 22.23, :map { :int 10, :string "Clojure", :float 11.9, :list '(1 "a" :b), :map { :key "value" } } }
|
||||
output #^DBObject (monger.convertion/to-db-object input)
|
||||
output #^DBObject (monger.conversion/to-db-object input)
|
||||
inner #^DBObject (.get output "map")]
|
||||
(is (= 10 (.get inner "int")))
|
||||
(is (= "Clojure" (.get inner "string")))
|
||||
|
|
@ -51,7 +51,7 @@
|
|||
;; to obtain _id that was generated. MK.
|
||||
(deftest convert-dbobject-to-dbobject
|
||||
(let [input (BasicDBObject.)
|
||||
output (monger.convertion/to-db-object input)]
|
||||
output (monger.conversion/to-db-object input)]
|
||||
(is (= input output))))
|
||||
|
||||
|
||||
|
|
@ -62,16 +62,16 @@
|
|||
;;
|
||||
|
||||
(deftest convert-nil-from-db-object
|
||||
(is (nil? (monger.convertion/from-db-object nil false)))
|
||||
(is (nil? (monger.convertion/from-db-object nil true))))
|
||||
(is (nil? (monger.conversion/from-db-object nil false)))
|
||||
(is (nil? (monger.conversion/from-db-object nil true))))
|
||||
|
||||
(deftest convert-integer-from-dbobject
|
||||
(is (= 2 (monger.convertion/from-db-object 2 false)))
|
||||
(is (= 2 (monger.convertion/from-db-object 2 true))))
|
||||
(is (= 2 (monger.conversion/from-db-object 2 false)))
|
||||
(is (= 2 (monger.conversion/from-db-object 2 true))))
|
||||
|
||||
(deftest convert-float-from-dbobject
|
||||
(is (= 3.3 (monger.convertion/from-db-object 3.3 false)))
|
||||
(is (= 3.3 (monger.convertion/from-db-object 3.3 true))))
|
||||
(is (= 3.3 (monger.conversion/from-db-object 3.3 false)))
|
||||
(is (= 3.3 (monger.conversion/from-db-object 3.3 true))))
|
||||
|
||||
(deftest convert-flat-db-object-to-map-without-keywordizing
|
||||
(let [name "Michael"
|
||||
|
|
@ -79,7 +79,7 @@
|
|||
input (doto (BasicDBObject.)
|
||||
(.put "name" name)
|
||||
(.put "age" age))
|
||||
output (monger.convertion/from-db-object input false)]
|
||||
output (monger.conversion/from-db-object input false)]
|
||||
(is (= (output { "name" name, "age" age })))
|
||||
(is (= (output "name") name))
|
||||
(is (nil? (output :name)))
|
||||
|
|
@ -93,7 +93,7 @@
|
|||
input (doto (BasicDBObject.)
|
||||
(.put "name" name)
|
||||
(.put "age" age))
|
||||
output (monger.convertion/from-db-object input true)]
|
||||
output (monger.conversion/from-db-object input true)]
|
||||
(is (= (output { :name name, :age age })))
|
||||
(is (= (output :name) name))
|
||||
(is (nil? (output "name")))
|
||||
|
|
@ -112,7 +112,7 @@
|
|||
input (doto (BasicDBObject.)
|
||||
(.put "_id" did)
|
||||
(.put "nested" nested))
|
||||
output (monger.convertion/from-db-object input false)]
|
||||
output (monger.conversion/from-db-object input false)]
|
||||
(is (= (output "_id") did))
|
||||
(is (= (-> output (get "nested") (get "int")) 101))
|
||||
(is (= (-> output (get "nested") (get "list")) ["red" "green" "blue"]))
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
(ns monger.test.result
|
||||
(:import (com.mongodb BasicDBObject WriteResult WriteConcern) (java.util Date))
|
||||
(:require [monger core collection convertion])
|
||||
(:require [monger core collection conversion])
|
||||
(:use [clojure.test]))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
(ns monger.test.util
|
||||
(:import (com.mongodb DBObject))
|
||||
(:require [monger util convertion])
|
||||
(:require [monger util conversion])
|
||||
(:use [clojure.test]))
|
||||
|
||||
|
||||
(deftest get-object-id
|
||||
(let [id #^ObjectId (monger.util/object-id)
|
||||
input #^DBObject (monger.convertion/to-db-object { :_id id })
|
||||
(let [id ^ObjectId (monger.util/object-id)
|
||||
input ^DBObject (monger.conversion/to-db-object { :_id id })
|
||||
output (monger.util/get-id input)]
|
||||
|
||||
(is (not (nil? output)))))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue