Permalink
Browse files

more details example

  • Loading branch information...
1 parent 4ed6c43 commit 4d4da483c5d832217c4c5e8ca89eed5c80b3aff7 @logaan committed Oct 14, 2013
Showing with 29 additions and 6 deletions.
  1. +14 −3 README.md
  2. +15 −3 test/vlad/test/readme.clj
View
17 README.md
@@ -22,9 +22,20 @@ API Docs: <http://logaan.github.io/vlad/vlad.html>
(:require [vlad :refer :all]
[midje.sweet :refer [fact]]))
-(fact (validate (present [:age]) {:name "Logan"})
- => [{:type :vlad.validations/present
- :selector [:age]}])
+(let [data {:name "Logan Campbell"}
+ errors (validate (present [:age]) data)
+ named (assign-name errors {[:name] "Name" [:age] "Age"})
+ translated (translate-errors named english-translation)]
+
+ (fact
+ errors => [{:type :vlad.validations/present
+ :selector [:age]}]
+
+ named => [{:type :vlad.validations/present
+ :name "Age"
+ :selector [:age]}]
+
+ translated => {[:age] ["Age is required."]}))
```
## Composition
View
18 test/vlad/test/readme.clj
@@ -3,9 +3,21 @@
[midje.sweet :refer [fact]]))
; Basics
-(fact (validate (present [:age]) {:name "Logan Campbell"})
- => [{:type :vlad.validations/present
- :selector [:age]}])
+
+(let [data {:name "Logan Campbell"}
+ errors (validate (present [:age]) data)
+ named (assign-name errors {[:name] "Name" [:age] "Age"})
+ translated (translate-errors named english-translation)]
+
+ (fact
+ errors => [{:type :vlad.validations/present
+ :selector [:age]}]
+
+ named => [{:type :vlad.validations/present
+ :name "Age"
+ :selector [:age]}]
+
+ translated => {[:age] ["Age is required."]}))
; Composition
(def common

0 comments on commit 4d4da48

Please sign in to comment.