Refactor tests: renaming json table to prevent hiding of native json type

This commit is contained in:
Wolfgang Walther
2020-11-20 09:24:32 -05:00
committed by Steve Chavez
parent ca7ffd0a70
commit b091586394
5 changed files with 26 additions and 26 deletions
+2 -2
View File
@@ -260,7 +260,7 @@ spec actualPgVersion = do
context "jsonb" $ do
it "serializes nested object" $ do
let inserted = [json| { "data": { "foo":"bar" } } |]
request methodPost "/json"
request methodPost "/json_table"
[("Prefer", "return=representation")]
inserted
`shouldRespondWith` [str|[{"data":{"foo":"bar"}}]|]
@@ -269,7 +269,7 @@ spec actualPgVersion = do
it "serializes nested array" $ do
let inserted = [json| { "data": [1,2,3] } |]
request methodPost "/json"
request methodPost "/json_table"
[("Prefer", "return=representation")]
inserted
`shouldRespondWith` [str|[{"data":[1,2,3]}]|]
+8 -8
View File
@@ -140,20 +140,20 @@ spec actualPgVersion = describe "json and jsonb operators" $ do
context "filtering response" $ do
it "can filter by properties inside json column" $ do
get "/json?data->foo->>bar=eq.baz" `shouldRespondWith`
get "/json_table?data->foo->>bar=eq.baz" `shouldRespondWith`
[json| [{"data": {"id": 1, "foo": {"bar": "baz"}}}] |]
{ matchHeaders = [matchContentTypeJson] }
get "/json?data->foo->>bar=eq.fake" `shouldRespondWith`
get "/json_table?data->foo->>bar=eq.fake" `shouldRespondWith`
[json| [] |]
{ matchHeaders = [matchContentTypeJson] }
it "can filter by properties inside json column using not" $
get "/json?data->foo->>bar=not.eq.baz" `shouldRespondWith`
get "/json_table?data->foo->>bar=not.eq.baz" `shouldRespondWith`
[json| [] |]
{ matchHeaders = [matchContentTypeJson] }
it "can filter by properties inside json column using ->>" $
get "/json?data->>id=eq.1" `shouldRespondWith`
get "/json_table?data->>id=eq.1" `shouldRespondWith`
[json| [{"data": {"id": 1, "foo": {"bar": "baz"}}}] |]
{ matchHeaders = [matchContentTypeJson] }
@@ -191,19 +191,19 @@ spec actualPgVersion = describe "json and jsonb operators" $ do
context "ordering response" $ do
it "orders by a json column property asc" $
get "/json?order=data->>id.asc" `shouldRespondWith`
get "/json_table?order=data->>id.asc" `shouldRespondWith`
[json| [{"data": {"id": 0}}, {"data": {"id": 1, "foo": {"bar": "baz"}}}, {"data": {"id": 3}}] |]
{ matchHeaders = [matchContentTypeJson] }
it "orders by a json column with two level property nulls first" $
get "/json?order=data->foo->>bar.nullsfirst" `shouldRespondWith`
get "/json_table?order=data->foo->>bar.nullsfirst" `shouldRespondWith`
[json| [{"data": {"id": 3}}, {"data": {"id": 0}}, {"data": {"id": 1, "foo": {"bar": "baz"}}}] |]
{ matchHeaders = [matchContentTypeJson] }
context "Patching record, in a nonempty table" $
it "can set a json column to escaped value" $ do
_ <- post "/json" [json| { data: {"escaped":"bar"} } |]
request methodPatch "/json?data->>escaped=eq.bar"
_ <- post "/json_table" [json| { data: {"escaped":"bar"} } |]
request methodPatch "/json_table?data->>escaped=eq.bar"
[("Prefer", "return=representation")]
[json| { "data": { "escaped":" \"bar" } } |]
`shouldRespondWith` [json| [{ "data": { "escaped":" \"bar" } }] |]
+5 -5
View File
@@ -257,13 +257,13 @@ SELECT pg_catalog.setval('items2_id_seq', 15, true);
--
-- Data for Name: json; Type: TABLE DATA; Schema: test; Owner: -
-- Data for Name: json_table; Type: TABLE DATA; Schema: test; Owner: -
--
TRUNCATE TABLE json CASCADE;
INSERT INTO json VALUES ('{"foo":{"bar":"baz"},"id":1}');
INSERT INTO json VALUES ('{"id":3}');
INSERT INTO json VALUES ('{"id":0}');
TRUNCATE TABLE json_table CASCADE;
INSERT INTO json_table VALUES ('{"foo":{"bar":"baz"},"id":1}');
INSERT INTO json_table VALUES ('{"id":3}');
INSERT INTO json_table VALUES ('{"id":0}');
--
+1 -1
View File
@@ -28,7 +28,7 @@ GRANT ALL ON TABLE
, has_count_column
, has_fk
, insertable_view_with_join
, json
, json_table
, materialized_view
, menagerie
, no_pk
+10 -10
View File
@@ -457,7 +457,7 @@ CREATE TABLE clients (
CREATE TABLE complex_items (
id bigint NOT NULL,
name text,
settings pg_catalog.json,
settings json,
arr_data integer[],
"field-with_sep" integer default 1 not null
);
@@ -551,11 +551,11 @@ CREATE VIEW insertable_view_with_join AS
JOIN auto_incrementing_pk USING (id));
--
-- Name: json; Type: TABLE; Schema: test; Owner: -
-- Name: json_table; Type: TABLE; Schema: test; Owner: -
--
CREATE TABLE json (
data pg_catalog.json
CREATE TABLE json_table (
data json
);
@@ -1112,11 +1112,11 @@ create function test.single_out_param(num int, OUT num_plus_one int) AS $$
select num + 1;
$$ language sql;
create function test.single_json_out_param(a int, b text, OUT my_json pg_catalog.json) AS $$
create function test.single_json_out_param(a int, b text, OUT my_json json) AS $$
select json_build_object('a', a, 'b', b);
$$ language sql;
create function test.many_out_params(OUT my_json pg_catalog.json, OUT num int, OUT str text) AS $$
create function test.many_out_params(OUT my_json json, OUT num int, OUT str text) AS $$
select '{"a": 1, "b": "two"}'::json, 3, 'four'::text;
$$ language sql;
@@ -1152,14 +1152,14 @@ begin
end;
$$ language plpgsql;
create or replace function test.send_body_status_403() returns pg_catalog.json as $$
create or replace function test.send_body_status_403() returns json as $$
begin
perform set_config('response.status', '403', true);
return json_build_object('message', 'invalid user or password');
end;
$$ language plpgsql;
create or replace function test.send_bad_status() returns pg_catalog.json as $$
create or replace function test.send_bad_status() returns json as $$
begin
perform set_config('response.status', 'bad', true);
return null;
@@ -1200,7 +1200,7 @@ create or replace function test.overloaded() returns setof int as $$
values (1), (2), (3);
$$ language sql;
create or replace function test.overloaded(pg_catalog.json) returns table(x int, y text) as $$
create or replace function test.overloaded(json) returns table(x int, y text) as $$
select * from json_to_recordset($1) as r(x int, y text);
$$ language sql;
@@ -1345,7 +1345,7 @@ create table "UnitTest"(
create table json_arr(
id integer primary key,
data pg_catalog.json
data json
);
create table jsonb_test(