fix spec problems

master
Josha von Gizycki 6 years ago
parent 9ba335341e
commit c37f3aec8d

@ -9,14 +9,17 @@
(spec/def ::label string?) (spec/def ::label string?)
(spec/def ::required boolean?) (spec/def ::required boolean?)
(spec/def ::spec keyword?) (spec/def ::spec
(spec/or :registered-spec keyword?
:predicate ifn?))
(spec/def ::options (spec/def ::options
(spec/or :empty empty? (spec/or :empty empty?
:options (spec/coll-of (spec/tuple string? string?)))) :options (spec/coll-of (spec/tuple string? string?))))
(spec/def ::widget (spec/def ::widget
#{:input :select :checkbox :textarea :mselect :hidden}) #{:input :select :checkbox :textarea :mselect :hidden})
(spec/def ::from-req (spec/def ::from-req
(spec/and fn? #(= 1 (->> % meta :arglists (map count) first)))) (spec/and ifn? ;;#(= 1 (->> % meta :arglists (map count) first))
))
(spec/def ::to-form ::from-req) (spec/def ::to-form ::from-req)
(spec/def ::field (spec/def ::field
(spec/keys :req-un [::label] (spec/keys :req-un [::label]
@ -122,7 +125,8 @@
(str (hash [def values]))) (str (hash [def values])))
(defn render-widgets [form-def values req] (defn render-widgets [form-def values req]
{:pre [(spec/valid? ::form form-def)]} (when-not (spec/valid? ::form form-def)
(throw (ex-info "Form def fails spec" (spec/explain-data ::form form-def))))
(let [form-hash (form-hash form-def values) (let [form-hash (form-hash form-def values)
submitted-hash (get-in req [:params :__form-hash]) submitted-hash (get-in req [:params :__form-hash])
validate? (= form-hash submitted-hash)] validate? (= form-hash submitted-hash)]
@ -141,7 +145,8 @@
(anti-forgery-field)))) (anti-forgery-field))))
(defn form-data [form-def req] (defn form-data [form-def req]
{:pre [(spec/valid? ::form form-def)]} (when-not (spec/valid? ::form form-def)
(throw (ex-info "Form def fails spec" (spec/explain-data ::form form-def))))
(reduce (fn [coll [id field]] (reduce (fn [coll [id field]]
(let [value (get-in req [:params id])] (let [value (get-in req [:params id])]
(assoc coll (assoc coll

Loading…
Cancel
Save