Skip to content
This repository
Browse code

add cljs views tests

  • Loading branch information...
commit 4c6bd1ee1e1a7e23098a3ad42a42003bdc443d05 1 parent cde3bc1
Chas Emerick cemerick authored

Showing 1 changed file with 41 additions and 0 deletions. Show diff stats Hide diff stats

  1. +41 0 test/clutch/test/views.clj
41 test/clutch/test/views.clj
... ... @@ -0,0 +1,41 @@
  1 +(ns clutch.test.views
  2 + (:use clojure.test
  3 + com.ashafa.clutch
  4 + [test-clutch :only (defdbtest test-database-name test-database-url *test-database*)])
  5 + (:refer-clojure :exclude (conj! assoc! dissoc!)))
  6 +
  7 +(defdbtest cljs-simple
  8 + (bulk-update [{:_id "x" :count 2}
  9 + {:_id "y" :count 3}])
  10 + (save-view "cljs-views"
  11 + (view-server-fns :cljs
  12 + {:enumeration {:map #(dotimes [x (aget % "count")]
  13 + (js/emit (js/Array (aget % "_id") x) (inc x)))}}))
  14 + (is (= '#{{:id x, :key [x 0], :value 1}
  15 + {:id x, :key [x 1], :value 2}
  16 + {:id y, :key [y 0], :value 1}
  17 + {:id y, :key [y 1], :value 2}
  18 + {:id y, :key [y 2], :value 3}})
  19 + (get-view "cljs-views" :enumeration)))
  20 +
  21 +(defdbtest cljs-inline-namespace
  22 + (bulk-update [{:_id "x" :count 2}
  23 + {:_id "y" :count 3}])
  24 + (save-view "namespaced-cljs-views"
  25 + (view-server-fns {:language :cljs
  26 + :main 'inline.namespace.couchview/main}
  27 + {:enumeration {:map [(ns inline.namespace.couchview)
  28 + (defn view-key
  29 + [doc x]
  30 + (js/Array (aget doc "_id") x))
  31 + (defn ^:export main
  32 + [doc]
  33 + (dotimes [x (aget % "count")]
  34 + (js/emit (view-key doc x) (inc x))))]}}))
  35 + (is (= '#{{:id x, :key [x 0], :value 1}
  36 + {:id x, :key [x 1], :value 2}
  37 + {:id y, :key [y 0], :value 1}
  38 + {:id y, :key [y 1], :value 2}
  39 + {:id y, :key [y 2], :value 3}})
  40 + (get-view "namespaced-cljs-views" :enumeration)))
  41 +

0 comments on commit 4c6bd1e

Please sign in to comment.
Something went wrong with that request. Please try again.