From a7264122e3eb54460846ae771b91b3af6cde987e Mon Sep 17 00:00:00 2001 From: "Michael S. Klishin" Date: Tue, 11 Oct 2011 21:04:21 +0400 Subject: [PATCH] Use clojure.test/are and namespace aliases --- test/monger/test/collection.clj | 55 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/test/monger/test/collection.clj b/test/monger/test/collection.clj index 205a90d..3dea112 100644 --- a/test/monger/test/collection.clj +++ b/test/monger/test/collection.clj @@ -333,43 +333,40 @@ ;; more sophisticated examples (deftest find-with-conditional-operators-comparison (let [collection "libraries"] - (monger.collection/insert-batch collection [{ :language "Clojure", :name "monger" :users 1} - { :language "Clojure", :name "langohr" :users 5 } - { :language "Clojure", :name "incanter" :users 15 } - { :language "Scala", :name "akka" :users 150}]) - - (is (= 2 (.count (monger.collection/find collection { :users { "$gt" 10 }})))) - (is (= 3 (.count (monger.collection/find collection { :users { "$gte" 5 }})))) - (is (= 2 (.count (monger.collection/find collection { :users { "$lt" 10 }})))) - (is (= 2 (.count (monger.collection/find collection { :users { "$lte" 5 }})))) - (is (= 1 (.count (monger.collection/find collection { :users { "$gt" 10 "$lt" 150 }})))) - - )) + (mgcol/insert-batch collection [{ :language "Clojure", :name "monger" :users 1} + { :language "Clojure", :name "langohr" :users 5 } + { :language "Clojure", :name "incanter" :users 15 } + { :language "Scala", :name "akka" :users 150}]) + (are [a b] (= a (.count (mgcol/find collection b))) + 2 { :users { "$gt" 10 }} + 3 { :users { "$gte" 5 }} + 2 { :users { "$lt" 10 }} + 2 { :users { "$lte" 5 }} + 1 { :users { "$gt" 10 "$lt" 150 }}))) (deftest find-on-embedded-arrays (let [collection "libraries"] - (monger.collection/insert-batch collection [{ :language "Clojure", :tags [ "functional" ] } - { :language "Scala", :tags [ "functional" "object-oriented" ] } - { :language "Ruby", :tags [ "object-oriented" "dynamic" ] }]) + (mgcol/insert-batch collection [{ :language "Clojure", :tags [ "functional" ] } + { :language "Scala", :tags [ "functional" "object-oriented" ] } + { :language "Ruby", :tags [ "object-oriented" "dynamic" ] }]) - (is (= "Scala" (:language (first (monger.collection/find-maps collection { :tags { "$all" [ "functional" "object-oriented" ] } } ))))) - (is (= 3 (.count (monger.collection/find-maps collection { :tags { "$in" [ "functional" "object-oriented" ] } } )))))) + (is (= "Scala" (:language (first (mgcol/find-maps collection { :tags { "$all" [ "functional" "object-oriented" ] } } ))))) + (is (= 3 (.count (mgcol/find-maps collection { :tags { "$in" [ "functional" "object-oriented" ] } } )))))) (deftest find-with-conditional-operators-on-embedded-documents (let [collection "people"] - (monger.collection/insert-batch collection [{ :name "Bob", :comments [ { :text "Nice!" :rating 1 } - { :text "Love it" :rating 4 } - { :text "What?":rating -5 } ] } - { :name "Alice", :comments [ { :text "Yeah" :rating 2 } - { :text "Doh" :rating 1 } - { :text "Agreed" :rating 3 } - ] } ]) - - (is (= 1 (.count (monger.collection/find collection { :comments { "$elemMatch" { :text "Nice!" :rating { "$gte" 1 } } } })))) - - (is (= 2 (.count (monger.collection/find collection { "comments.rating" 1 } )))) - (is (= 1 (.count (monger.collection/find collection { "comments.rating" { "$gt" 3 } })))))) + (mgcol/insert-batch collection [{ :name "Bob", :comments [ { :text "Nice!" :rating 1 } + { :text "Love it" :rating 4 } + { :text "What?":rating -5 } ] } + { :name "Alice", :comments [ { :text "Yeah" :rating 2 } + { :text "Doh" :rating 1 } + { :text "Agreed" :rating 3 } + ] } ]) + (are [a b] (= a (.count (mgcol/find collection b))) + 1 { :comments { "$elemMatch" { :text "Nice!" :rating { "$gte" 1 } } } } + 2 { "comments.rating" 1 } + 1 { "comments.rating" { "$gt" 3 } }))) ;; ;; update, save