 
     (it "should produce a handler returning valid response maps"
 
-      (let [handler (dispatcher/compile-dispatch-table simple-dispatch-table)
-            index-response (handler (mock/request :get "/foo"))
-            show-response  (handler (mock/request :get "/foo/1"))]
+      (let [handler (dispatcher/compile-dispatch-table
+                      (mapv (comp #(conj % rook/wrap-with-default-arg-resolvers) pop)
+                        simple-dispatch-table))
+            index-response  (handler (mock/request :get "/foo"))
+            show-response   (handler (mock/request :get "/foo/1"))
+            create-response (handler (merge (mock/request :post "/foo")
+                                       {:params {:x 123}}))]
         (should= {:status 200 :headers {} :body "Hello!"}
           index-response)
         (should= {:status 200 :headers {} :body "Interesting id: 1"}
-          show-response)))
+          show-response)
+        (should= {:status 200 :headers {} :body "Created 123"}
+          create-response)))
 
     (it "should inject the middleware"
 

(ns rook.dispatcher-spec
  (:use speclj.core)
  (:require [io.aviso.rook.dispatcher :as dispatcher]
            [ring.mock.request :as mock]))

(create-ns 'example.foo)



      (let [dt (set (dispatcher/unnest-dispatch-table
                      (dispatcher/namespace-dispatch-table
                        ["foo"] 'example.foo `*default-middleware*)))]
        (should= (set simple-dispatch-table) dt))))

  (describe "async handlers"

    (it "should return a channel with the correct response"

      (let [handler (namespace-handler
                      {:apply-middleware-fn dispatcher/apply-middleware-async}
                      [] 'barney `*default-middleware*)]
        (should= {:message "ribs!"}
          (-> (mock/request :get "/") handler async/<!! :body))))

    (it "should expose the request's :params key as an argument"
      (let [handler (namespace-handler
                      {:apply-middleware-fn dispatcher/apply-middleware-async}
                      [] 'echo-params rook/wrap-with-default-arg-resolvers)
            params {:foo :bar}]
        (should-be-same params
          (-> (mock/request :get "/")
            (assoc :params params)
            handler
            async/<!!
            :body
            :params-arg)))))

  (describe "loopback-handler"

    (it "should allow resources to collaborate"
      (let [handler (rook-async/async-handler->ring-handler
                      (rook-async/wrap-with-loopback
                        (dispatcher/compile-dispatch-table
                          {:apply-middleware-fn dispatcher/apply-middleware-async}
                          (into
                            (dispatcher/namespace-dispatch-table
                              ["fred"] 'fred rook/wrap-with-default-arg-resolvers)
                            (dispatcher/namespace-dispatch-table
                              ["barney"] 'barney rook/wrap-with-default-arg-resolvers)))))]
        (should= ":barney says `ribs!'"
          (-> (mock/request :get "/fred")
            handler
            :body
            :message))))

    (it "should send schema validation failures")

    (it "should return a 500 response if a sync handler throws an exception")))
