Permalink
Browse files

add cljs views tests

  • Loading branch information...
1 parent cde3bc1 commit 4c6bd1ee1e1a7e23098a3ad42a42003bdc443d05 @cemerick cemerick committed May 6, 2012
Showing with 41 additions and 0 deletions.
  1. +41 −0 test/clutch/test/views.clj
View
41 test/clutch/test/views.clj
@@ -0,0 +1,41 @@
+(ns clutch.test.views
+ (:use clojure.test
+ com.ashafa.clutch
+ [test-clutch :only (defdbtest test-database-name test-database-url *test-database*)])
+ (:refer-clojure :exclude (conj! assoc! dissoc!)))
+
+(defdbtest cljs-simple
+ (bulk-update [{:_id "x" :count 2}
+ {:_id "y" :count 3}])
+ (save-view "cljs-views"
+ (view-server-fns :cljs
+ {:enumeration {:map #(dotimes [x (aget % "count")]
+ (js/emit (js/Array (aget % "_id") x) (inc x)))}}))
+ (is (= '#{{:id x, :key [x 0], :value 1}
+ {:id x, :key [x 1], :value 2}
+ {:id y, :key [y 0], :value 1}
+ {:id y, :key [y 1], :value 2}
+ {:id y, :key [y 2], :value 3}})
+ (get-view "cljs-views" :enumeration)))
+
+(defdbtest cljs-inline-namespace
+ (bulk-update [{:_id "x" :count 2}
+ {:_id "y" :count 3}])
+ (save-view "namespaced-cljs-views"
+ (view-server-fns {:language :cljs
+ :main 'inline.namespace.couchview/main}
+ {:enumeration {:map [(ns inline.namespace.couchview)
+ (defn view-key
+ [doc x]
+ (js/Array (aget doc "_id") x))
+ (defn ^:export main
+ [doc]
+ (dotimes [x (aget % "count")]
+ (js/emit (view-key doc x) (inc x))))]}}))
+ (is (= '#{{:id x, :key [x 0], :value 1}
+ {:id x, :key [x 1], :value 2}
+ {:id y, :key [y 0], :value 1}
+ {:id y, :key [y 1], :value 2}
+ {:id y, :key [y 2], :value 3}})
+ (get-view "namespaced-cljs-views" :enumeration)))
+

0 comments on commit 4c6bd1e

Please sign in to comment.