ibdknox/noir — Issue #80: Validations on a model
Author: blakesmith
Created: 2012-02-07 03:37:44+00:00
State: open

Hello!

Coming from Rails land, I'm used to having validations happening at the model level, and I'm seeking to do something similar with Noir.

I have a validation on my model like so:

```clojure
(defn valid? [{:keys [title]}]
(vali/rule (vali/has-value? title)
[:title "You must have a title"]))
```

When I try to run (valid? {:title "Bill and Ted's Excellent Adventure"}), I get true, but running with title missing, I get:

Var noir.validation/*errors* is unbound.
[Thrown class java.lang.IllegalStateException]

I dug into the source a bit, and it seems like noir makes the assumption that validations can only happen inside the context of a request. Is there something conceptually I'm missing? If my database doesn't support data constraints, I run the risk of having bad data sneak in there if it's not coming from a form. Is it possible to re-use noir's validations outside the context of a web request?

Cheers, and thanks a ton for Noir!

Blake