Ensure db fixtures loaded in feature specs

This commit is contained in:
Joe Nelson
2014-08-17 16:18:09 -07:00
parent 3a646a4eb4
commit 0fbfa2395b
4 changed files with 29 additions and 14 deletions
+23
View File
@@ -0,0 +1,23 @@
module SpecHelper where
import Network.Wai
import Database.HDBC
import Database.HDBC.PostgreSQL
import Dbapi (AppConfig(..))
cfg :: AppConfig
cfg = AppConfig "postgres://postgres:@localhost:5432/dbapi_test" 9000
loadFixture :: String -> IO Connection
loadFixture name = do
conn <- connectPostgreSQL $ configDbUri cfg
sql <- readFile $ "test/fixtures/" ++ name ++ ".sql"
runRaw conn "drop schema if exists \"1\" cascade"
runRaw conn sql
commit conn
return conn
prepareAppDb :: String -> Application -> IO Application
prepareAppDb = (. return) . (>>) . loadFixture