on 44d3bd2 help sign in
typeable/wai/TestApp.hs
41 lines 1.5 kB history raw
1{-# LANGUAGE QuasiQuotes, TypeFamilies, GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE TemplateHaskell #-}
3{-# LANGUAGE OverloadedStrings #-}
4module TestApp (testApp) where
6import Network.Wai
7import Data.ByteString.Lazy.Char8 (pack)
8import Database.Persist.Sqlite
9import System.Directory
10import Control.Monad (when)
11import Helper
12import Text.Hamlet
14mkPersist [$persist|
15Dummy
16 dummy String
17|]
19testApp handler = do
20 putStrLn "testApp called, this should happen only once per reload"
21 -- Swap between the following two lines as necessary to generate errors
22 exi <- doesFileExist db
23 --let exi = True
24 when exi $ removeFile db
25 withSqlitePool db 10 $ \pool -> do
26 flip runSqlPool pool $ runMigration $ migrate $ Dummy ""
27 handler $ \req -> do
28 if pathInfo req == "/favicon.ico"
29 then return $ Response status301 [("Location", "http://docs.yesodweb.com/favicon.ico")]
30 $ ResponseLBS $ pack ""
31 else do
32 print $ pathInfo req
33 x <- flip runSqlPool pool $ do
34 insert $ Dummy ""
35 count ([] :: [Filter Dummy])
36 return $ Response status200
37 [("Content-Type", "text/html; charset=utf-8")]
38 $ ResponseLBS
39 $ renderHamlet id
40 $(hamletFileDebug "hamlet/testapp.hamlet")
41 putStrLn "handler completed, this should only happen at the beginning of a reload"