Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error production during coercion #4

Merged
merged 1 commit into from
Apr 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/constraint/validations/url.clj
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
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}]))))