Commit 989ea960 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '330300-ajk-rst' into 'master'

Rename project integration associations: RST [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!64334
parents 3cf48f31 d9e1d0cb
...@@ -51,6 +51,9 @@ class Integration < ApplicationRecord ...@@ -51,6 +51,9 @@ class Integration < ApplicationRecord
jenkins jira jenkins jira
packagist pipelines_email pivotaltracker pushover packagist pipelines_email pivotaltracker pushover
mattermost mattermost_slash_commands microsoft_teams mock_ci mock_monitoring mattermost mattermost_slash_commands microsoft_teams mock_ci mock_monitoring
redmine
slack slack_slash_commands
teamcity
].to_set.freeze ].to_set.freeze
def self.renamed?(name) def self.renamed?(name)
......
...@@ -184,10 +184,10 @@ class Project < ApplicationRecord ...@@ -184,10 +184,10 @@ class Project < ApplicationRecord
has_one :pivotaltracker_integration, class_name: 'Integrations::Pivotaltracker' has_one :pivotaltracker_integration, class_name: 'Integrations::Pivotaltracker'
has_one :prometheus_service, class_name: 'Integrations::Prometheus', inverse_of: :project has_one :prometheus_service, class_name: 'Integrations::Prometheus', inverse_of: :project
has_one :pushover_integration, class_name: 'Integrations::Pushover' has_one :pushover_integration, class_name: 'Integrations::Pushover'
has_one :redmine_service, class_name: 'Integrations::Redmine' has_one :redmine_integration, class_name: 'Integrations::Redmine'
has_one :slack_service, class_name: 'Integrations::Slack' has_one :slack_integration, class_name: 'Integrations::Slack'
has_one :slack_slash_commands_service, class_name: 'Integrations::SlackSlashCommands' has_one :slack_slash_commands_integration, class_name: 'Integrations::SlackSlashCommands'
has_one :teamcity_service, class_name: 'Integrations::Teamcity' has_one :teamcity_integration, class_name: 'Integrations::Teamcity'
has_one :unify_circuit_service, class_name: 'Integrations::UnifyCircuit' has_one :unify_circuit_service, class_name: 'Integrations::UnifyCircuit'
has_one :webex_teams_service, class_name: 'Integrations::WebexTeams' has_one :webex_teams_service, class_name: 'Integrations::WebexTeams'
has_one :youtrack_service, class_name: 'Integrations::Youtrack' has_one :youtrack_service, class_name: 'Integrations::Youtrack'
......
...@@ -158,8 +158,8 @@ module EE ...@@ -158,8 +158,8 @@ module EE
joins(:project_feature).mirror.where(mirror_trigger_builds: true, joins(:project_feature).mirror.where(mirror_trigger_builds: true,
project_features: { builds_access_level: ::ProjectFeature::ENABLED }) project_features: { builds_access_level: ::ProjectFeature::ENABLED })
end end
scope :with_slack_service, -> { joins(:slack_service) } scope :with_slack_integration, -> { joins(:slack_integration) }
scope :with_slack_slash_commands_service, -> { joins(:slack_slash_commands_service) } scope :with_slack_slash_commands_integration, -> { joins(:slack_slash_commands_integration) }
scope :with_prometheus_service, -> { joins(:prometheus_service) } scope :with_prometheus_service, -> { joins(:prometheus_service) }
scope :aimed_for_deletion, -> (date) { where('marked_for_deletion_at <= ?', date).without_deleted } scope :aimed_for_deletion, -> (date) { where('marked_for_deletion_at <= ?', date).without_deleted }
scope :not_aimed_for_deletion, -> { where(marked_for_deletion_at: nil) } scope :not_aimed_for_deletion, -> { where(marked_for_deletion_at: nil) }
......
...@@ -231,8 +231,8 @@ module EE ...@@ -231,8 +231,8 @@ module EE
override :usage_activity_by_stage_configure override :usage_activity_by_stage_configure
def usage_activity_by_stage_configure(time_period) def usage_activity_by_stage_configure(time_period)
super.merge({ super.merge({
projects_slack_notifications_active: distinct_count(::Project.with_slack_service.where(time_period), :creator_id), projects_slack_notifications_active: distinct_count(::Project.with_slack_integration.where(time_period), :creator_id),
projects_slack_slash_active: distinct_count(::Project.with_slack_slash_commands_service.where(time_period), :creator_id) projects_slack_slash_active: distinct_count(::Project.with_slack_slash_commands_integration.where(time_period), :creator_id)
}) })
end end
......
...@@ -41,8 +41,8 @@ RSpec.describe EE::ServicesHelper do ...@@ -41,8 +41,8 @@ RSpec.describe EE::ServicesHelper do
assign(:project, project) assign(:project, project)
end end
context 'Slack service' do context 'with Slack integration' do
let(:integration) { build(:slack_service) } let(:integration) { build(:integrations_slack) }
it 'does not include Jira specific fields' do it 'does not include Jira specific fields' do
is_expected.not_to include(*jira_fields.keys) is_expected.not_to include(*jira_fields.keys)
......
...@@ -259,8 +259,8 @@ RSpec.describe Gitlab::UsageData do ...@@ -259,8 +259,8 @@ RSpec.describe Gitlab::UsageData do
for_defined_days_back do for_defined_days_back do
user = create(:user) user = create(:user)
project = create(:project, creator: user) project = create(:project, creator: user)
create(:slack_service, project: project) create(:integrations_slack, project: project)
create(:slack_slash_commands_service, project: project) create(:slack_slash_commands_integration, project: project)
create(:prometheus_service, project: project) create(:prometheus_service, project: project)
end end
......
...@@ -130,7 +130,9 @@ RSpec.describe Projects::ServicesController do ...@@ -130,7 +130,9 @@ RSpec.describe Projects::ServicesController do
end end
context 'with the Slack integration' do context 'with the Slack integration' do
let_it_be(:service) { build(:slack_service) } let_it_be(:integration) { build(:integrations_slack) }
let(:service) { integration } # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
it 'returns an error response when the URL is blocked' do it 'returns an error response when the URL is blocked' do
put :test, params: project_params(service: { webhook: 'http://127.0.0.1' }) put :test, params: project_params(service: { webhook: 'http://127.0.0.1' })
......
...@@ -91,7 +91,7 @@ FactoryBot.define do ...@@ -91,7 +91,7 @@ FactoryBot.define do
issue_tracker issue_tracker
end end
factory :redmine_service, class: 'Integrations::Redmine' do factory :redmine_integration, class: 'Integrations::Redmine' do
project project
active { true } active { true }
issue_tracker issue_tracker
...@@ -160,14 +160,15 @@ FactoryBot.define do ...@@ -160,14 +160,15 @@ FactoryBot.define do
password { 'my-secret-password' } password { 'my-secret-password' }
end end
factory :slack_service, class: 'Integrations::Slack' do # avoids conflict with slack_integration factory
factory :integrations_slack, class: 'Integrations::Slack' do
project project
active { true } active { true }
webhook { 'https://slack.service.url' } webhook { 'https://slack.service.url' }
type { 'SlackService' } type { 'SlackService' }
end end
factory :slack_slash_commands_service, class: 'Integrations::SlackSlashCommands' do factory :slack_slash_commands_integration, class: 'Integrations::SlackSlashCommands' do
project project
active { true } active { true }
type { 'SlackSlashCommandsService' } type { 'SlackSlashCommandsService' }
......
...@@ -396,7 +396,7 @@ FactoryBot.define do ...@@ -396,7 +396,7 @@ FactoryBot.define do
factory :redmine_project, parent: :project do factory :redmine_project, parent: :project do
has_external_issue_tracker { true } has_external_issue_tracker { true }
redmine_service redmine_integration
end end
factory :youtrack_project, parent: :project do factory :youtrack_project, parent: :project do
......
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe 'Admin visits service templates' do RSpec.describe 'Admin visits service templates' do
let(:admin) { create(:user, :admin) } let(:admin) { create(:user, :admin) }
let(:slack_service) { Integration.for_template.find { |s| s.type == 'SlackService' } } let(:slack_integration) { Integration.for_template.find { |s| s.type == 'SlackService' } }
before do before do
sign_in(admin) sign_in(admin)
...@@ -23,7 +23,7 @@ RSpec.describe 'Admin visits service templates' do ...@@ -23,7 +23,7 @@ RSpec.describe 'Admin visits service templates' do
context 'with an active service template' do context 'with an active service template' do
before do before do
create(:slack_service, :template, active: true) create(:integrations_slack, :template, active: true)
visit(admin_application_settings_services_path) visit(admin_application_settings_services_path)
end end
...@@ -33,20 +33,20 @@ RSpec.describe 'Admin visits service templates' do ...@@ -33,20 +33,20 @@ RSpec.describe 'Admin visits service templates' do
context 'without instance-level integration' do context 'without instance-level integration' do
it 'shows a link to service template' do it 'shows a link to service template' do
expect(page).to have_link('Slack', href: edit_admin_application_settings_service_path(slack_service.id)) expect(page).to have_link('Slack', href: edit_admin_application_settings_service_path(slack_integration.id))
expect(page).not_to have_link('Slack', href: edit_admin_application_settings_integration_path(slack_service)) expect(page).not_to have_link('Slack', href: edit_admin_application_settings_integration_path(slack_integration))
end end
end end
context 'with instance-level integration' do context 'with instance-level integration' do
before do before do
create(:slack_service, instance: true, project: nil) create(:integrations_slack, instance: true, project: nil)
visit(admin_application_settings_services_path) visit(admin_application_settings_services_path)
end end
it 'shows a link to instance-level integration' do it 'shows a link to instance-level integration' do
expect(page).not_to have_link('Slack', href: edit_admin_application_settings_service_path(slack_service.id)) expect(page).not_to have_link('Slack', href: edit_admin_application_settings_service_path(slack_integration.id))
expect(page).to have_link('Slack', href: edit_admin_application_settings_integration_path(slack_service)) expect(page).to have_link('Slack', href: edit_admin_application_settings_integration_path(slack_integration))
end end
end end
end end
......
...@@ -20,12 +20,12 @@ RSpec.describe 'User activates Slack notifications', :js do ...@@ -20,12 +20,12 @@ RSpec.describe 'User activates Slack notifications', :js do
end end
context 'when service is already configured' do context 'when service is already configured' do
let(:service) { Integrations::Slack.new } let(:integration) { Integrations::Slack.new }
let(:project) { create(:project, slack_service: service) } let(:project) { create(:project, slack_integration: integration) }
before do before do
service.fields integration.fields
service.update!( integration.update!(
push_channel: 1, push_channel: 1,
issue_channel: 2, issue_channel: 2,
merge_request_channel: 3, merge_request_channel: 3,
...@@ -34,7 +34,7 @@ RSpec.describe 'User activates Slack notifications', :js do ...@@ -34,7 +34,7 @@ RSpec.describe 'User activates Slack notifications', :js do
pipeline_channel: 6, pipeline_channel: 6,
wiki_page_channel: 7) wiki_page_channel: 7)
visit(edit_project_service_path(project, service)) visit(edit_project_service_path(project, integration))
end end
it 'filters events by channel' do it 'filters events by channel' do
......
...@@ -36,8 +36,8 @@ RSpec.describe ServicesHelper do ...@@ -36,8 +36,8 @@ RSpec.describe ServicesHelper do
subject { helper.integration_form_data(integration) } subject { helper.integration_form_data(integration) }
context 'Slack service' do context 'with Slack integration' do
let(:integration) { build(:slack_service) } let(:integration) { build(:integrations_slack) }
it { is_expected.to include(*fields) } it { is_expected.to include(*fields) }
it { is_expected.not_to include(*jira_fields) } it { is_expected.not_to include(*jira_fields) }
......
...@@ -118,7 +118,7 @@ RSpec.describe Banzai::Filter::References::ExternalIssueReferenceFilter do ...@@ -118,7 +118,7 @@ RSpec.describe Banzai::Filter::References::ExternalIssueReferenceFilter do
end end
context "redmine project" do context "redmine project" do
let_it_be(:service) { create(:redmine_service, project: project) } let_it_be(:integration) { create(:redmine_integration, project: project) }
before do before do
project.update!(issues_enabled: false) project.update!(issues_enabled: false)
......
...@@ -369,7 +369,7 @@ project: ...@@ -369,7 +369,7 @@ project:
- emails_on_push_integration - emails_on_push_integration
- pipelines_email_integration - pipelines_email_integration
- mattermost_slash_commands_integration - mattermost_slash_commands_integration
- slack_slash_commands_service - slack_slash_commands_integration
- irker_integration - irker_integration
- packagist_integration - packagist_integration
- pivotaltracker_integration - pivotaltracker_integration
...@@ -377,17 +377,17 @@ project: ...@@ -377,17 +377,17 @@ project:
- flowdock_integration - flowdock_integration
- assembla_integration - assembla_integration
- asana_integration - asana_integration
- slack_service - slack_integration
- microsoft_teams_integration - microsoft_teams_integration
- mattermost_integration - mattermost_integration
- hangouts_chat_integration - hangouts_chat_integration
- unify_circuit_service - unify_circuit_service
- buildkite_integration - buildkite_integration
- bamboo_integration - bamboo_integration
- teamcity_service - teamcity_integration
- pushover_integration - pushover_integration
- jira_integration - jira_integration
- redmine_service - redmine_integration
- youtrack_service - youtrack_service
- custom_issue_tracker_integration - custom_issue_tracker_integration
- bugzilla_integration - bugzilla_integration
......
...@@ -14,7 +14,7 @@ RSpec.describe HasIntegrations do ...@@ -14,7 +14,7 @@ RSpec.describe HasIntegrations do
create(:jira_integration, project: project_2, inherit_from_id: nil) create(:jira_integration, project: project_2, inherit_from_id: nil)
create(:jira_integration, group: create(:group), project: nil, inherit_from_id: nil) create(:jira_integration, group: create(:group), project: nil, inherit_from_id: nil)
create(:jira_integration, project: project_3, inherit_from_id: nil) create(:jira_integration, project: project_3, inherit_from_id: nil)
create(:slack_service, project: project_4, inherit_from_id: nil) create(:integrations_slack, project: project_4, inherit_from_id: nil)
end end
describe '.with_custom_integration_for' do describe '.with_custom_integration_for' do
......
...@@ -569,7 +569,7 @@ RSpec.describe Group do ...@@ -569,7 +569,7 @@ RSpec.describe Group do
before do before do
create(:jira_integration, group: group, project: nil) create(:jira_integration, group: group, project: nil)
create(:slack_service, group: another_group, project: nil) create(:integrations_slack, group: another_group, project: nil)
end end
it 'returns groups without integration' do it 'returns groups without integration' do
......
...@@ -70,7 +70,7 @@ RSpec.describe Integration do ...@@ -70,7 +70,7 @@ RSpec.describe Integration do
describe '.by_type' do describe '.by_type' do
let!(:service1) { create(:jira_integration) } let!(:service1) { create(:jira_integration) }
let!(:service2) { create(:jira_integration) } let!(:service2) { create(:jira_integration) }
let!(:service3) { create(:redmine_service) } let!(:service3) { create(:redmine_integration) }
subject { described_class.by_type(type) } subject { described_class.by_type(type) }
......
...@@ -19,7 +19,7 @@ RSpec.describe Integrations::SlackSlashCommands do ...@@ -19,7 +19,7 @@ RSpec.describe Integrations::SlackSlashCommands do
end end
let(:service) do let(:service) do
project.create_slack_slash_commands_service( project.create_slack_slash_commands_integration(
properties: { token: 'token' }, properties: { token: 'token' },
active: true active: true
) )
......
...@@ -10,7 +10,7 @@ RSpec.describe Integrations::Slack do ...@@ -10,7 +10,7 @@ RSpec.describe Integrations::Slack do
stub_request(:post, "https://slack.service.url/") stub_request(:post, "https://slack.service.url/")
end end
let_it_be(:slack_service) { create(:slack_service, branches_to_be_notified: 'all') } let_it_be(:slack_integration) { create(:integrations_slack, branches_to_be_notified: 'all') }
it 'uses only known events', :aggregate_failures do it 'uses only known events', :aggregate_failures do
described_class::SUPPORTED_EVENTS_FOR_USAGE_LOG.each do |action| described_class::SUPPORTED_EVENTS_FOR_USAGE_LOG.each do |action|
...@@ -26,7 +26,7 @@ RSpec.describe Integrations::Slack do ...@@ -26,7 +26,7 @@ RSpec.describe Integrations::Slack do
it 'increases the usage data counter' do it 'increases the usage data counter' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(event_name, values: user.id).and_call_original expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(event_name, values: user.id).and_call_original
slack_service.execute(data) slack_integration.execute(data)
end end
end end
...@@ -38,7 +38,7 @@ RSpec.describe Integrations::Slack do ...@@ -38,7 +38,7 @@ RSpec.describe Integrations::Slack do
it 'does not increase the usage data counter' do it 'does not increase the usage data counter' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with('i_ecosystem_slack_service_pipeline_notification', values: user.id) expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with('i_ecosystem_slack_service_pipeline_notification', values: user.id)
slack_service.execute(data) slack_integration.execute(data)
end end
end end
...@@ -126,7 +126,7 @@ RSpec.describe Integrations::Slack do ...@@ -126,7 +126,7 @@ RSpec.describe Integrations::Slack do
it 'does not increase the usage data counter' do it 'does not increase the usage data counter' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event) expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event)
slack_service.execute(data) slack_integration.execute(data)
end end
end end
end end
......
...@@ -10,7 +10,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -10,7 +10,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
let(:teamcity_full_url) { 'http://gitlab.com/teamcity/httpAuth/app/rest/builds/branch:unspecified:any,revision:123' } let(:teamcity_full_url) { 'http://gitlab.com/teamcity/httpAuth/app/rest/builds/branch:unspecified:any,revision:123' }
let(:project) { create(:project) } let(:project) { create(:project) }
subject(:service) do subject(:integration) do
described_class.create!( described_class.create!(
project: project, project: project,
properties: { properties: {
...@@ -28,14 +28,14 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -28,14 +28,14 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
end end
describe 'Validations' do describe 'Validations' do
context 'when service is active' do context 'when integration is active' do
before do before do
subject.active = true subject.active = true
end end
it { is_expected.to validate_presence_of(:build_type) } it { is_expected.to validate_presence_of(:build_type) }
it { is_expected.to validate_presence_of(:teamcity_url) } it { is_expected.to validate_presence_of(:teamcity_url) }
it_behaves_like 'issue tracker service URL attribute', :teamcity_url it_behaves_like 'issue tracker integration URL attribute', :teamcity_url
describe '#username' do describe '#username' do
it 'does not validate the presence of username if password is nil' do it 'does not validate the presence of username if password is nil' do
...@@ -66,7 +66,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -66,7 +66,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
end end
end end
context 'when service is inactive' do context 'when integration is inactive' do
before do before do
subject.active = false subject.active = false
end end
...@@ -79,71 +79,66 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -79,71 +79,66 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
end end
describe 'Callbacks' do describe 'Callbacks' do
let(:teamcity_integration) { integration }
describe 'before_update :reset_password' do describe 'before_update :reset_password' do
context 'when a password was previously set' do context 'when a password was previously set' do
it 'resets password if url changed' do it 'resets password if url changed' do
teamcity_service = service teamcity_integration.teamcity_url = 'http://gitlab1.com'
teamcity_integration.save!
teamcity_service.teamcity_url = 'http://gitlab1.com'
teamcity_service.save!
expect(teamcity_service.password).to be_nil expect(teamcity_integration.password).to be_nil
end end
it 'does not reset password if username changed' do it 'does not reset password if username changed' do
teamcity_service = service teamcity_integration.username = 'some_name'
teamcity_integration.save!
teamcity_service.username = 'some_name' expect(teamcity_integration.password).to eq('password')
teamcity_service.save!
expect(teamcity_service.password).to eq('password')
end end
it "does not reset password if new url is set together with password, even if it's the same password" do it "does not reset password if new url is set together with password, even if it's the same password" do
teamcity_service = service teamcity_integration.teamcity_url = 'http://gitlab_edited.com'
teamcity_integration.password = 'password'
teamcity_service.teamcity_url = 'http://gitlab_edited.com' teamcity_integration.save!
teamcity_service.password = 'password'
teamcity_service.save!
expect(teamcity_service.password).to eq('password') expect(teamcity_integration.password).to eq('password')
expect(teamcity_service.teamcity_url).to eq('http://gitlab_edited.com') expect(teamcity_integration.teamcity_url).to eq('http://gitlab_edited.com')
end end
end end
it 'saves password if new url is set together with password when no password was previously set' do it 'saves password if new url is set together with password when no password was previously set' do
teamcity_service = service teamcity_integration.password = nil
teamcity_service.password = nil
teamcity_service.teamcity_url = 'http://gitlab_edited.com' teamcity_integration.teamcity_url = 'http://gitlab_edited.com'
teamcity_service.password = 'password' teamcity_integration.password = 'password'
teamcity_service.save! teamcity_integration.save!
expect(teamcity_service.password).to eq('password') expect(teamcity_integration.password).to eq('password')
expect(teamcity_service.teamcity_url).to eq('http://gitlab_edited.com') expect(teamcity_integration.teamcity_url).to eq('http://gitlab_edited.com')
end end
end end
end end
describe '#build_page' do describe '#build_page' do
it 'returns the contents of the reactive cache' do it 'returns the contents of the reactive cache' do
stub_reactive_cache(service, { build_page: 'foo' }, 'sha', 'ref') stub_reactive_cache(integration, { build_page: 'foo' }, 'sha', 'ref')
expect(service.build_page('sha', 'ref')).to eq('foo') expect(integration.build_page('sha', 'ref')).to eq('foo')
end end
end end
describe '#commit_status' do describe '#commit_status' do
it 'returns the contents of the reactive cache' do it 'returns the contents of the reactive cache' do
stub_reactive_cache(service, { commit_status: 'foo' }, 'sha', 'ref') stub_reactive_cache(integration, { commit_status: 'foo' }, 'sha', 'ref')
expect(service.commit_status('sha', 'ref')).to eq('foo') expect(integration.commit_status('sha', 'ref')).to eq('foo')
end end
end end
describe '#calculate_reactive_cache' do describe '#calculate_reactive_cache' do
context 'build_page' do context 'build_page' do
subject { service.calculate_reactive_cache('123', 'unused')[:build_page] } subject { integration.calculate_reactive_cache('123', 'unused')[:build_page] }
it 'returns a specific URL when status is 500' do it 'returns a specific URL when status is 500' do
stub_request(status: 500) stub_request(status: 500)
...@@ -179,7 +174,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -179,7 +174,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
end end
context 'commit_status' do context 'commit_status' do
subject { service.calculate_reactive_cache('123', 'unused')[:commit_status] } subject { integration.calculate_reactive_cache('123', 'unused')[:commit_status] }
it 'sets commit status to :error when status is 500' do it 'sets commit status to :error when status is 500' do
stub_request(status: 500) stub_request(status: 500)
...@@ -243,25 +238,25 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -243,25 +238,25 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
it 'handles push request correctly' do it 'handles push request correctly' do
stub_post_to_build_queue(branch: 'dev-123_branch') stub_post_to_build_queue(branch: 'dev-123_branch')
expect(service.execute(data)).to include('Ok') expect(integration.execute(data)).to include('Ok')
end end
it 'returns nil when ref is blank' do it 'returns nil when ref is blank' do
data[:after] = Gitlab::Git::BLANK_SHA data[:after] = Gitlab::Git::BLANK_SHA
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
it 'returns nil when there is no content' do it 'returns nil when there is no content' do
data[:total_commits_count] = 0 data[:total_commits_count] = 0
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
it 'returns nil when a merge request is opened for the same ref' do it 'returns nil when a merge request is opened for the same ref' do
create(:merge_request, source_project: project, source_branch: 'dev-123_branch') create(:merge_request, source_project: project, source_branch: 'dev-123_branch')
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
end end
...@@ -283,26 +278,26 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -283,26 +278,26 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
it 'handles merge request correctly' do it 'handles merge request correctly' do
stub_post_to_build_queue(branch: 'dev-123_branch') stub_post_to_build_queue(branch: 'dev-123_branch')
expect(service.execute(data)).to include('Ok') expect(integration.execute(data)).to include('Ok')
end end
it 'returns nil when merge request is not opened' do it 'returns nil when merge request is not opened' do
data[:object_attributes][:state] = 'closed' data[:object_attributes][:state] = 'closed'
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
it 'returns nil unless merge request is marked as unchecked' do it 'returns nil unless merge request is marked as unchecked' do
data[:object_attributes][:merge_status] = 'can_be_merged' data[:object_attributes][:merge_status] = 'can_be_merged'
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
end end
it 'returns nil when event is not supported' do it 'returns nil when event is not supported' do
data = { object_kind: 'foo' } data = { object_kind: 'foo' }
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
end end
......
...@@ -35,7 +35,7 @@ RSpec.describe Project, factory_default: :keep do ...@@ -35,7 +35,7 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_many(:hooks) } it { is_expected.to have_many(:hooks) }
it { is_expected.to have_many(:protected_branches) } it { is_expected.to have_many(:protected_branches) }
it { is_expected.to have_many(:exported_protected_branches) } it { is_expected.to have_many(:exported_protected_branches) }
it { is_expected.to have_one(:slack_service) } it { is_expected.to have_one(:slack_integration) }
it { is_expected.to have_one(:microsoft_teams_integration) } it { is_expected.to have_one(:microsoft_teams_integration) }
it { is_expected.to have_one(:mattermost_integration) } it { is_expected.to have_one(:mattermost_integration) }
it { is_expected.to have_one(:hangouts_chat_integration) } it { is_expected.to have_one(:hangouts_chat_integration) }
...@@ -55,13 +55,13 @@ RSpec.describe Project, factory_default: :keep do ...@@ -55,13 +55,13 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_one(:pivotaltracker_integration) } it { is_expected.to have_one(:pivotaltracker_integration) }
it { is_expected.to have_one(:flowdock_integration) } it { is_expected.to have_one(:flowdock_integration) }
it { is_expected.to have_one(:assembla_integration) } it { is_expected.to have_one(:assembla_integration) }
it { is_expected.to have_one(:slack_slash_commands_service) } it { is_expected.to have_one(:slack_slash_commands_integration) }
it { is_expected.to have_one(:mattermost_slash_commands_integration) } it { is_expected.to have_one(:mattermost_slash_commands_integration) }
it { is_expected.to have_one(:buildkite_integration) } it { is_expected.to have_one(:buildkite_integration) }
it { is_expected.to have_one(:bamboo_integration) } it { is_expected.to have_one(:bamboo_integration) }
it { is_expected.to have_one(:teamcity_service) } it { is_expected.to have_one(:teamcity_integration) }
it { is_expected.to have_one(:jira_integration) } it { is_expected.to have_one(:jira_integration) }
it { is_expected.to have_one(:redmine_service) } it { is_expected.to have_one(:redmine_integration) }
it { is_expected.to have_one(:youtrack_service) } it { is_expected.to have_one(:youtrack_service) }
it { is_expected.to have_one(:custom_issue_tracker_integration) } it { is_expected.to have_one(:custom_issue_tracker_integration) }
it { is_expected.to have_one(:bugzilla_integration) } it { is_expected.to have_one(:bugzilla_integration) }
...@@ -5369,26 +5369,26 @@ RSpec.describe Project, factory_default: :keep do ...@@ -5369,26 +5369,26 @@ RSpec.describe Project, factory_default: :keep do
end end
describe '#execute_services' do describe '#execute_services' do
let(:service) { create(:slack_service, push_events: true, merge_requests_events: false, active: true) } let(:integration) { create(:integrations_slack, push_events: true, merge_requests_events: false, active: true) }
it 'executes services with the specified scope' do it 'executes integrations with the specified scope' do
data = 'any data' data = 'any data'
expect_next_found_instance_of(Integrations::Slack) do |instance| expect_next_found_instance_of(Integrations::Slack) do |instance|
expect(instance).to receive(:async_execute).with(data).once expect(instance).to receive(:async_execute).with(data).once
end end
service.project.execute_services(data, :push_hooks) integration.project.execute_services(data, :push_hooks)
end end
it 'does not execute services that don\'t match the specified scope' do it 'does not execute integration that don\'t match the specified scope' do
expect(Integrations::Slack).not_to receive(:allocate).and_wrap_original do |method| expect(Integrations::Slack).not_to receive(:allocate).and_wrap_original do |method|
method.call.tap do |instance| method.call.tap do |instance|
expect(instance).not_to receive(:async_execute) expect(instance).not_to receive(:async_execute)
end end
end end
service.project.execute_services(anything, :merge_request_hooks) integration.project.execute_services(anything, :merge_request_hooks)
end end
end end
......
...@@ -9,7 +9,7 @@ RSpec.describe 'query Jira service' do ...@@ -9,7 +9,7 @@ RSpec.describe 'query Jira service' do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:jira_integration) { create(:jira_integration, project: project) } let_it_be(:jira_integration) { create(:jira_integration, project: project) }
let_it_be(:bugzilla_integration) { create(:bugzilla_integration, project: project) } let_it_be(:bugzilla_integration) { create(:bugzilla_integration, project: project) }
let_it_be(:redmine_service) { create(:redmine_service, project: project) } let_it_be(:redmine_integration) { create(:redmine_integration, project: project) }
let(:query) do let(:query) do
%( %(
......
...@@ -239,7 +239,7 @@ RSpec.describe API::Services do ...@@ -239,7 +239,7 @@ RSpec.describe API::Services do
let(:service_name) { 'slack_slash_commands' } let(:service_name) { 'slack_slash_commands' }
before do before do
project.create_slack_slash_commands_service( project.create_slack_slash_commands_integration(
active: true, active: true,
properties: { token: 'token' } properties: { token: 'token' }
) )
......
...@@ -12,7 +12,7 @@ RSpec.describe ServiceEventEntity do ...@@ -12,7 +12,7 @@ RSpec.describe ServiceEventEntity do
end end
describe '#as_json' do describe '#as_json' do
context 'service without fields' do context 'integration without fields' do
let(:integration) { create(:emails_on_push_integration, push_events: true) } let(:integration) { create(:emails_on_push_integration, push_events: true) }
let(:event) { 'push' } let(:event) { 'push' }
...@@ -24,8 +24,8 @@ RSpec.describe ServiceEventEntity do ...@@ -24,8 +24,8 @@ RSpec.describe ServiceEventEntity do
end end
end end
context 'service with fields' do context 'integration with fields' do
let(:integration) { create(:slack_service, note_events: false, note_channel: 'note-channel') } let(:integration) { create(:integrations_slack, note_events: false, note_channel: 'note-channel') }
let(:event) { 'note' } let(:event) { 'note' }
it 'exposes correct attributes' do it 'exposes correct attributes' do
......
...@@ -20,7 +20,7 @@ RSpec.describe Admin::PropagateIntegrationService do ...@@ -20,7 +20,7 @@ RSpec.describe Admin::PropagateIntegrationService do
end end
let_it_be(:different_type_inherited_integration) do let_it_be(:different_type_inherited_integration) do
create(:redmine_service, project: project, inherit_from_id: instance_integration.id) create(:redmine_integration, project: project, inherit_from_id: instance_integration.id)
end end
context 'with inherited integration' do context 'with inherited integration' do
......
...@@ -241,7 +241,7 @@ RSpec.describe Groups::TransferService do ...@@ -241,7 +241,7 @@ RSpec.describe Groups::TransferService do
context 'when the group is allowed to be transferred' do context 'when the group is allowed to be transferred' do
let_it_be(:new_parent_group, reload: true) { create(:group, :public) } let_it_be(:new_parent_group, reload: true) { create(:group, :public) }
let_it_be(:new_parent_group_integration) { create(:slack_service, group: new_parent_group, project: nil, webhook: 'http://new-group.slack.com') } let_it_be(:new_parent_group_integration) { create(:integrations_slack, group: new_parent_group, project: nil, webhook: 'http://new-group.slack.com') }
before do before do
allow(PropagateIntegrationWorker).to receive(:perform_async) allow(PropagateIntegrationWorker).to receive(:perform_async)
...@@ -277,8 +277,8 @@ RSpec.describe Groups::TransferService do ...@@ -277,8 +277,8 @@ RSpec.describe Groups::TransferService do
let(:new_created_integration) { Integration.find_by(group: group) } let(:new_created_integration) { Integration.find_by(group: group) }
context 'with an inherited integration' do context 'with an inherited integration' do
let_it_be(:instance_integration) { create(:slack_service, :instance, webhook: 'http://project.slack.com') } let_it_be(:instance_integration) { create(:integrations_slack, :instance, webhook: 'http://project.slack.com') }
let_it_be(:group_integration) { create(:slack_service, group: group, project: nil, webhook: 'http://group.slack.com', inherit_from_id: instance_integration.id) } let_it_be(:group_integration) { create(:integrations_slack, group: group, project: nil, webhook: 'http://group.slack.com', inherit_from_id: instance_integration.id) }
it 'replaces inherited integrations', :aggregate_failures do it 'replaces inherited integrations', :aggregate_failures do
expect(new_created_integration.webhook).to eq(new_parent_group_integration.webhook) expect(new_created_integration.webhook).to eq(new_parent_group_integration.webhook)
...@@ -288,7 +288,7 @@ RSpec.describe Groups::TransferService do ...@@ -288,7 +288,7 @@ RSpec.describe Groups::TransferService do
end end
context 'with a custom integration' do context 'with a custom integration' do
let_it_be(:group_integration) { create(:slack_service, group: group, project: nil, webhook: 'http://group.slack.com') } let_it_be(:group_integration) { create(:integrations_slack, group: group, project: nil, webhook: 'http://group.slack.com') }
it 'does not updates the integrations', :aggregate_failures do it 'does not updates the integrations', :aggregate_failures do
expect { transfer_service.execute(new_parent_group) }.not_to change { group_integration.webhook } expect { transfer_service.execute(new_parent_group) }.not_to change { group_integration.webhook }
......
...@@ -7,7 +7,8 @@ RSpec.describe Integrations::Test::ProjectService do ...@@ -7,7 +7,8 @@ RSpec.describe Integrations::Test::ProjectService do
describe '#execute' do describe '#execute' do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:integration) { create(:slack_service, project: project) }
let(:integration) { create(:integrations_slack, project: project) }
let(:user) { project.owner } let(:user) { project.owner }
let(:event) { nil } let(:event) { nil }
let(:sample_data) { { data: 'sample' } } let(:sample_data) { { data: 'sample' } }
......
...@@ -7,7 +7,7 @@ RSpec.describe Projects::TransferService do ...@@ -7,7 +7,7 @@ RSpec.describe Projects::TransferService do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:group_integration) { create(:slack_service, group: group, project: nil, webhook: 'http://group.slack.com') } let_it_be(:group_integration) { create(:integrations_slack, group: group, project: nil, webhook: 'http://group.slack.com') }
let(:project) { create(:project, :repository, :legacy_storage, namespace: user.namespace) } let(:project) { create(:project, :repository, :legacy_storage, namespace: user.namespace) }
subject(:execute_transfer) { described_class.new(project, user).execute(group).tap { project.reload } } subject(:execute_transfer) { described_class.new(project, user).execute(group).tap { project.reload } }
...@@ -121,24 +121,24 @@ RSpec.describe Projects::TransferService do ...@@ -121,24 +121,24 @@ RSpec.describe Projects::TransferService do
context 'with a project integration' do context 'with a project integration' do
let_it_be_with_reload(:project) { create(:project, namespace: user.namespace) } let_it_be_with_reload(:project) { create(:project, namespace: user.namespace) }
let_it_be(:instance_integration) { create(:slack_service, :instance, webhook: 'http://project.slack.com') } let_it_be(:instance_integration) { create(:integrations_slack, :instance, webhook: 'http://project.slack.com') }
context 'with an inherited integration' do context 'with an inherited integration' do
let_it_be(:project_integration) { create(:slack_service, project: project, webhook: 'http://project.slack.com', inherit_from_id: instance_integration.id) } let_it_be(:project_integration) { create(:integrations_slack, project: project, webhook: 'http://project.slack.com', inherit_from_id: instance_integration.id) }
it 'replaces inherited integrations', :aggregate_failures do it 'replaces inherited integrations', :aggregate_failures do
execute_transfer execute_transfer
expect(project.slack_service.webhook).to eq(group_integration.webhook) expect(project.slack_integration.webhook).to eq(group_integration.webhook)
expect(Integration.count).to eq(3) expect(Integration.count).to eq(3)
end end
end end
context 'with a custom integration' do context 'with a custom integration' do
let_it_be(:project_integration) { create(:slack_service, project: project, webhook: 'http://project.slack.com') } let_it_be(:project_integration) { create(:integrations_slack, project: project, webhook: 'http://project.slack.com') }
it 'does not updates the integrations' do it 'does not updates the integrations' do
expect { execute_transfer }.not_to change { project.slack_service.webhook } expect { execute_transfer }.not_to change { project.slack_integration.webhook }
end end
end end
end end
......
...@@ -8,7 +8,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| ...@@ -8,7 +8,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name|
def execute_with_options(options) def execute_with_options(options)
receive(:new).with(webhook_url, options.merge(http_client: Integrations::SlackMattermostNotifier::HTTPClient)) receive(:new).with(webhook_url, options.merge(http_client: Integrations::SlackMattermostNotifier::HTTPClient))
.and_return(double(:slack_service).as_null_object) .and_return(double(:slack_integration).as_null_object)
end end
describe "Associations" do describe "Associations" do
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'issue tracker service URL attribute' do |url_attr| RSpec.shared_examples 'issue tracker integration URL attribute' do |url_attr|
it { is_expected.to allow_value('https://example.com').for(url_attr) } it { is_expected.to allow_value('https://example.com').for(url_attr) }
it { is_expected.not_to allow_value('example.com').for(url_attr) } it { is_expected.not_to allow_value('example.com').for(url_attr) }
...@@ -8,6 +8,12 @@ RSpec.shared_examples 'issue tracker service URL attribute' do |url_attr| ...@@ -8,6 +8,12 @@ RSpec.shared_examples 'issue tracker service URL attribute' do |url_attr|
it { is_expected.not_to allow_value('herp-and-derp').for(url_attr) } it { is_expected.not_to allow_value('herp-and-derp').for(url_attr) }
end end
# TODO: clean up:
# remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 has been completed
RSpec.shared_examples 'issue tracker service URL attribute' do |url_attr|
it_behaves_like 'issue tracker integration URL attribute', url_attr
end
RSpec.shared_examples 'allows project key on reference pattern' do |url_attr| RSpec.shared_examples 'allows project key on reference pattern' do |url_attr|
it 'allows underscores in the project name' do it 'allows underscores in the project name' do
expect(described_class.reference_pattern.match('EXT_EXT-1234')[0]).to eq 'EXT_EXT-1234' expect(described_class.reference_pattern.match('EXT_EXT-1234')[0]).to eq 'EXT_EXT-1234'
......
...@@ -15,7 +15,7 @@ RSpec.describe 'projects/services/_form' do ...@@ -15,7 +15,7 @@ RSpec.describe 'projects/services/_form' do
current_user: user, current_user: user,
can?: true, can?: true,
current_application_settings: Gitlab::CurrentSettings.current_application_settings, current_application_settings: Gitlab::CurrentSettings.current_application_settings,
integration: project.redmine_service, integration: project.redmine_integration,
request: double(referer: '/services') request: double(referer: '/services')
) )
end end
......
...@@ -8,7 +8,7 @@ RSpec.describe PropagateIntegrationGroupWorker do ...@@ -8,7 +8,7 @@ RSpec.describe PropagateIntegrationGroupWorker do
let_it_be(:another_group) { create(:group) } let_it_be(:another_group) { create(:group) }
let_it_be(:subgroup1) { create(:group, parent: group) } let_it_be(:subgroup1) { create(:group, parent: group) }
let_it_be(:subgroup2) { create(:group, parent: group) } let_it_be(:subgroup2) { create(:group, parent: group) }
let_it_be(:integration) { create(:redmine_service, :instance) } let_it_be(:integration) { create(:redmine_integration, :instance) }
let(:job_args) { [integration.id, group.id, subgroup2.id] } let(:job_args) { [integration.id, group.id, subgroup2.id] }
...@@ -22,7 +22,7 @@ RSpec.describe PropagateIntegrationGroupWorker do ...@@ -22,7 +22,7 @@ RSpec.describe PropagateIntegrationGroupWorker do
end end
context 'with a group integration' do context 'with a group integration' do
let_it_be(:integration) { create(:redmine_service, group: group, project: nil) } let_it_be(:integration) { create(:redmine_integration, group: group, project: nil) }
it 'calls to BulkCreateIntegrationService' do it 'calls to BulkCreateIntegrationService' do
expect(BulkCreateIntegrationService).to receive(:new) expect(BulkCreateIntegrationService).to receive(:new)
......
...@@ -5,8 +5,8 @@ require 'spec_helper' ...@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec.describe PropagateIntegrationInheritDescendantWorker do RSpec.describe PropagateIntegrationInheritDescendantWorker do
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:subgroup) { create(:group, parent: group) } let_it_be(:subgroup) { create(:group, parent: group) }
let_it_be(:group_integration) { create(:redmine_service, group: group, project: nil) } let_it_be(:group_integration) { create(:redmine_integration, group: group, project: nil) }
let_it_be(:subgroup_integration) { create(:redmine_service, group: subgroup, project: nil, inherit_from_id: group_integration.id) } let_it_be(:subgroup_integration) { create(:redmine_integration, group: subgroup, project: nil, inherit_from_id: group_integration.id) }
it_behaves_like 'an idempotent worker' do it_behaves_like 'an idempotent worker' do
let(:job_args) { [group_integration.id, subgroup_integration.id, subgroup_integration.id] } let(:job_args) { [group_integration.id, subgroup_integration.id, subgroup_integration.id] }
......
...@@ -4,10 +4,10 @@ require 'spec_helper' ...@@ -4,10 +4,10 @@ require 'spec_helper'
RSpec.describe PropagateIntegrationInheritWorker do RSpec.describe PropagateIntegrationInheritWorker do
describe '#perform' do describe '#perform' do
let_it_be(:integration) { create(:redmine_service, :instance) } let_it_be(:integration) { create(:redmine_integration, :instance) }
let_it_be(:integration1) { create(:redmine_service, inherit_from_id: integration.id) } let_it_be(:integration1) { create(:redmine_integration, inherit_from_id: integration.id) }
let_it_be(:integration2) { create(:bugzilla_integration, inherit_from_id: integration.id) } let_it_be(:integration2) { create(:bugzilla_integration, inherit_from_id: integration.id) }
let_it_be(:integration3) { create(:redmine_service) } let_it_be(:integration3) { create(:redmine_integration) }
it_behaves_like 'an idempotent worker' do it_behaves_like 'an idempotent worker' do
let(:job_args) { [integration.id, integration1.id, integration3.id] } let(:job_args) { [integration.id, integration1.id, integration3.id] }
......
...@@ -8,7 +8,7 @@ RSpec.describe PropagateIntegrationProjectWorker do ...@@ -8,7 +8,7 @@ RSpec.describe PropagateIntegrationProjectWorker do
let_it_be(:project1) { create(:project) } let_it_be(:project1) { create(:project) }
let_it_be(:project2) { create(:project, group: group) } let_it_be(:project2) { create(:project, group: group) }
let_it_be(:project3) { create(:project, group: group) } let_it_be(:project3) { create(:project, group: group) }
let_it_be(:integration) { create(:redmine_service, :instance) } let_it_be(:integration) { create(:redmine_integration, :instance) }
let(:job_args) { [integration.id, project1.id, project3.id] } let(:job_args) { [integration.id, project1.id, project3.id] }
...@@ -22,7 +22,7 @@ RSpec.describe PropagateIntegrationProjectWorker do ...@@ -22,7 +22,7 @@ RSpec.describe PropagateIntegrationProjectWorker do
end end
context 'with a group integration' do context 'with a group integration' do
let_it_be(:integration) { create(:redmine_service, group: group, project: nil) } let_it_be(:integration) { create(:redmine_integration, group: group, project: nil) }
it 'calls to BulkCreateIntegrationService' do it 'calls to BulkCreateIntegrationService' do
expect(BulkCreateIntegrationService).to receive(:new) expect(BulkCreateIntegrationService).to receive(:new)
......
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