fix: Make OPTIONS consider view instead of triggers (#1824)
This commit is contained in:
+55
-10
@@ -12,15 +12,60 @@ import SpecHelper
|
||||
|
||||
spec :: SpecWith ((), Application)
|
||||
spec = describe "Allow header" $ do
|
||||
it "includes read/write verbs for writeable table" $ do
|
||||
r <- request methodOptions "/items" [] ""
|
||||
liftIO $
|
||||
simpleHeaders r `shouldSatisfy`
|
||||
matchHeader "Allow" "GET,POST,PATCH,DELETE"
|
||||
context "a table" $ do
|
||||
it "includes read/write verbs for writeable table" $ do
|
||||
r <- request methodOptions "/items" [] ""
|
||||
liftIO $
|
||||
simpleHeaders r `shouldSatisfy`
|
||||
matchHeader "Allow" "OPTIONS,GET,HEAD,POST,PUT,PATCH,DELETE"
|
||||
|
||||
it "includes read verbs for read-only table" $ do
|
||||
r <- request methodOptions "/has_count_column" [] ""
|
||||
liftIO $
|
||||
simpleHeaders r `shouldSatisfy`
|
||||
matchHeader "Allow" "GET"
|
||||
context "a view" $ do
|
||||
context "auto updatable" $ do
|
||||
it "includes read/write verbs for auto updatable views with pk" $ do
|
||||
r <- request methodOptions "/projects_auto_updatable_view_with_pk" [] ""
|
||||
liftIO $
|
||||
simpleHeaders r `shouldSatisfy`
|
||||
matchHeader "Allow" "OPTIONS,GET,HEAD,POST,PUT,PATCH,DELETE"
|
||||
|
||||
it "includes read/write verbs for auto updatable views without pk" $ do
|
||||
r <- request methodOptions "/projects_auto_updatable_view_without_pk" [] ""
|
||||
liftIO $
|
||||
simpleHeaders r `shouldSatisfy`
|
||||
matchHeader "Allow" "OPTIONS,GET,HEAD,POST,PATCH,DELETE"
|
||||
|
||||
context "non auto updatable" $ do
|
||||
it "includes read verbs for non auto updatable views" $ do
|
||||
r <- request methodOptions "/projects_view_without_triggers" [] ""
|
||||
liftIO $
|
||||
simpleHeaders r `shouldSatisfy`
|
||||
matchHeader "Allow" "OPTIONS,GET,HEAD"
|
||||
|
||||
it "includes read/write verbs for insertable, updatable and deletable views with pk" $ do
|
||||
r <- request methodOptions "/projects_view_with_all_triggers_with_pk" [] ""
|
||||
liftIO $
|
||||
simpleHeaders r `shouldSatisfy`
|
||||
matchHeader "Allow" "OPTIONS,GET,HEAD,POST,PUT,PATCH,DELETE"
|
||||
|
||||
it "includes read/write verbs for insertable, updatable and deletable views without pk" $ do
|
||||
r <- request methodOptions "/projects_view_with_all_triggers_without_pk" [] ""
|
||||
liftIO $
|
||||
simpleHeaders r `shouldSatisfy`
|
||||
matchHeader "Allow" "OPTIONS,GET,HEAD,POST,PATCH,DELETE"
|
||||
|
||||
it "includes read and insert verbs for insertable views" $ do
|
||||
r <- request methodOptions "/projects_view_with_insert_trigger" [] ""
|
||||
liftIO $
|
||||
simpleHeaders r `shouldSatisfy`
|
||||
matchHeader "Allow" "OPTIONS,GET,HEAD,POST"
|
||||
|
||||
it "includes read and update verbs for updatable views" $ do
|
||||
r <- request methodOptions "/projects_view_with_update_trigger" [] ""
|
||||
liftIO $
|
||||
simpleHeaders r `shouldSatisfy`
|
||||
matchHeader "Allow" "OPTIONS,GET,HEAD,PATCH"
|
||||
|
||||
it "includes read and delete verbs for deletable views" $ do
|
||||
r <- request methodOptions "/projects_view_with_delete_trigger" [] ""
|
||||
liftIO $
|
||||
simpleHeaders r `shouldSatisfy`
|
||||
matchHeader "Allow" "OPTIONS,GET,HEAD,DELETE"
|
||||
|
||||
Vendored
+67
@@ -1544,6 +1544,73 @@ $$A materialized view for projects
|
||||
|
||||
Just a test for materialized views$$;
|
||||
|
||||
-- Tests for updatable, insertable and deletable views
|
||||
create view test.projects_auto_updatable_view_with_pk as
|
||||
select id, name, client_id from test.projects;
|
||||
|
||||
create view test.projects_auto_updatable_view_without_pk as
|
||||
select name, client_id from test.projects;
|
||||
|
||||
create view test.projects_view_without_triggers as
|
||||
select distinct id, name, client_id from test.projects;
|
||||
|
||||
create or replace function test.test_for_views_with_triggers() returns trigger as $$
|
||||
begin
|
||||
return null;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
create view test.projects_view_with_all_triggers_with_pk as
|
||||
select distinct id, name, client_id from test.projects;
|
||||
|
||||
create trigger projects_view_with_all_triggers_with_pk_insert
|
||||
instead of insert on test.projects_view_with_all_triggers_with_pk
|
||||
for each row execute procedure test_for_views_with_triggers();
|
||||
|
||||
create trigger projects_view_with_all_triggers_with_pk_update
|
||||
instead of update on test.projects_view_with_all_triggers_with_pk
|
||||
for each row execute procedure test_for_views_with_triggers();
|
||||
|
||||
create trigger projects_view_with_all_triggers_with_pk_delete
|
||||
instead of delete on test.projects_view_with_all_triggers_with_pk
|
||||
for each row execute procedure test_for_views_with_triggers();
|
||||
|
||||
create view test.projects_view_with_all_triggers_without_pk as
|
||||
select distinct name, client_id from test.projects;
|
||||
|
||||
create trigger projects_view_with_all_triggers_without_pk_insert
|
||||
instead of insert on test.projects_view_with_all_triggers_without_pk
|
||||
for each row execute procedure test_for_views_with_triggers();
|
||||
|
||||
create trigger projects_view_with_all_triggers_without_pk_update
|
||||
instead of update on test.projects_view_with_all_triggers_without_pk
|
||||
for each row execute procedure test_for_views_with_triggers();
|
||||
|
||||
create trigger projects_view_with_all_triggers_without_pk_delete
|
||||
instead of delete on test.projects_view_with_all_triggers_without_pk
|
||||
for each row execute procedure test_for_views_with_triggers();
|
||||
|
||||
create view test.projects_view_with_insert_trigger as
|
||||
select distinct id, name, client_id from test.projects;
|
||||
|
||||
create trigger projects_view_with_insert_trigger_insert
|
||||
instead of insert on test.projects_view_with_insert_trigger
|
||||
for each row execute procedure test_for_views_with_triggers();
|
||||
|
||||
create view test.projects_view_with_update_trigger as
|
||||
select distinct id, name, client_id from test.projects;
|
||||
|
||||
create trigger projects_view_with_update_trigger_update
|
||||
instead of update on test.projects_view_with_update_trigger
|
||||
for each row execute procedure test_for_views_with_triggers();
|
||||
|
||||
create view test.projects_view_with_delete_trigger as
|
||||
select distinct id, name, client_id from test.projects;
|
||||
|
||||
create trigger projects_view_with_delete_trigger_delete
|
||||
instead of delete on test.projects_view_with_delete_trigger
|
||||
for each row execute procedure test_for_views_with_triggers();
|
||||
|
||||
create or replace function test."quotedFunction"("user" text, "fullName" text, "SSN" text)
|
||||
returns jsonb AS $$
|
||||
select format('{"user": "%s", "fullName": "%s", "SSN": "%s"}', "user", "fullName", "SSN")::jsonb;
|
||||
|
||||
Reference in New Issue
Block a user