Permalink
Browse files

Support for ring keyword-params

  • Loading branch information...
1 parent b78ba75 commit f6e332ea9c3a3d383ea24cb73cdb3f817cacbc6e @alienscience committed Apr 21, 2011
Showing with 27 additions and 7 deletions.
  1. +8 −3 TODO
  2. +3 −2 src/form_dot_clj/core.clj
  3. +16 −2 test/form_dot_clj/test/core.clj
View
@@ -1,4 +1,9 @@
-1) Generate .js from datastructures
-2) Move to :require
-3) Have :dest-html, :dest-js protection
+
+1. Look at jquery validation (or some other library)
+3. Separate out js-dot-clj
+4. See if there is a better way to do date input
+ [:date "d mmm yyyy" "1900-01-01" "2010-8-10"
+ "Must be a date betweenn xxx and xxx"
+5. Have separate example app??
+
@@ -88,7 +88,8 @@
[value-map error-map control-tuple params]
(let [control-key (first control-tuple)
control (second control-tuple)
- param (-> control :name params)
+ control-name (control :name)
+ param (or (params control-name) (params control-key))
required (control :required)]
(if (or (nil? param)
(= (.length param) 0))
@@ -114,7 +115,7 @@
(let [[new-values new-errors]
(check-control value-map error-map (first todo) params)]
(recur new-values new-errors (rest todo))))))
-
+
(defn validate
"Checks the values posted to the given controls.
Returns a two entry vector containing a map of validated values
@@ -41,12 +41,25 @@
:url-value-field (textbox for-url)
)
+(defn- keyword-keys
+ "Converts a map to have keyword keys"
+ [m]
+ (into {}
+ (map (fn [[a b]]
+ [(keyword a) b])
+ m)))
+
(defn has-value
"Checks that the given param map converts to the given value
map"
[params expected-values]
- (let [[validated errors] (validate test-form params)]
- (is (= validated expected-values) "Expected values")))
+ (let [kw-params (keyword-keys params)
+ [validated errors] (validate test-form params)
+ [kw-validated kw-errors] (validate test-form kw-params)]
+ (is (= validated expected-values) "Expected values (string keys)")
+ (is (= kw-validated expected-values) "Expected values (keyword keys")
+ (is (empty? errors))
+ (is (empty? kw-errors))))
(deftest conversion
(has-value {"string-field" "moot"}
@@ -64,6 +77,7 @@
(has-value {"bool-field" "false"} {:bool-field false})
(has-value {"bool-field" "FALSE"} {:bool-field false}))
+
(def *all-ascii* (str/map-str char (range 1 128)))
(deftest xss

0 comments on commit f6e332e

Please sign in to comment.