From 537969ff097f022a4f717110f7bc360c14978273 Mon Sep 17 00:00:00 2001 From: "Michael S. Klishin" Date: Sun, 30 Oct 2011 23:57:33 +0400 Subject: [PATCH] Tests/examples for the modifier --- test/monger/test/atomic_modifiers.clj | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/monger/test/atomic_modifiers.clj b/test/monger/test/atomic_modifiers.clj index 4a83bc9..743e824 100644 --- a/test/monger/test/atomic_modifiers.clj +++ b/test/monger/test/atomic_modifiers.clj @@ -89,3 +89,31 @@ (mgcol/insert coll { :_id oid :weight 10.0 }) (mgcol/update coll { :_id oid } { "$set" { :weight 20.5 :height 25.6 } }) (is (= { :_id oid :weight 20.5 :height 25.6 } (mgcol/find-map-by-id coll oid [:weight]))))) + + +;; +;; $unset +;; + +(deftest unset-a-single-existing-field-using-$unset-modifier + (let [coll "docs" + oid (ObjectId.)] + (mgcol/insert coll { :_id oid :title "Document 1" :published true }) + (mgcol/update coll { :_id oid } { "$unset" { :published 1 } }) + (is (= { :_id oid :title "Document 1" } (mgcol/find-map-by-id coll oid))))) + + +(deftest unset-multiple-existing-fields-using-$unset-modifier + (let [coll "docs" + oid (ObjectId.)] + (mgcol/insert coll { :_id oid :title "Document 1" :published true :featured true }) + (mgcol/update coll { :_id oid } { "$unset" { :published 1 :featured true } }) + (is (= { :_id oid :title "Document 1" } (mgcol/find-map-by-id coll oid))))) + + +(deftest unsetting-an-unexisting-field-using-$unset-modifier-is-not-considered-an-issue + (let [coll "docs" + oid (ObjectId.)] + (mgcol/insert coll { :_id oid :title "Document 1" :published true }) + (is (mgres/ok? (mgcol/update coll { :_id oid } { "$unset" { :published 1 :featured true } }))) + (is (= { :_id oid :title "Document 1" } (mgcol/find-map-by-id coll oid)))))