     :visits (sut/new-visits))
    {:visits {:db :db}}))
 
+(defn include-handler [f]
+  (let [visits (:visits cts/*system*)
+        handler (make-handler (vhosts-model [:* (sut/visit-routes visits)]))]
+    (binding [*handler* handler]
+      (f))))
+
 (t/use-fixtures :once schema.test/validate-schemas)
 (t/use-fixtures :each
   (cts/with-system-fixture test-system)
-  (cts/with-transaction-fixture [:visits :db :spec]))
+  (cts/with-transaction-fixture [:visits :db :spec])
+  include-handler)
 
 (s/def example-visit :- m/Visit
   "Minimally-defined visit for our testing purposes"


(deftest create-visits-valid-data
  (testing "POST /visits (valid data)"
    (let [visits (:visits cts/*system*)
          handler (make-handler (vhosts-model [:* (sut/visit-routes visits)]))
          data example-visit
          request (mock/json-body (mock/request :post "/visits") data)
          response @(handler request)]
      (is (= 201 (:status response)))
      (is (contains? (:headers response) "location"))
      (is (not (nil? (re-matches #"/visits/(\d+)"


(deftest create-visits-invalid-data
  (testing "POST /visits (invalid data)"
    (let [request (mock/json-body (mock/request :post "/visits") {})
          response @(*handler* request)]
      (is (= 400 (:status response))))))

(deftest list-visits-no-entries-yet
  (testing "GET /visits (no entries yet)"
    (let [request (mock/json-body (mock/request :get "/visits") {})
          response @(*handler* request)]
      (is (= 200 (:status response)))
      (is (= {:data []} (parse-string (bs/to-string (:body response)) keyword))))))

(deftest list-visits-entries-exist
  (testing "Get /visits (a couple of entries)"
    (let [numtimes 2
          _ (dotimes [_ numtimes]
              @(*handler* (mock/json-body (mock/request :post "/visits") example-visit)))
          list-request (mock/request :get "/visits")
          list-response @(*handler* list-request)
          list-body (:data (parse-string (bs/to-string (:body list-response)) keyword))]
      (is (= 200 (:status list-response)))
      (is (= numtimes (count list-body)))
