Commit bf78685a authored by Rémy Coutable's avatar Rémy Coutable

Fix ProjectPushRules API

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 4053ce9e
......@@ -22,6 +22,7 @@ module API
mount ::API::V3::Notes
mount ::API::V3::ProjectGitHook
mount ::API::V3::ProjectHooks
mount ::API::V3::ProjectPushRule
mount ::API::V3::Projects
mount ::API::V3::ProjectSnippets
mount ::API::V3::Repositories
......
module API
module V3
class ProjectPushRule < Grape::API
before { authenticate! }
before { authorize_admin_project }
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
desc 'Deletes project push rule'
delete ":id/push_rule" do
push_rule = user_project.push_rule
not_found!('Push Rule') unless push_rule
status(200)
push_rule.destroy
end
end
end
end
end
......@@ -131,8 +131,7 @@ describe API::ProjectPushRule, 'ProjectPushRule', api: true do
it "deletes push rule from project" do
delete api("/projects/#{project.id}/push_rule", user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Hash
expect(response).to have_http_status(204)
end
end
......
require 'spec_helper'
describe API::V3::ProjectPushRule, 'ProjectPushRule', api: true do
include ApiHelpers
let(:user) { create(:user) }
let(:user3) { create(:user) }
let!(:project) { create(:project, creator_id: user.id, namespace: user.namespace) }
before do
project.team << [user, :master]
project.team << [user3, :developer]
end
describe "DELETE /projects/:id/push_rule" do
before do
create(:push_rule, project: project)
end
context "authorized user" do
it "deletes push rule from project" do
delete v3_api("/projects/#{project.id}/push_rule", user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Hash
end
end
context "unauthorized user" do
it "returns a 403 error" do
delete v3_api("/projects/#{project.id}/push_rule", user3)
expect(response).to have_http_status(403)
end
end
end
describe "DELETE /projects/:id/push_rule" do
context "for non existing push rule" do
it "deletes push rule from project" do
delete v3_api("/projects/#{project.id}/push_rule", user)
expect(response).to have_http_status(404)
expect(json_response).to be_an Hash
expect(json_response['message']).to eq('404 Push Rule Not Found')
end
it "returns a 403 error if not authorized" do
delete v3_api("/projects/#{project.id}/push_rule", user3)
expect(response).to have_http_status(403)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment