Tests a single insertion

This commit is contained in:
Joe Nelson
2014-08-10 19:45:48 -07:00
parent c9e92ffc67
commit 276cea4a02
2 changed files with 25 additions and 5 deletions
+14 -3
View File
@@ -1,3 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
module PgQuerySpec where
import Test.Hspec
@@ -5,7 +7,10 @@ import Test.Hspec
import Database.HDBC
import Database.HDBC.PostgreSQL
loadFixture :: String -> IO ()
import PgQuery (insert)
import Types (SqlRow(..))
loadFixture :: String -> IO Connection
loadFixture name = do
conn <- connectPostgreSQL "postgres://postgres:@localhost:5432/dbapi_test"
sql <- readFile $ "test/fixtures/" ++ name ++ ".sql"
@@ -13,6 +18,7 @@ loadFixture name = do
runRaw conn "create schema public"
runRaw conn sql
commit conn
return conn
main :: IO ()
main = hspec spec
@@ -20,8 +26,13 @@ main = hspec spec
spec :: Spec
spec = beforeAll (loadFixture "schema") $ do
describe "insert" $
it "can insert into an empty table" $ \_ ->
head [23 ..] `shouldBe` (23 :: Int)
it "can insert into an empty table" $ \conn -> do
_ <- insert "public" "auto_incrementing_pk" (SqlRow [
("non_nullable_string", toSql ("a string that isn't null" :: String))
]) conn
r <- quickQuery conn "select count(1) from auto_incrementing_pk" []
commit conn
[[toSql (1 :: Int)]] `shouldBe` r
describe "insert again" $
it "is true" $ \_ ->