Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

pre-routes should be ANY by default. Closes #33.

Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information...
commit 2867e6bded4ee29b7c74381f74d29fc8913cdbe4 1 parent 8c9d98c
@ibdknox ibdknox authored
Showing with 11 additions and 8 deletions.
  1. +6 −6 src/noir/core.clj
  2. +5 −2 test/noir/test/core.clj
View
12 src/noir/core.clj
@@ -29,12 +29,12 @@
[nil all])]
[{:fn-name fn-name} remaining]))
-(defn- parse-route [[{:keys [fn-name] :as result} [cur :as all]]]
+(defn- parse-route [[{:keys [fn-name] :as result} [cur :as all]] default-action]
(when-not (or (vector? cur) (string? cur))
(throwf "Routes must either be a string or vector, not a %s" (type cur)))
(let [[action url] (if (vector? cur)
[(keyword->symbol "compojure.core" (first cur)) (second cur)]
- ['compojure.core/GET cur])
+ [default-action cur])
final (-> result
(assoc :fn-name (if fn-name
fn-name
@@ -52,10 +52,10 @@
(defn ^{:skip-wiki true} parse-args
"parses the arguments to defpage. Returns a map containing the keys :name :action :url :destruct :body"
- [args]
+ [args & [default-action]]
(-> args
(parse-fn-name)
- (parse-route)
+ (parse-route (or default-action 'compojure.core/GET))
(parse-destruct-body)))
(defmacro defpage
@@ -122,7 +122,7 @@
[route & [params]]
(if (fn? route)
(route params)
- (let [[{fn-name :fn-name :as res}] (parse-route [{} [route]])
+ (let [[{fn-name :fn-name :as res}] (parse-route [{} [route]] 'compojure.core/GET)
func (get @route-funcs (keyword fn-name))]
(func params))))
@@ -135,7 +135,7 @@
(pre-route '/admin/*' {} (when-not (is-admin?) (redirect '/login')))"
[& args]
- (let [{:keys [action destruct url body]} (parse-args args)
+ (let [{:keys [action destruct url body]} (parse-args args 'compojure.core/ANY)
safe-url (if (vector? url)
(first url)
url)]
View
7 test/noir/test/core.clj
@@ -151,9 +151,12 @@
(compojure-route (ANY "/compojure" [] "compojure-route"))
(deftest pre-route-test
+ (-> (send-request [:post "/pre"])
+ (has-status 403)
+ (has-body "not allowed"))
(-> (send-request "/pre")
- (has-status 403)
- (has-body "not allowed")))
+ (has-status 403)
+ (has-body "not allowed")))
(deftest compojure-route-test
(-> (send-request "/compojure")

0 comments on commit 2867e6b

Please sign in to comment.
Something went wrong with that request. Please try again.