WIP: Testing compound key insert reveals weird type conversion

This commit is contained in:
Joe Nelson
2014-08-25 19:43:23 -07:00
parent eef7860922
commit c007dbb2b2
3 changed files with 55 additions and 24 deletions
+11 -2
View File
@@ -32,7 +32,7 @@ instance JSON.FromJSON IncPK where
spec :: Spec
spec = around appWithFixture $
describe "Posting new record" $
describe "Posting new record" $ do
context "with no pk supplied" $ do
context "into a table with auto-incrementing pk" $
it "succeeds with 201 and link" $ do
@@ -50,5 +50,14 @@ spec = around appWithFixture $
context "into a table with simple pk" $
it "fails with 400 and error" $
post "/contacts" [json| { "name":"J Doe"} |]
post "/simple_pk" [json| { "extra":"foo"} |]
`shouldRespondWith` 400
context "with compound pk supplied" $
it "builds response location header appropriately" $
post "/compound_pk" [json| { "k1":12, "k2":42 } |]
`shouldRespondWith` ResponseMatcher {
matchBody = Just "compare with error",
matchStatus = 201,
matchHeaders = [("Location", "/auto_incrementing_pk?k1=eq.12&k2=eq.42")]
}
+4 -3
View File
@@ -15,9 +15,10 @@ spec = around appWithFixture $ do
it "lists views in schema" $
get "/" `shouldRespondWith`
[json| [
{"schema":"1","name":"auto_incrementing_pk","insertable":true},
{"schema":"1","name":"contacts","insertable":true}]
|]
{"schema":"1","name":"auto_incrementing_pk","insertable":true}
, {"schema":"1","name":"compound_pk","insertable":true}
, {"schema":"1","name":"simple_pk","insertable":true}
] |]
{matchStatus = 200}
describe "Table info" $
+40 -19
View File
@@ -4,7 +4,7 @@
-- Dumped from database version 9.3.4
-- Dumped by pg_dump version 9.3.1
-- Started on 2014-08-25 17:13:38 PDT
-- Started on 2014-08-25 17:39:56 PDT
SET statement_timeout = 0;
SET lock_timeout = 0;
@@ -14,7 +14,7 @@ SET check_function_bodies = false;
SET client_min_messages = warning;
--
-- TOC entry 6 (class 2615 OID 229843)
-- TOC entry 6 (class 2615 OID 229910)
-- Name: 1; Type: SCHEMA; Schema: -; Owner: -
--
@@ -22,7 +22,7 @@ CREATE SCHEMA "1";
--
-- TOC entry 173 (class 3079 OID 12018)
-- TOC entry 174 (class 3079 OID 12018)
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
--
@@ -30,8 +30,8 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- TOC entry 2213 (class 0 OID 0)
-- Dependencies: 173
-- TOC entry 2219 (class 0 OID 0)
-- Dependencies: 174
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
--
@@ -45,7 +45,7 @@ SET default_tablespace = '';
SET default_with_oids = false;
--
-- TOC entry 170 (class 1259 OID 229844)
-- TOC entry 170 (class 1259 OID 229911)
-- Name: auto_incrementing_pk; Type: TABLE; Schema: 1; Owner: -; Tablespace:
--
@@ -58,7 +58,7 @@ CREATE TABLE auto_incrementing_pk (
--
-- TOC entry 171 (class 1259 OID 229851)
-- TOC entry 171 (class 1259 OID 229918)
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE; Schema: 1; Owner: -
--
@@ -71,7 +71,7 @@ CREATE SEQUENCE auto_incrementing_pk_id_seq
--
-- TOC entry 2214 (class 0 OID 0)
-- TOC entry 2220 (class 0 OID 0)
-- Dependencies: 171
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE OWNED BY; Schema: 1; Owner: -
--
@@ -80,18 +80,30 @@ ALTER SEQUENCE auto_incrementing_pk_id_seq OWNED BY auto_incrementing_pk.id;
--
-- TOC entry 172 (class 1259 OID 229859)
-- Name: contacts; Type: TABLE; Schema: 1; Owner: -; Tablespace:
-- TOC entry 173 (class 1259 OID 229931)
-- Name: compound_pk; Type: TABLE; Schema: 1; Owner: -; Tablespace:
--
CREATE TABLE contacts (
email character varying NOT NULL,
name character varying NOT NULL
CREATE TABLE compound_pk (
k1 integer NOT NULL,
k2 integer NOT NULL,
extra integer
);
--
-- TOC entry 2096 (class 2604 OID 229853)
-- TOC entry 172 (class 1259 OID 229920)
-- Name: simple_pk; Type: TABLE; Schema: 1; Owner: -; Tablespace:
--
CREATE TABLE simple_pk (
k character varying NOT NULL,
extra character varying NOT NULL
);
--
-- TOC entry 2100 (class 2604 OID 229926)
-- Name: id; Type: DEFAULT; Schema: 1; Owner: -
--
@@ -99,7 +111,7 @@ ALTER TABLE ONLY auto_incrementing_pk ALTER COLUMN id SET DEFAULT nextval('auto_
--
-- TOC entry 2098 (class 2606 OID 229855)
-- TOC entry 2102 (class 2606 OID 229928)
-- Name: auto_incrementing_pk_pkey; Type: CONSTRAINT; Schema: 1; Owner: -; Tablespace:
--
@@ -108,15 +120,24 @@ ALTER TABLE ONLY auto_incrementing_pk
--
-- TOC entry 2100 (class 2606 OID 229866)
-- TOC entry 2106 (class 2606 OID 229935)
-- Name: compound_pk_pkey; Type: CONSTRAINT; Schema: 1; Owner: -; Tablespace:
--
ALTER TABLE ONLY compound_pk
ADD CONSTRAINT compound_pk_pkey PRIMARY KEY (k1, k2);
--
-- TOC entry 2104 (class 2606 OID 229930)
-- Name: contacts_pkey; Type: CONSTRAINT; Schema: 1; Owner: -; Tablespace:
--
ALTER TABLE ONLY contacts
ADD CONSTRAINT contacts_pkey PRIMARY KEY (email);
ALTER TABLE ONLY simple_pk
ADD CONSTRAINT contacts_pkey PRIMARY KEY (k);
-- Completed on 2014-08-25 17:13:38 PDT
-- Completed on 2014-08-25 17:39:56 PDT
--
-- PostgreSQL database dump complete