Minor database refactoring

This commit is contained in:
Nicholas Kariniemi 2013-08-18 14:13:55 +03:00
parent 635dfd948e
commit 707fb9f22d
4 changed files with 14 additions and 7 deletions

View file

@ -7,12 +7,17 @@
(def test-db "grub-test")
(defn short-delay []
(<!! (timeout 1)))
(<!! (timeout 20)))
(defn get-test-grub []
{:_id (str "grub" (rand-int 10000))
:grub (str "testtext" (rand-int 1000))
:completed ([true false] (rand-int 1))})
(describe
"grub.db"
(before (do (db/connect-and-handle-events test-db)
(mc/drop db/grub-collection)))
(before-all (db/connect-and-handle-events test-db))
(before (mc/drop db/grub-collection))
(describe "Create grub"
(it "should create a grub when a create event comes"
(let [test-grub "testgrub"

View file

@ -38,8 +38,7 @@
(defn -main [& args]
(let [port 3000]
(println (str "Starting server on localhost:" port))
(db/connect-and-handle-events)
(defonce stop-server (httpkit/run-server app {:port port}))
(when (some #(= % "integration") args)
(integration-test/run)
(integration-test/run port)
(stop-server))))

View file

@ -15,7 +15,7 @@
(let [grub (-> event
(select-keys [:_id :grub])
(assoc :completed false))]
(when (and (:_id grub) (:grub grub)) (mc/insert grub-collection grub))))
(mc/insert grub-collection grub)))
(defmethod handle-event :complete [event]
(mc/update grub-collection
@ -57,3 +57,5 @@
(handle-incoming-events!)
(m/connect!)
(m/set-db! (m/get-db db-name))))
(connect-and-handle-events default-db)

View file

@ -37,7 +37,8 @@
(defn handle-incoming-events []
(let [[incoming incoming'] (fan-out incoming-events 2)]
(do-chan! push-event-to-others incoming)
(go-loop (let [event (<! incoming')]
(go-loop (let [event (<! incoming')
parsed-event (dissoc event :ws-channel)]
(>! @db/incoming-events event)))))
(defn websocket-handler [request]