Feature tests pass, unit test does not

This commit is contained in:
Joe Nelson
2014-08-23 18:08:20 -07:00
parent a3a6108d49
commit 036ffa107b
6 changed files with 27 additions and 30 deletions
+6 -12
View File
@@ -10,8 +10,6 @@ import Control.Exception.Base (bracket)
import Dbapi (app, AppConfig(..))
import Debug.Trace
cfg :: AppConfig
cfg = AppConfig "postgres://postgres:@localhost:5432/dbapi_test" 9000
@@ -23,21 +21,17 @@ withDatabaseConnection = bracket openConnection disconnect
loadFixture :: String -> Connection -> IO ()
loadFixture name conn = do
runRaw conn "begin;"
sql <- readFile $ "test/fixtures/" ++ name ++ ".sql"
runRaw conn sql
rollbackFixture :: Connection -> IO ()
rollbackFixture = flip runRaw "rollback;"
dbWithSchema :: ActionWith Connection -> IO ()
dbWithSchema action = withDatabaseConnection $ \c -> do
trace "Load fixture" loadFixture "schema" c
trace "act" action (c)
trace "rollback" rollbackFixture c
runRaw c "begin;"
action c
rollback c
appWithFixture :: ActionWith Application -> IO ()
appWithFixture action = withDatabaseConnection $ \c -> do
loadFixture "schema" c
action (app cfg)
rollbackFixture c
runRaw c "begin;"
action $ app c
rollback c