Skip to content

Commit

Permalink
Merge pull request #4 from listora/test-validation-coercion
Browse files Browse the repository at this point in the history
Fix error production during coercion
  • Loading branch information
James Conroy-Finn committed Apr 15, 2014
2 parents 9369301 + dda2e4a commit 7bc0e98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/constraint/validations/url.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
(defn- string->url [schemes value]
(if (valid? schemes value)
{:value (URL. value)}
{:errors (set (invalid-url schemes value))}))
{:errors #{(invalid-url schemes value)}}))

(defn url-coercions
"Defines coercion from a java.lang.String to a java.net.URL given the allowed
Expand Down
15 changes: 11 additions & 4 deletions test/constraint/validations/url_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@
:found domain-only}]))))

(deftest test-coercions
(let [url (URL. "http://example.com")
coercions (url-coercions ["http"])]
(is (valid? URL (str url) coercions))
(is (= (coerce URL (str url) coercions) url))))
(let [schemes ["http" "https"]
validator (url schemes)
example-url (URL. "http://example.com")
coercions (url-coercions schemes)]
(is (valid? URL (str example-url) coercions))
(is (= (coerce URL (str example-url) coercions) example-url))

(is (= (validate (url schemes) domain-only)
[{:error :invalid-url
:message "Expected URL with scheme \"http\", or \"https\""
:found domain-only}]))))

0 comments on commit 7bc0e98

Please sign in to comment.