diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2016-01-05 11:27:38 +0100 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2016-01-05 11:32:21 +0100 |
commit | f00607431cd13a952731e36701ebc3b39e64d09b (patch) | |
tree | f65376c27789d0e87659f37294b2da9738604d5e | |
parent | 3098500835aad26748d982fa81c84a2deed97931 (diff) | |
download | gitlab-ce-f00607431cd13a952731e36701ebc3b39e64d09b.tar.gz |
Add delete feature to triggers API
-rw-r--r-- | lib/api/triggers.rb | 19 | ||||
-rw-r--r-- | spec/requests/api/triggers_spec.rb | 33 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/api/triggers.rb b/lib/api/triggers.rb index 9a1e3fdc976..3cb7810241f 100644 --- a/lib/api/triggers.rb +++ b/lib/api/triggers.rb @@ -61,6 +61,25 @@ module API present triggers, with: Entities::Trigger end + + # Delete trigger + # + # Parameters: + # id (required) - The ID of a project + # trigger_id - The ID of trigger to delete + # Example Request: + # DELETE /projects/:id/triggers/:trigger_id + delete ':id/triggers/:trigger_id' do + authenticate! + authorize_admin_project + + trigger = user_project.triggers.where(id: params[:trigger_id].to_i).first + return not_found!('Trigger') unless trigger + + trigger.destroy + + present trigger, with: Entities::Trigger + end end end end diff --git a/spec/requests/api/triggers_spec.rb b/spec/requests/api/triggers_spec.rb index 4b356108c80..4e073a55d9c 100644 --- a/spec/requests/api/triggers_spec.rb +++ b/spec/requests/api/triggers_spec.rb @@ -114,4 +114,37 @@ describe API::API do end end end + + describe 'DELETE /projects/:id/triggets/:trigger_id' do + context 'authenticated user with valid permissions' do + it 'should delete trigger' do + expect do + delete api("/projects/#{project.id}/triggers/#{trigger.id}", user) + end.to change{project.triggers.count}.by(-1) + expect(response.status).to eq(200) + end + + it 'should responde with 404 Not Found if requesting non-existing trigger' do + delete api("/projects/#{project.id}/triggers/9999", user) + + expect(response.status).to eq(404) + end + end + + context 'authenticated user with invalid permissions' do + it 'should not delete trigger' do + delete api("/projects/#{project.id}/triggers/#{trigger.id}", user2) + + expect(response.status).to eq(403) + end + end + + context 'unauthentikated user' do + it 'should not delete trigger' do + delete api("/projects/#{project.id}/triggers/#{trigger.id}") + + expect(response.status).to eq(401) + end + end + end end |