                                                   {:Accept (mime-type :item)}})]
           (:status response) => 404
           (body? response) => false)
+        (collection/item-count e) => 0))
+    
+    ;; no charset - 201 Created
+    ;; curl -i --header "Accept: application/vnd.fcms.item+json;version=1" --header "Content-Type: application/vnd.fcms.item+json;version=1" -X POST -d '{"name":"i"}' http://localhost:3000/c/
+    (fact "create an item without an Accept-Charset header"
+      (let [response (create-item-with-api {:name i})]
+        (:status response) => 201
+        (response-mime-type response) => (mime-type :item)
+        (response-location response) => "/e/i"
+        (json? response) => true
+        ;; Get the created item and make sure it's right
+        (item/get-item e i) => (contains
+                                 {:collection e
+                                   :name i
+                                   :slug i
+                                   :version 1})        
+        (let [response (api-request :get "/e/i" {:headers
+                                                  {:Accept (mime-type :item)}})]
+          (:status response) => 200
+          (json? response) => true)
+        (collection/item-count e) => 1))
+    ;; wrong charset - 406 Not Acceptable
+    ;; curl -i --header "Accept: application/vnd.fcms.item+json;version=1" --header "Accept-Charset: utf-8" --header "Content-Type: application/vnd.fcms
+    (fact "create an item the wrong Accept-Charset header"
+      (let [response (create-item-with-api
+                       {:Accept-Charset "iso-8859-1"
+                        :Accept (mime-type :item)
+                        :Content-Type (mime-type :item)}
+                       {:name i})]
+        (:status response) => 406
+        (response-mime-type response) => (mime-type :text)
+        (response-location response) => nil
+        (let [body (body-from-response response)]
+          (.contains body "Acceptable media type: application/vnd.fcms.item+json;version=1") => true
+          (.contains body "Acceptable charset: utf-8") => true)        
+        (let [response (api-request :get "/e/i" {:headers
+                                                  {:Accept (mime-type :item)}})]
+          (:status response) => 404
+          (body? response) => false)
+        (collection/item-count e) => 0))
+    ;; no body - 400 Bad Request
+    ;; curl -i --header "Accept: application/vnd.fcms.item+json;version=1" --header "Content-Type: application/vnd.fcms.item+json;version=1" --header "Charset: UTF-8" -X POST http://localhost:3000/c/
+
+    ;; FAILS
+    (fact "create an item with no body"
+      (let [response (create-item-with-api {})]
+        (:status response) => 400
+        (response-mime-type response) => (mime-type :text)
+        (let [body (body-from-response response)]
+          (.contains body "Bad request.") => true)
+        (collection/item-count e) => 0))
+    
+    ;; body, but not valid JSON - 400 Bad Request
+    ;; curl -i --header "Accept: application/vnd.fcms.item+json;version=1" --header "Content-Type: application/vnd.fcms.item+json;version=1" --header "Charset: UTF-8" -X POST -d 'Hi Mom!' http://localhost:3000/c/
+    ;; curl -i --header "Accept: application/vnd.fcms.item+json;version=1" --header "Content-Type: application/vnd.fcms.item+json;version=1" --header "Charset: UTF-8" -X POST -d '{"name":"g' http://localhost:3000/c/'
+    (fact "create an item with an invalid body"
+      (let [response (create-item-with-api "Hi Mom!")]
+        (:status response) => 400
+        (response-mime-type response) => (mime-type :text)
+        (response-location response) => nil
+        (let [body (body-from-response response)]
+          (.contains body "Bad request.") => true)        
+        (collection/item-count e) => 0)
+      (let [response (create-item-with-api "{'name': 'i'")]
+        (:status response) => 400
+        (response-mime-type response) => (mime-type :text)
+        (response-location response) => nil
+        (let [body (body-from-response response)]
+          (.contains body "Bad request.") => true)        
+        (collection/item-count e) => 0))
+    
+    ;; collection doesn't exist - 404 Not Found
+    ;; curl -i --header "Accept: application/vnd.fcms.item+json;version=1" --header "Content-Type: application/vnd.fcms.item+json;version=1" --header "Charset: UTF-8" -X POST -d '{"name":"i"}' http://localhost:3000/not-here/
+
+    ;; FAILS (wrong status)
+    (fact "create an item in a collection that doesn't exist"
+      (let [response (api-request :post "/not-here/" {:headers
+                                                       {:Accept (mime-type :item)
+                                                         :Accept-Charset "utf-8"
+                                                         :Content-Type (mime-type :item)}
+                                                       :body {:name i}})]
+        (:status response) => 404
+        (response-mime-type response) => (mime-type :text)
+        (let [body (body-from-response response)]
+          (.contains body "Collection not found.") => true)
+        (collection/item-count e) => 0))
+
+    ;; no "name" in body - 422 Unprocessable Entity
+    ;; curl -i --header "Accept: application/vnd.fcms.item+json;version=1" --header "Content-Type: application/vnd.fcms.item+json;version=1" --header "Charset: UTF-8" -X POST -d '{"slug":"i"}' http://localhost:3000/c/
+    (fact "create an item without a name"
+      (let [response (create-item-with-api {:slug i})]
+        (:status response) => 422
+        (response-mime-type response) => (mime-type :text)
+        (let [body (body-from-response response)]
+          (.contains body "Name is required.") => true)
+        (collection/item-count e) => 0))
+    
+    ;; slug specified in body is already used - 422 Unprocessable Entity
+    ;; curl -i --header "Accept: application/vnd.fcms.item+json;version=1" --header "Content-Type: application/vnd.fcms.item+json;version=1" --header "Charset: UTF-8" -X POST -d '{"name":"another-i", "slug":"i"}' http://localhost:3000/c/
+    (fact "create an item with a slug that's already used in the collection"
+      (let [response (create-item-with-api {:name i})]
+        (:status response) => 201
+        (response-mime-type response) => (mime-type :item)
+        (response-location response) => "/e/i"
+        (json? response)
+        ;; Get the created item and make sure it's right
+        (item/get-item e i) => (contains
+                                 {:collection e
+                                   :name i
+                                   :slug i
+                                   :version 1})
+        (collection/item-count e) => 1)
+      (let [response (api-request :get "/e/i" {:headers
+                                                {:Accept (mime-type :item)}})]
+        (:status response) => 200
+        (json? response) => true)
+      (let [response (create-item-with-api {:name "another-i" :slug i})]
+        (:status response) => 422
+        (response-mime-type response) => (mime-type :text)
+        (response-location response) => nil
+        (let [body (body-from-response response)]
+          (.contains body "Slug already used in collection.") => true)
+        (collection/item-count e) => 1))
+    ;; slug specified in body is invalid - 422 Unprocessable Entity
+    ;; curl -i --header "Accept: application/vnd.fcms.item+json;version=1" --header "Content-Type: application/vnd.fcms.item+json;version=1" --header "Charset: UTF-8" -X POST -d '{"name":"i", "slug":"I i"}' http://localhost:3000/c/
+    (fact "create an item with a slug that's invalid"
+      (let [response (create-item-with-api {:name i :slug "I i"})]
+        (:status response) => 422
+        (response-mime-type response) => (mime-type :text)
+        (response-location response) => nil
+        (let [body (body-from-response response)]
+          (.contains body "Invalid slug.") => true)
         (collection/item-count e) => 0))))
        (collection/item-count e) => 1))
    
    ;; wrong content type - 415 Unsupported Media Type
    ;; curl -i --header "Accept: application/vnd.fcms.item+json;version=1" --header "Accept-Charset: utf-8" --header "Content-Type: application/vnd.fcms.collection+json;version=1" -X POST -d '{"name":"i"}' http://localhost:3000/c/    
    (fact "create an item with the wrong Content-Type header"
      (let [response (create-item-with-api
                       {:Accept (mime-type :item)
                        :Content-Type (mime-type :collection)}
                       {:name i})]
        (:status response) => 415

    ;; curl -i --header "Accept: application/vnd.fcms.item+json;version=1" --header "Accept-Charset: utf-8" -X POST -d '{"name":"i"}' http://localhost:3000/c/
    (fact "create an item without a Content-Type header"
      (let [response (create-item-with-api
                       {:Accept (mime-type :item)
                        :Accept-Charset "utf-8"}
                       {:name i})]
        (:status response) => 201
        (response-mime-type response) => (mime-type :item)
