Commit 3aec0e1f authored by Robert Speicher's avatar Robert Speicher

Merge branch 'refactor-service-external-methods' into 'master'

Refactor service external issue tracker and wiki

See merge request gitlab-org/gitlab!45883
parents 7ee20cb9 c2829d40
......@@ -422,8 +422,12 @@ class Service < ApplicationRecord
ProjectServiceWorker.perform_async(id, data)
end
def issue_tracker?
self.category == :issue_tracker
def external_issue_tracker?
category == :issue_tracker && active?
end
def external_wiki?
type == 'ExternalWikiService' && active?
end
# override if needed
......
......@@ -34,11 +34,11 @@ class BulkCreateIntegrationService
end
def run_callbacks(batch)
if integration.issue_tracker? && integration.active?
if integration.external_issue_tracker?
batch.update_all(has_external_issue_tracker: true)
end
if integration.type == 'ExternalWikiService' && integration.active?
if integration.external_wiki?
batch.update_all(has_external_wiki: true)
end
end
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Service do
using RSpec::Parameterized::TableSyntax
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
......@@ -15,8 +17,6 @@ RSpec.describe Service do
end
describe 'validations' do
using RSpec::Parameterized::TableSyntax
it { is_expected.to validate_presence_of(:type) }
where(:project_id, :group_id, :template, :instance, :valid) do
......@@ -863,4 +863,32 @@ RSpec.describe Service do
end
end
end
describe '#external_issue_tracker?' do
where(:category, :active, :result) do
:issue_tracker | true | true
:issue_tracker | false | false
:common | true | false
end
with_them do
it 'returns the right result' do
expect(build(:service, category: category, active: active).external_issue_tracker?).to eq(result)
end
end
end
describe '#external_wiki?' do
where(:type, :active, :result) do
'ExternalWikiService' | true | true
'ExternalWikiService' | false | false
'SlackService' | true | false
end
with_them do
it 'returns the right result' do
expect(build(:service, type: type, active: active).external_wiki?).to eq(result)
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