create items in test, not in the schema.
This commit is contained in:
@@ -13,25 +13,11 @@ import Data.Maybe (fromJust)
|
||||
import Network.HTTP.Types.Header
|
||||
import Network.HTTP.Types
|
||||
import Control.Monad (replicateM_)
|
||||
import Data.Monoid
|
||||
import qualified Hasql as H
|
||||
import qualified Data.ByteString.Char8 as BS
|
||||
|
||||
import TestTypes(IncPK(..), CompoundPK(..))
|
||||
|
||||
--import Debug.Trace
|
||||
|
||||
|
||||
clearTable :: BS.ByteString -> IO ()
|
||||
clearTable table = H.session pgSettings testSettings $ H.tx Nothing $
|
||||
H.unit ("delete from \"1\"."<>table, [], True)
|
||||
|
||||
createItems :: Int -> IO ()
|
||||
createItems n = H.session pgSettings testSettings $ H.tx Nothing txn >> return ()
|
||||
where
|
||||
txn = sequence $ map H.unit stmts
|
||||
stmts = map [H.q|insert into "1".items (id) values (?)|] [1..n]
|
||||
|
||||
spec :: Spec
|
||||
spec = beforeAll resetDb $ around withApp $ do
|
||||
describe "Posting new record" $ do
|
||||
|
||||
@@ -6,7 +6,10 @@ import Test.Hspec.Wai
|
||||
import SpecHelper
|
||||
|
||||
spec :: Spec
|
||||
spec = beforeAll resetDb $ around withApp $ do
|
||||
spec = beforeAll (do
|
||||
resetDb
|
||||
createItems 15
|
||||
) . afterAll_ (clearTable "items") . around withApp $ do
|
||||
describe "Querying a nonexistent table" $
|
||||
it "causes a 404" $
|
||||
get "/faketable" `shouldRespondWith` 404
|
||||
|
||||
@@ -8,7 +8,8 @@ import Network.Wai.Test (SResponse(simpleHeaders,simpleStatus))
|
||||
import SpecHelper
|
||||
|
||||
spec :: Spec
|
||||
spec = beforeAll resetDb $ around withApp $
|
||||
spec = beforeAll (resetDb >> createItems 15) . afterAll_ (clearTable "items")
|
||||
. around withApp $
|
||||
describe "GET /items" $ do
|
||||
|
||||
context "without range headers" $
|
||||
|
||||
@@ -10,6 +10,7 @@ import Hasql as H
|
||||
import Hasql.Postgres as H
|
||||
|
||||
import Data.String.Conversions (cs)
|
||||
import Data.Monoid
|
||||
-- import Control.Exception.Base (bracket, finally)
|
||||
import Control.Monad (void)
|
||||
import Control.Exception
|
||||
@@ -89,6 +90,16 @@ authHeader :: String -> String -> Header
|
||||
authHeader u p =
|
||||
(hAuthorization, cs $ "Basic " ++ encode (u ++ ":" ++ p))
|
||||
|
||||
clearTable :: BS.ByteString -> IO ()
|
||||
clearTable table = H.session pgSettings testSettings $ H.tx Nothing $
|
||||
H.unit ("delete from \"1\"."<>table, [], True)
|
||||
|
||||
createItems :: Int -> IO ()
|
||||
createItems n = H.session pgSettings testSettings $ H.tx Nothing txn
|
||||
where
|
||||
txn = sequence_ $ map H.unit stmts
|
||||
stmts = map [H.q|insert into "1".items (id) values (?)|] [1..n]
|
||||
|
||||
-- for hspec-wai
|
||||
pending_ :: WaiSession ()
|
||||
pending_ = liftIO Test.Hspec.pending
|
||||
|
||||
Vendored
+1
-18
@@ -452,30 +452,13 @@ SELECT pg_catalog.setval('has_fk_id_seq', 1, false);
|
||||
-- Data for Name: items; Type: TABLE DATA; Schema: 1; Owner: postgrest_test
|
||||
--
|
||||
|
||||
INSERT INTO items (id) VALUES (1);
|
||||
INSERT INTO items (id) VALUES (2);
|
||||
INSERT INTO items (id) VALUES (3);
|
||||
INSERT INTO items (id) VALUES (4);
|
||||
INSERT INTO items (id) VALUES (5);
|
||||
INSERT INTO items (id) VALUES (6);
|
||||
INSERT INTO items (id) VALUES (7);
|
||||
INSERT INTO items (id) VALUES (8);
|
||||
INSERT INTO items (id) VALUES (9);
|
||||
INSERT INTO items (id) VALUES (10);
|
||||
INSERT INTO items (id) VALUES (11);
|
||||
INSERT INTO items (id) VALUES (12);
|
||||
INSERT INTO items (id) VALUES (13);
|
||||
INSERT INTO items (id) VALUES (14);
|
||||
INSERT INTO items (id) VALUES (15);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2339 (class 0 OID 0)
|
||||
-- Dependencies: 198
|
||||
-- Name: items_id_seq; Type: SEQUENCE SET; Schema: 1; Owner: postgrest_test
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('items_id_seq', 19, true);
|
||||
SELECT pg_catalog.setval('items_id_seq', 1, true);
|
||||
|
||||
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user