summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2014-05-19 11:33:30 +1000
committerCarlo Zancanaro <carlo@zancanaro.id.au>2014-05-19 11:33:30 +1000
commit5c84a05e68f003e8bb1c1d9c86fb1ad72d80951a (patch)
treee8d338a3a2b2f79aedf4384be2cd660817978c35
parent92ce6a23354422ba0a87d2d64548b83e0da8737b (diff)
Fix the tests
-rw-r--r--src/abra/core.clj4
-rw-r--r--test/abra/core_test.clj29
2 files changed, 18 insertions, 15 deletions
diff --git a/src/abra/core.clj b/src/abra/core.clj
index 19e4990..109b026 100644
--- a/src/abra/core.clj
+++ b/src/abra/core.clj
@@ -130,7 +130,9 @@
(let [spec (*lookup-route* [route arg-values])
{:keys [uri type args]} spec
root-path *root*
- prefix (if *request*
+ prefix (if (and *request*
+ (:scheme *request*)
+ (get-in *request* [:headers "host"]))
(str (name (:scheme *request*)) "://"
(get-in *request* [:headers "host"])))]
(if spec
diff --git a/test/abra/core_test.clj b/test/abra/core_test.clj
index 362a3d1..1207830 100644
--- a/test/abra/core_test.clj
+++ b/test/abra/core_test.clj
@@ -11,7 +11,8 @@
:uri uri
:remote-addr "127.0.0.1"
:server-port 8080
- :server-name "something"}
+ :server-name "something"
+ :headers {"host" "something:8080"}}
handler
:body))
@@ -29,7 +30,7 @@
(GET "/fail1" [] (url-for :user))
(GET "/fail2" [] (url-for :user 10 20)))
wrap-reverse-routing)]
- (is (= (make-request handler "/succeed") "/user/10"))
+ (is (= (make-request handler "/succeed") "http://something:8080/user/10"))
(is (nil? (make-request handler "/fail1")))
(is (nil? (make-request handler "/fail2")))))
@@ -66,9 +67,9 @@
(GET "/fail2" [] (url-for :edit-user))
(GET "/fail3" [] (url-for :edit-user 10 20)))
wrap-reverse-routing)]
- (is (= (make-request handler "/succeed1") "/user/"))
- (is (= (make-request handler "/succeed2") "/user/10/"))
- (is (= (make-request handler "/succeed3") "/user/10/edit"))
+ (is (= (make-request handler "/succeed1") "http://something:8080/user/"))
+ (is (= (make-request handler "/succeed2") "http://something:8080/user/10/"))
+ (is (= (make-request handler "/succeed3") "http://something:8080/user/10/edit"))
(is (nil? (make-request handler "/fail1")))
(is (nil? (make-request handler "/fail2")))
@@ -91,9 +92,9 @@
(GET "/fail2" [] (url-for :edit-user))
(GET "/fail3" [] (url-for :edit-user 10 20)))
wrap-reverse-routing)]
- (is (= (make-request handler "/succeed1") "/user/"))
- (is (= (make-request handler "/succeed2") "/user/10/"))
- (is (= (make-request handler "/succeed3") "/user/10/edit"))
+ (is (= (make-request handler "/succeed1") "http://something:8080/user/"))
+ (is (= (make-request handler "/succeed2") "http://something:8080/user/10/"))
+ (is (= (make-request handler "/succeed3") "http://something:8080/user/10/edit"))
(is (nil? (make-request handler "/fail1")))
(is (nil? (make-request handler "/fail2")))
@@ -108,12 +109,12 @@
(GET "/succeed" [] (url-for :user))
(GET "/fail" [] (url-for :user 10)))
wrap-reverse-routing)]
- (is (= (make-request handler "/succeed") "/user"))
+ (is (= (make-request handler "/succeed") "http://something:8080/user"))
(is (nil? (make-request handler "/fail")))
(var-set subroutes (register-route :user
(GET "/not-user" [] (str "user"))))
- (is (= (make-request handler "/succeed") "/not-user"))
+ (is (= (make-request handler "/succeed") "http://something:8080/not-user"))
(is (nil? (make-request handler "/fail"))))))
(deftest top-level-is-a-var
@@ -124,7 +125,7 @@
(GET "/fail1" [] (url-for :user))
(GET "/fail2" [] (url-for :user 10 20)))]
(let [handler (wrap-reverse-routing bare-handler)]
- (is (= (make-request handler "/succeed") "/user/10"))
+ (is (= (make-request handler "/succeed") "http://something:8080/user/10"))
(is (nil? (make-request handler "/fail1")))
(is (nil? (make-request handler "/fail2"))))))
@@ -139,7 +140,7 @@
(GET "/succeed" [] (url-for :get-object "user" 10))
(GET "/fail" [] (url-for :get-object nil 10)))
wrap-reverse-routing)]
- (is (= (make-request handler "/succeed"), "/user/10"))
+ (is (= (make-request handler "/succeed"), "http://something:8080/user/10"))
(is (nil? (make-request handler "/fail")))))
(deftest context-with-limited-options
@@ -154,7 +155,7 @@
(GET "/fail1" [] (url-for :get-object nil 10))
(GET "/fail2" [] (url-for :get-object "person" 10)))
wrap-reverse-routing)]
- (is (= (make-request handler "/succeed"), "/user/10"))
+ (is (= (make-request handler "/succeed"), "http://something:8080/user/10"))
(is (nil? (make-request handler "/fail1")))
(is (nil? (make-request handler "/fail2")))))
@@ -170,7 +171,7 @@
(GET "/fail2" [] (url-for :user 10 20)))
(add-middleware middleware)
wrap-reverse-routing)]
- (is (= (make-request handler "/succeed") "/user/10"))
+ (is (= (make-request handler "/succeed") "http://something:8080/user/10"))
(is (nil? (make-request handler "/fail1")))
(is (nil? (make-request handler "/fail2")))))