Tests a single insertion
This commit is contained in:
+11
-2
@@ -36,5 +36,14 @@ Test-Suite spec
|
||||
Hs-Source-Dirs: src , test
|
||||
Ghc-Options: -Wall
|
||||
Main-Is: Spec.hs
|
||||
Build-Depends: base, hspec2, HDBC,
|
||||
HDBC-postgresql
|
||||
Build-Depends: base, hspec2
|
||||
, HDBC, HDBC-postgresql
|
||||
, warp, wai >= 3.0.1 && < 3.0.2
|
||||
, http-types, scientific, time
|
||||
, bytestring, aeson, network
|
||||
, text, optparse-applicative
|
||||
, unordered-containers
|
||||
, regex-base
|
||||
, http-media, regex-tdfa
|
||||
, Ranged-sets
|
||||
, transformers
|
||||
|
||||
+14
-3
@@ -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" $ \_ ->
|
||||
|
||||
Reference in New Issue
Block a user