From d3fcf8d56122514c3dcbac004fcf105a4e899352 Mon Sep 17 00:00:00 2001 From: sostler Date: Wed, 10 Feb 2010 01:08:44 -0500 Subject: Added custom compojure tree --- compojure-3.2/test/compojure/validation_test.clj | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 compojure-3.2/test/compojure/validation_test.clj (limited to 'compojure-3.2/test/compojure/validation_test.clj') diff --git a/compojure-3.2/test/compojure/validation_test.clj b/compojure-3.2/test/compojure/validation_test.clj new file mode 100755 index 0000000..c203a81 --- /dev/null +++ b/compojure-3.2/test/compojure/validation_test.clj @@ -0,0 +1,37 @@ +(ns compojure.validation-test + (:use compojure.html.form-helpers + compojure.validation + clojure.contrib.test-is)) + +(deftest passes-validate + (is (= (validate {:a 1} :a (constantly true) "fail") + {}))) + +(deftest fails-validate + (is (= (validate {:a 1} :a (constantly false) "fail") + {:a ["fail"]}))) + +(deftest error-class-errors + (binding [*errors* {:foo "bar"}] + (is (= ((error-class text-field) :foo) + [:div.error (text-field :foo)])))) + +(deftest error-class-no-errors + (binding [*errors* {}] + (is (= ((error-class text-field) :foo) + (text-field :foo))))) + +(deftest merge-errors-test + (are (= (apply merge-errors _1) _2) + [{}] {} + [{} {} {}] {} + [{:a ["f"]}] {:a ["f"]} + [{:a ["f"]} {:b ["g"]}] {:a ["f"], :b ["g"]} + [{:a ["f"]} {:a ["g"]}] {:a ["f" "g"]})) + +(deftest validation-test + (let [params {:a 1, :b 2} + pred #(= % 2) + mesg "isn't 2"] + (is (= (validation params [:a pred mesg] [:b pred mesg]) + {:a ["isn't 2"]})))) -- cgit v1.2.3-70-g09d2