Commit 4cd6edf0 authored by Alex Kalderimis's avatar Alex Kalderimis

Rename slack project association to integration

Renames project association from slack_service to slack_integration.
parent affb8e23
......@@ -52,6 +52,7 @@ class Integration < ApplicationRecord
packagist pipelines_email pivotaltracker pushover
mattermost mattermost_slash_commands microsoft_teams mock_ci mock_monitoring
redmine
slack
].to_set.freeze
def self.renamed?(name)
......
......@@ -185,7 +185,7 @@ class Project < ApplicationRecord
has_one :prometheus_service, class_name: 'Integrations::Prometheus', inverse_of: :project
has_one :pushover_integration, class_name: 'Integrations::Pushover'
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 :teamcity_service, class_name: 'Integrations::Teamcity'
has_one :unify_circuit_service, class_name: 'Integrations::UnifyCircuit'
......
......@@ -158,7 +158,7 @@ module EE
joins(:project_feature).mirror.where(mirror_trigger_builds: true,
project_features: { builds_access_level: ::ProjectFeature::ENABLED })
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_prometheus_service, -> { joins(:prometheus_service) }
scope :aimed_for_deletion, -> (date) { where('marked_for_deletion_at <= ?', date).without_deleted }
......
......@@ -231,7 +231,7 @@ module EE
override :usage_activity_by_stage_configure
def usage_activity_by_stage_configure(time_period)
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)
})
end
......
......@@ -41,8 +41,8 @@ RSpec.describe EE::ServicesHelper do
assign(:project, project)
end
context 'Slack service' do
let(:integration) { build(:slack_service) }
context 'with Slack integration' do
let(:integration) { build(:slack_integration) }
it 'does not include Jira specific fields' do
is_expected.not_to include(*jira_fields.keys)
......
......@@ -259,7 +259,7 @@ RSpec.describe Gitlab::UsageData do
for_defined_days_back do
user = create(:user)
project = create(:project, creator: user)
create(:slack_service, project: project)
create(:slack_integration, project: project)
create(:slack_slash_commands_service, project: project)
create(:prometheus_service, project: project)
end
......
......@@ -130,7 +130,9 @@ RSpec.describe Projects::ServicesController do
end
context 'with the Slack integration' do
let_it_be(:service) { build(:slack_service) }
let_it_be(:integration) { build(:slack_integration) }
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
put :test, params: project_params(service: { webhook: 'http://127.0.0.1' })
......
......@@ -160,7 +160,7 @@ FactoryBot.define do
password { 'my-secret-password' }
end
factory :slack_service, class: 'Integrations::Slack' do
factory :slack_integration, class: 'Integrations::Slack' do
project
active { true }
webhook { 'https://slack.service.url' }
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe 'Admin visits service templates' do
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
sign_in(admin)
......@@ -23,7 +23,7 @@ RSpec.describe 'Admin visits service templates' do
context 'with an active service template' do
before do
create(:slack_service, :template, active: true)
create(:slack_integration, :template, active: true)
visit(admin_application_settings_services_path)
end
......@@ -33,20 +33,20 @@ RSpec.describe 'Admin visits service templates' do
context 'without instance-level integration' 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).not_to have_link('Slack', href: edit_admin_application_settings_integration_path(slack_service))
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_integration))
end
end
context 'with instance-level integration' do
before do
create(:slack_service, instance: true, project: nil)
create(:slack_integration, instance: true, project: nil)
visit(admin_application_settings_services_path)
end
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).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_service_path(slack_integration.id))
expect(page).to have_link('Slack', href: edit_admin_application_settings_integration_path(slack_integration))
end
end
end
......
......@@ -20,12 +20,12 @@ RSpec.describe 'User activates Slack notifications', :js do
end
context 'when service is already configured' do
let(:service) { Integrations::Slack.new }
let(:project) { create(:project, slack_service: service) }
let(:integration) { Integrations::Slack.new }
let(:project) { create(:project, slack_integration: integration) }
before do
service.fields
service.update!(
integration.fields
integration.update!(
push_channel: 1,
issue_channel: 2,
merge_request_channel: 3,
......@@ -34,7 +34,7 @@ RSpec.describe 'User activates Slack notifications', :js do
pipeline_channel: 6,
wiki_page_channel: 7)
visit(edit_project_service_path(project, service))
visit(edit_project_service_path(project, integration))
end
it 'filters events by channel' do
......
......@@ -36,8 +36,8 @@ RSpec.describe ServicesHelper do
subject { helper.integration_form_data(integration) }
context 'Slack service' do
let(:integration) { build(:slack_service) }
context 'with Slack integration' do
let(:integration) { build(:slack_integration) }
it { is_expected.to include(*fields) }
it { is_expected.not_to include(*jira_fields) }
......
......@@ -377,7 +377,7 @@ project:
- flowdock_integration
- assembla_integration
- asana_integration
- slack_service
- slack_integration
- microsoft_teams_integration
- mattermost_integration
- hangouts_chat_integration
......
......@@ -14,7 +14,7 @@ RSpec.describe HasIntegrations do
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, project: project_3, inherit_from_id: nil)
create(:slack_service, project: project_4, inherit_from_id: nil)
create(:slack_integration, project: project_4, inherit_from_id: nil)
end
describe '.with_custom_integration_for' do
......
......@@ -569,7 +569,7 @@ RSpec.describe Group do
before do
create(:jira_integration, group: group, project: nil)
create(:slack_service, group: another_group, project: nil)
create(:slack_integration, group: another_group, project: nil)
end
it 'returns groups without integration' do
......
......@@ -10,7 +10,7 @@ RSpec.describe Integrations::Slack do
stub_request(:post, "https://slack.service.url/")
end
let_it_be(:slack_service) { create(:slack_service, branches_to_be_notified: 'all') }
let_it_be(:slack_integration) { create(:slack_integration, branches_to_be_notified: 'all') }
it 'uses only known events', :aggregate_failures do
described_class::SUPPORTED_EVENTS_FOR_USAGE_LOG.each do |action|
......@@ -26,7 +26,7 @@ RSpec.describe Integrations::Slack 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
slack_service.execute(data)
slack_integration.execute(data)
end
end
......@@ -38,7 +38,7 @@ RSpec.describe Integrations::Slack 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)
slack_service.execute(data)
slack_integration.execute(data)
end
end
......@@ -126,7 +126,7 @@ RSpec.describe Integrations::Slack do
it 'does not increase the usage data counter' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event)
slack_service.execute(data)
slack_integration.execute(data)
end
end
end
......
......@@ -35,7 +35,7 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_many(:hooks) }
it { is_expected.to have_many(: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(:mattermost_integration) }
it { is_expected.to have_one(:hangouts_chat_integration) }
......@@ -5369,26 +5369,26 @@ RSpec.describe Project, factory_default: :keep do
end
describe '#execute_services' do
let(:service) { create(:slack_service, push_events: true, merge_requests_events: false, active: true) }
let(:integration) { create(:slack_integration, 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'
expect_next_found_instance_of(Integrations::Slack) do |instance|
expect(instance).to receive(:async_execute).with(data).once
end
service.project.execute_services(data, :push_hooks)
integration.project.execute_services(data, :push_hooks)
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|
method.call.tap do |instance|
expect(instance).not_to receive(:async_execute)
end
end
service.project.execute_services(anything, :merge_request_hooks)
integration.project.execute_services(anything, :merge_request_hooks)
end
end
......
......@@ -12,7 +12,7 @@ RSpec.describe ServiceEventEntity do
end
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(:event) { 'push' }
......@@ -24,8 +24,8 @@ RSpec.describe ServiceEventEntity do
end
end
context 'service with fields' do
let(:integration) { create(:slack_service, note_events: false, note_channel: 'note-channel') }
context 'integration with fields' do
let(:integration) { create(:slack_integration, note_events: false, note_channel: 'note-channel') }
let(:event) { 'note' }
it 'exposes correct attributes' do
......
......@@ -241,7 +241,7 @@ RSpec.describe Groups::TransferService 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_integration) { create(:slack_service, group: new_parent_group, project: nil, webhook: 'http://new-group.slack.com') }
let_it_be(:new_parent_group_integration) { create(:slack_integration, group: new_parent_group, project: nil, webhook: 'http://new-group.slack.com') }
before do
allow(PropagateIntegrationWorker).to receive(:perform_async)
......@@ -277,8 +277,8 @@ RSpec.describe Groups::TransferService do
let(:new_created_integration) { Integration.find_by(group: group) }
context 'with an inherited integration' do
let_it_be(:instance_integration) { create(:slack_service, :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(:instance_integration) { create(:slack_integration, :instance, webhook: 'http://project.slack.com') }
let_it_be(:group_integration) { create(:slack_integration, group: group, project: nil, webhook: 'http://group.slack.com', inherit_from_id: instance_integration.id) }
it 'replaces inherited integrations', :aggregate_failures do
expect(new_created_integration.webhook).to eq(new_parent_group_integration.webhook)
......@@ -288,7 +288,7 @@ RSpec.describe Groups::TransferService do
end
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(:slack_integration, group: group, project: nil, webhook: 'http://group.slack.com') }
it 'does not updates the integrations', :aggregate_failures do
expect { transfer_service.execute(new_parent_group) }.not_to change { group_integration.webhook }
......
......@@ -7,7 +7,8 @@ RSpec.describe Integrations::Test::ProjectService do
describe '#execute' do
let_it_be(:project) { create(:project) }
let(:integration) { create(:slack_service, project: project) }
let(:integration) { create(:slack_integration, project: project) }
let(:user) { project.owner }
let(:event) { nil }
let(:sample_data) { { data: 'sample' } }
......
......@@ -7,7 +7,7 @@ RSpec.describe Projects::TransferService do
let_it_be(:user) { create(:user) }
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(:slack_integration, group: group, project: nil, webhook: 'http://group.slack.com') }
let(:project) { create(:project, :repository, :legacy_storage, namespace: user.namespace) }
subject(:execute_transfer) { described_class.new(project, user).execute(group).tap { project.reload } }
......@@ -121,24 +121,24 @@ RSpec.describe Projects::TransferService do
context 'with a project integration' do
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(:slack_integration, :instance, webhook: 'http://project.slack.com') }
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(:slack_integration, project: project, webhook: 'http://project.slack.com', inherit_from_id: instance_integration.id) }
it 'replaces inherited integrations', :aggregate_failures do
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)
end
end
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(:slack_integration, project: project, webhook: 'http://project.slack.com') }
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
......
......@@ -8,7 +8,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name|
def execute_with_options(options)
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
describe "Associations" do
......
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