From c37f3aec8dadd125c3b7073f4327504764613585 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sun, 30 Sep 2018 23:26:15 +0200 Subject: [PATCH] fix spec problems --- src/formulare/core.clj | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/formulare/core.clj b/src/formulare/core.clj index 087b60a..7c1ea2e 100644 --- a/src/formulare/core.clj +++ b/src/formulare/core.clj @@ -9,14 +9,17 @@ (spec/def ::label string?) (spec/def ::required boolean?) -(spec/def ::spec keyword?) +(spec/def ::spec + (spec/or :registered-spec keyword? + :predicate ifn?)) (spec/def ::options (spec/or :empty empty? :options (spec/coll-of (spec/tuple string? string?)))) (spec/def ::widget #{:input :select :checkbox :textarea :mselect :hidden}) (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 ::field (spec/keys :req-un [::label] @@ -122,7 +125,8 @@ (str (hash [def values]))) (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) submitted-hash (get-in req [:params :__form-hash]) validate? (= form-hash submitted-hash)] @@ -141,7 +145,8 @@ (anti-forgery-field)))) (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]] (let [value (get-in req [:params id])] (assoc coll