Make sure monger.collection/insert-and-return respects existing document id, just like save-and-return does

This commit is contained in:
Michael S. Klishin 2012-07-11 22:26:13 +04:00
parent 8bd2469465
commit 2a1e52fc1e
2 changed files with 8 additions and 1 deletions

View file

@ -97,7 +97,7 @@
;; and it does not work very well in our case, because that DBObject is short lived and produced ;; and it does not work very well in our case, because that DBObject is short lived and produced
;; from the Clojure map we are passing in. Plus, this approach is very awkward with immutable data ;; from the Clojure map we are passing in. Plus, this approach is very awkward with immutable data
;; structures being the default. MK. ;; structures being the default. MK.
(let [doc (merge document {:_id (ObjectId.)})] (let [doc (merge {:_id (ObjectId.)} document)]
(insert db collection doc concern) (insert db collection doc concern)
doc))) doc)))

View file

@ -129,6 +129,13 @@
(is (:_id result)) (is (:_id result))
(is (= 1 (mc/count collection))))) (is (= 1 (mc/count collection)))))
(deftest insert-and-return-with-a-provided-id
(let [collection "people"
oid (ObjectId.)
doc {:name "Joe" :age 30 :_id oid}
result (mc/insert-and-return :people doc)]
(is (= (:_id result) (:_id doc) oid))
(is (= 1 (mc/count collection)))))
;; ;;