Commit 9793e093 authored by Arturo Herrero's avatar Arturo Herrero Committed by Lukas Eipert

Properly pass admin integration to the frontend

This sets the admin integration object to used in the view and ensures
that parameters relating to the admin integration sent from the frontend
are handled properly.
Co-authored-by: default avatarLukas Eipert <leipert@gitlab.com>
Co-authored-by: default avatarJustin Ho Tuan Duong <hduong@gitlab.com>
parent 801bd579
......@@ -31,6 +31,7 @@ module ServiceParams
:external_wiki_url,
:google_iap_service_account_json,
:google_iap_audience_client_id,
:inherit_from_id,
# We're using `issues_events` and `merge_requests_events`
# in the view so we still need to explicitly state them
# here. `Service#event_names` would only give
......
......@@ -21,10 +21,12 @@ class Projects::ServicesController < Projects::ApplicationController
layout "project_settings"
def edit
@admin_integration = Service.instance_for(service.type)
end
def update
@service.attributes = service_params[:service]
@service.inherit_from_id = nil if service_params[:service][:inherit_from_id].blank?
saved = @service.save(context: :manual_change)
......
......@@ -101,6 +101,7 @@ module ServicesHelper
def integration_form_data(integration)
{
id: integration.id,
show_active: integration.show_active_box?.to_s,
activated: (integration.active || integration.new_record?).to_s,
type: integration.to_param,
......
......@@ -364,6 +364,10 @@ class Service < ApplicationRecord
exists?(instance: true, type: type)
end
def self.instance_for(type)
find_by(instance: true, type: type)
end
# override if needed
def supports_data_fields?
false
......
......@@ -179,6 +179,23 @@ RSpec.describe Projects::ServicesController do
it_behaves_like 'service update'
end
context 'wehn param `inherit_from_id` is set to empty string' do
let(:service_params) { { inherit_from_id: '' } }
it 'sets inherit_from_id to nil' do
expect(service.reload.inherit_from_id).to eq(nil)
end
end
context 'wehn param `inherit_from_id` is set to some value' do
let(:instance_service) { create(:jira_service, :instance) }
let(:service_params) { { inherit_from_id: instance_service.id } }
it 'sets inherit_from_id to value' do
expect(service.reload.inherit_from_id).to eq(instance_service.id)
end
end
end
describe 'as JSON' do
......
......@@ -7,4 +7,28 @@ RSpec.describe ServicesHelper do
it { expect(event_action_title('comment')).to eq 'Comment' }
it { expect(event_action_title('something')).to eq 'Something' }
end
describe '#integration_form_data' do
subject { helper.integration_form_data(integration) }
context 'Jira service' do
let(:integration) { build(:jira_service) }
it 'includes Jira specific fields' do
is_expected.to include(
:id,
:show_active,
:activated,
:type,
:merge_request_events,
:commit_events,
:enable_comments,
:comment_detail,
:trigger_events,
:fields,
:inherit_from_id
)
end
end
end
end
......@@ -386,6 +386,33 @@ RSpec.describe Service do
end
end
describe 'instance' do
describe '.instance_for' do
let_it_be(:jira_service) { create(:jira_service, :instance) }
let_it_be(:slack_service) { create(:slack_service, :instance) }
subject { described_class.instance_for(type) }
context 'Hipchat serivce' do
let(:type) { 'HipchatService' }
it { is_expected.to eq(nil) }
end
context 'Jira serivce' do
let(:type) { 'JiraService' }
it { is_expected.to eq(jira_service) }
end
context 'Slack serivce' do
let(:type) { 'SlackService' }
it { is_expected.to eq(slack_service) }
end
end
end
describe "{property}_changed?" do
let(:service) do
BambooService.create(
......
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