Commit 5967062f authored by Andy Soiron's avatar Andy Soiron Committed by Sean McGivern

Reset admin and group integrations

Adds the destroy call to the admin and group
integrations reset actions to actually reset
an integration. Inheriting integrations will be
deleted on the database level with a "ON DELETE CASCADE"
foreign key
parent 5559a68e
......@@ -43,6 +43,8 @@ module IntegrationsActions
end
def reset
integration.destroy!
flash[:notice] = s_('Integrations|This integration, and inheriting projects were reset.')
render json: {}, status: :ok
......
......@@ -75,18 +75,26 @@ RSpec.describe Admin::IntegrationsController do
end
describe '#reset' do
let(:integration) { create(:jira_service, :instance) }
let_it_be(:integration) { create(:jira_service, :instance) }
let_it_be(:inheriting_integration) { create(:jira_service, inherit_from_id: integration.id) }
before do
subject do
post :reset, params: { id: integration.class.to_param }
end
it 'returns 200 OK' do
it 'returns 200 OK', :aggregate_failures do
subject
expected_json = {}.to_json
expect(flash[:notice]).to eq('This integration, and inheriting projects were reset.')
expect(response).to have_gitlab_http_status(:ok)
expect(response.body).to eq(expected_json)
end
it 'deletes the integration and all inheriting integrations' do
expect { subject }.to change { JiraService.for_instance.count }.by(-1)
.and change { JiraService.inherit_from_id(integration.id).count }.by(-1)
end
end
end
......@@ -3,8 +3,8 @@
require 'spec_helper'
RSpec.describe Groups::Settings::IntegrationsController do
let(:user) { create(:user) }
let(:group) { create(:group) }
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
before do
sign_in(user)
......@@ -91,4 +91,42 @@ RSpec.describe Groups::Settings::IntegrationsController do
end
end
end
describe '#reset' do
let_it_be(:integration) { create(:jira_service, group: group, project: nil) }
let_it_be(:inheriting_integration) { create(:jira_service, inherit_from_id: integration.id) }
subject do
post :reset, params: { group_id: group, id: integration.class.to_param }
end
context 'when user is not owner' do
it 'renders not_found' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when user is owner' do
before do
group.add_owner(user)
end
it 'returns 200 OK', :aggregate_failures do
subject
expected_json = {}.to_json
expect(flash[:notice]).to eq('This integration, and inheriting projects were reset.')
expect(response).to have_gitlab_http_status(:ok)
expect(response.body).to eq(expected_json)
end
it 'deletes the integration and all inheriting integrations' do
expect { subject }.to change { JiraService.for_group(group.id).count }.by(-1)
.and change { JiraService.inherit_from_id(integration.id).count }.by(-1)
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