Skip to content

Commit

Permalink
Remove route-pair coercion from vhosts
Browse files Browse the repository at this point in the history
This breaks custom matchers, as mentioned in juxt#187.  This does not fix
 juxt#187 because RoutePair generally needs fixing, but this makes it
sufficiently optional for users.
  • Loading branch information
SevereOverfl0w committed Apr 24, 2019
1 parent 1ed0dbe commit 83fffe4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/bidi/vhosts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
(:require
[bidi.bidi :as bidi :refer :all :exclude [path-for]]
[bidi.ring :as br]
[bidi.schema :as bsc]
[schema.core :as s]
[schema.coerce :as sc]
[schema.utils :refer [error?]])
Expand All @@ -16,8 +15,8 @@
keyword? s/Keyword))

(s/defschema VHostWithRoutes
(s/constrained [(s/one [VHost] "Virtual host")
bsc/RoutePair] (comp not-empty first) "Must have at least one vhost"))
(s/constrained [(s/one [VHost] "Virtual host") s/Any]
(comp not-empty first) "Must have at least one vhost"))

(defn uri->host [^URI uri]
(cond-> (.getHost uri)
Expand Down
16 changes: 16 additions & 0 deletions test/bidi/vhosts_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[schema.core :as s]
[schema.utils :refer [error?]]
[bidi.vhosts :refer :all]
[bidi.bidi :as bidi]
[ring.mock.request :refer (request) :rename {request mock-request}]))

(def example-vhosts-model
Expand Down Expand Up @@ -185,3 +186,18 @@
"http://d.com:8002"
"https://example.org"]
(vhosts->roots (:vhosts example-vhosts-model) {:scheme :https :headers {"host" "example.org"}}))))

(defrecord ARecord []
bidi/Pattern)

(deftest record-survives-test
(let [routes [(->ARecord) :match]
vhost (vhosts-model [["https://example.com"] routes])]
(is (=
(-> vhost
:vhosts
;; The first (and only) pairing
first
;; The route structure
second)
routes))))

0 comments on commit 83fffe4

Please sign in to comment.