Commit e3426d08 authored by Markus Koller's avatar Markus Koller

Merge branch 'issue_330446' into 'master'

Refactor specs to use `:integration` rather than `:service`

See merge request gitlab-org/gitlab!75997
parents 752e45af 2930cf7c
...@@ -32,14 +32,14 @@ RSpec.describe Integration do ...@@ -32,14 +32,14 @@ RSpec.describe Integration do
end end
describe '.vulnerability_hooks' do describe '.vulnerability_hooks' do
it 'includes services where vulnerability_events is true' do it 'includes integrations where vulnerability_events is true' do
create(:service, active: true, vulnerability_events: true) create(:integration, active: true, vulnerability_events: true)
expect(described_class.vulnerability_hooks.count).to eq 1 expect(described_class.vulnerability_hooks.count).to eq 1
end end
it 'excludes services where vulnerability_events is false' do it 'excludes integrations where vulnerability_events is false' do
create(:service, active: true, vulnerability_events: false) create(:integration, active: true, vulnerability_events: false)
expect(described_class.vulnerability_hooks.count).to eq 0 expect(described_class.vulnerability_hooks.count).to eq 0
end end
......
# frozen_string_literal: true # frozen_string_literal: true
FactoryBot.define do FactoryBot.define do
factory :integration, aliases: [:service] do factory :integration do
project project
type { 'Integration' } type { 'Integration' }
end end
......
...@@ -19,16 +19,16 @@ FactoryBot.define do ...@@ -19,16 +19,16 @@ FactoryBot.define do
create(:jira_import_state, :finished, project: projects[1], label: jira_label, imported_issues_count: 3) create(:jira_import_state, :finished, project: projects[1], label: jira_label, imported_issues_count: 3)
create(:jira_import_state, :scheduled, project: projects[1], label: jira_label) create(:jira_import_state, :scheduled, project: projects[1], label: jira_label)
create(:prometheus_integration, project: projects[1]) create(:prometheus_integration, project: projects[1])
create(:service, project: projects[1], type: 'JenkinsService', active: true) create(:integration, project: projects[1], type: 'JenkinsService', active: true)
create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true) create(:integration, project: projects[0], type: 'SlackSlashCommandsService', active: true)
create(:service, project: projects[1], type: 'SlackService', active: true) create(:integration, project: projects[1], type: 'SlackService', active: true)
create(:service, project: projects[2], type: 'SlackService', active: true) create(:integration, project: projects[2], type: 'SlackService', active: true)
create(:service, project: projects[2], type: 'MattermostService', active: false) create(:integration, project: projects[2], type: 'MattermostService', active: false)
create(:service, group: group, project: nil, type: 'MattermostService', active: true) create(:integration, group: group, project: nil, type: 'MattermostService', active: true)
mattermost_instance = create(:service, :instance, type: 'MattermostService', active: true) mattermost_instance = create(:integration, :instance, type: 'MattermostService', active: true)
create(:service, project: projects[1], type: 'MattermostService', active: true, inherit_from_id: mattermost_instance.id) create(:integration, project: projects[1], type: 'MattermostService', active: true, inherit_from_id: mattermost_instance.id)
create(:service, group: group, project: nil, type: 'SlackService', active: true, inherit_from_id: mattermost_instance.id) create(:integration, group: group, project: nil, type: 'SlackService', active: true, inherit_from_id: mattermost_instance.id)
create(:service, project: projects[2], type: 'CustomIssueTrackerService', active: true) create(:integration, project: projects[2], type: 'CustomIssueTrackerService', active: true)
create(:project_error_tracking_setting, project: projects[0]) create(:project_error_tracking_setting, project: projects[0])
create(:project_error_tracking_setting, project: projects[1], enabled: false) create(:project_error_tracking_setting, project: projects[1], enabled: false)
alert_bot_issues = create_list(:incident, 2, project: projects[0], author: User.alert_bot) alert_bot_issues = create_list(:incident, 2, project: projects[0], author: User.alert_bot)
......
...@@ -96,7 +96,7 @@ RSpec.describe 'Merge request > User sees merge widget', :js do ...@@ -96,7 +96,7 @@ RSpec.describe 'Merge request > User sees merge widget', :js do
context 'view merge request with external CI service' do context 'view merge request with external CI service' do
before do before do
create(:service, project: project, create(:integration, project: project,
active: true, active: true,
type: 'DroneCiService', type: 'DroneCiService',
category: 'ci') category: 'ci')
......
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe 'Profile > Chat' do RSpec.describe 'Profile > Chat' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:integration) { create(:service) } let(:integration) { create(:integration) }
before do before do
sign_in(user) sign_in(user)
......
...@@ -8,7 +8,7 @@ RSpec.describe Types::Projects::ServiceType do ...@@ -8,7 +8,7 @@ RSpec.describe Types::Projects::ServiceType do
describe ".resolve_type" do describe ".resolve_type" do
it 'resolves the corresponding type for objects' do it 'resolves the corresponding type for objects' do
expect(described_class.resolve_type(build(:jira_integration), {})).to eq(Types::Projects::Services::JiraServiceType) expect(described_class.resolve_type(build(:jira_integration), {})).to eq(Types::Projects::Services::JiraServiceType)
expect(described_class.resolve_type(build(:service), {})).to eq(Types::Projects::Services::BaseServiceType) expect(described_class.resolve_type(build(:integration), {})).to eq(Types::Projects::Services::BaseServiceType)
expect(described_class.resolve_type(build(:drone_ci_integration), {})).to eq(Types::Projects::Services::BaseServiceType) expect(described_class.resolve_type(build(:drone_ci_integration), {})).to eq(Types::Projects::Services::BaseServiceType)
expect(described_class.resolve_type(build(:custom_issue_tracker_integration), {})).to eq(Types::Projects::Services::BaseServiceType) expect(described_class.resolve_type(build(:custom_issue_tracker_integration), {})).to eq(Types::Projects::Services::BaseServiceType)
end end
......
...@@ -86,7 +86,7 @@ RSpec.describe AutoDevopsHelper do ...@@ -86,7 +86,7 @@ RSpec.describe AutoDevopsHelper do
context 'when another service is enabled' do context 'when another service is enabled' do
before do before do
create(:service, project: project, category: :ci, active: true) create(:integration, project: project, category: :ci, active: true)
end end
it { is_expected.to eq(false) } it { is_expected.to eq(false) }
......
...@@ -258,7 +258,7 @@ RSpec.describe Gitlab::ImportExport::FastHashSerializer do ...@@ -258,7 +258,7 @@ RSpec.describe Gitlab::ImportExport::FastHashSerializer do
create(:resource_label_event, label: group_label, merge_request: merge_request) create(:resource_label_event, label: group_label, merge_request: merge_request)
create(:event, :created, target: milestone, project: project, author: user) create(:event, :created, target: milestone, project: project, author: user)
create(:service, project: project, type: 'CustomIssueTrackerService', category: 'issue_tracker', properties: { one: 'value' }) create(:integration, project: project, type: 'CustomIssueTrackerService', category: 'issue_tracker', properties: { one: 'value' })
create(:project_custom_attribute, project: project) create(:project_custom_attribute, project: project)
create(:project_custom_attribute, project: project) create(:project_custom_attribute, project: project)
......
...@@ -88,7 +88,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_ ...@@ -88,7 +88,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_
end end
context 'original service exists' do context 'original service exists' do
let(:service_id) { create(:service, project: project).id } let(:service_id) { create(:integration, project: project).id }
it 'does not have the original service_id' do it 'does not have the original service_id' do
expect(created_object.service_id).not_to eq(service_id) expect(created_object.service_id).not_to eq(service_id)
......
...@@ -46,11 +46,11 @@ RSpec.describe Gitlab::Integrations::StiType do ...@@ -46,11 +46,11 @@ RSpec.describe Gitlab::Integrations::StiType do
SQL SQL
end end
let_it_be(:service) { create(:service) } let_it_be(:integration) { create(:integration) }
it 'forms SQL UPDATE statements correctly' do it 'forms SQL UPDATE statements correctly' do
sql_statements = types.map do |type| sql_statements = types.map do |type|
record = ActiveRecord::QueryRecorder.new { service.update_column(:type, type) } record = ActiveRecord::QueryRecorder.new { integration.update_column(:type, type) }
record.log.first record.log.first
end end
...@@ -65,8 +65,6 @@ RSpec.describe Gitlab::Integrations::StiType do ...@@ -65,8 +65,6 @@ RSpec.describe Gitlab::Integrations::StiType do
SQL SQL
end end
let(:service) { create(:service) }
it 'forms SQL DELETE statements correctly' do it 'forms SQL DELETE statements correctly' do
sql_statements = types.map do |type| sql_statements = types.map do |type|
record = ActiveRecord::QueryRecorder.new { Integration.delete_by(type: type) } record = ActiveRecord::QueryRecorder.new { Integration.delete_by(type: type) }
...@@ -81,7 +79,7 @@ RSpec.describe Gitlab::Integrations::StiType do ...@@ -81,7 +79,7 @@ RSpec.describe Gitlab::Integrations::StiType do
describe '#deserialize' do describe '#deserialize' do
specify 'it deserializes type correctly', :aggregate_failures do specify 'it deserializes type correctly', :aggregate_failures do
types.each do |type| types.each do |type|
service = create(:service, type: type) service = create(:integration, type: type)
expect(service.type).to eq('AsanaService') expect(service.type).to eq('AsanaService')
end end
...@@ -90,7 +88,7 @@ RSpec.describe Gitlab::Integrations::StiType do ...@@ -90,7 +88,7 @@ RSpec.describe Gitlab::Integrations::StiType do
describe '#cast' do describe '#cast' do
it 'casts type as model correctly', :aggregate_failures do it 'casts type as model correctly', :aggregate_failures do
create(:service, type: 'AsanaService') create(:integration, type: 'AsanaService')
types.each do |type| types.each do |type|
expect(Integration.find_by(type: type)).to be_kind_of(Integrations::Asana) expect(Integration.find_by(type: type)).to be_kind_of(Integrations::Asana)
...@@ -100,7 +98,7 @@ RSpec.describe Gitlab::Integrations::StiType do ...@@ -100,7 +98,7 @@ RSpec.describe Gitlab::Integrations::StiType do
describe '#changed?' do describe '#changed?' do
it 'detects changes correctly', :aggregate_failures do it 'detects changes correctly', :aggregate_failures do
service = create(:service, type: 'AsanaService') service = create(:integration, type: 'AsanaService')
types.each do |type| types.each do |type|
service.type = type service.type = type
......
...@@ -33,28 +33,28 @@ RSpec.describe Integration do ...@@ -33,28 +33,28 @@ RSpec.describe Integration do
end end
with_them do with_them do
it 'validates the service' do it 'validates the integration' do
expect(build(:service, project_id: project_id, group_id: group_id, instance: instance).valid?).to eq(valid) expect(build(:integration, project_id: project_id, group_id: group_id, instance: instance).valid?).to eq(valid)
end end
end end
context 'with existing services' do context 'with existing integrations' do
before_all do before_all do
create(:service, :instance) create(:integration, :instance)
create(:service, project: project) create(:integration, project: project)
create(:service, group: group, project: nil) create(:integration, group: group, project: nil)
end end
it 'allows only one instance service per type' do it 'allows only one instance integration per type' do
expect(build(:service, :instance)).to be_invalid expect(build(:integration, :instance)).to be_invalid
end end
it 'allows only one project service per type' do it 'allows only one project integration per type' do
expect(build(:service, project: project)).to be_invalid expect(build(:integration, project: project)).to be_invalid
end end
it 'allows only one group service per type' do it 'allows only one group integration per type' do
expect(build(:service, group: group, project: nil)).to be_invalid expect(build(:integration, group: group, project: nil)).to be_invalid
end end
end end
end end
...@@ -79,57 +79,57 @@ RSpec.describe Integration do ...@@ -79,57 +79,57 @@ RSpec.describe Integration do
end end
describe '.by_type' do describe '.by_type' do
let!(:service1) { create(:jira_integration) } let!(:integration1) { create(:jira_integration) }
let!(:service2) { create(:jira_integration) } let!(:integration2) { create(:jira_integration) }
let!(:service3) { create(:redmine_integration) } let!(:integration3) { create(:redmine_integration) }
subject { described_class.by_type(type) } subject { described_class.by_type(type) }
context 'when type is "JiraService"' do context 'when type is "JiraService"' do
let(:type) { 'JiraService' } let(:type) { 'JiraService' }
it { is_expected.to match_array([service1, service2]) } it { is_expected.to match_array([integration1, integration2]) }
end end
context 'when type is "RedmineService"' do context 'when type is "RedmineService"' do
let(:type) { 'RedmineService' } let(:type) { 'RedmineService' }
it { is_expected.to match_array([service3]) } it { is_expected.to match_array([integration3]) }
end end
end end
describe '.for_group' do describe '.for_group' do
let!(:service1) { create(:jira_integration, project_id: nil, group_id: group.id) } let!(:integration1) { create(:jira_integration, project_id: nil, group_id: group.id) }
let!(:service2) { create(:jira_integration) } let!(:integration2) { create(:jira_integration) }
it 'returns the right group service' do it 'returns the right group integration' do
expect(described_class.for_group(group)).to match_array([service1]) expect(described_class.for_group(group)).to match_array([integration1])
end end
end end
describe '.confidential_note_hooks' do describe '.confidential_note_hooks' do
it 'includes services where confidential_note_events is true' do it 'includes integrations where confidential_note_events is true' do
create(:service, active: true, confidential_note_events: true) create(:integration, active: true, confidential_note_events: true)
expect(described_class.confidential_note_hooks.count).to eq 1 expect(described_class.confidential_note_hooks.count).to eq 1
end end
it 'excludes services where confidential_note_events is false' do it 'excludes integrations where confidential_note_events is false' do
create(:service, active: true, confidential_note_events: false) create(:integration, active: true, confidential_note_events: false)
expect(described_class.confidential_note_hooks.count).to eq 0 expect(described_class.confidential_note_hooks.count).to eq 0
end end
end end
describe '.alert_hooks' do describe '.alert_hooks' do
it 'includes services where alert_events is true' do it 'includes integrations where alert_events is true' do
create(:service, active: true, alert_events: true) create(:integration, active: true, alert_events: true)
expect(described_class.alert_hooks.count).to eq 1 expect(described_class.alert_hooks.count).to eq 1
end end
it 'excludes services where alert_events is false' do it 'excludes integrations where alert_events is false' do
create(:service, active: true, alert_events: false) create(:integration, active: true, alert_events: false)
expect(described_class.alert_hooks.count).to eq 0 expect(described_class.alert_hooks.count).to eq 0
end end
...@@ -137,35 +137,35 @@ RSpec.describe Integration do ...@@ -137,35 +137,35 @@ RSpec.describe Integration do
end end
describe '#operating?' do describe '#operating?' do
it 'is false when the service is not active' do it 'is false when the integration is not active' do
expect(build(:service).operating?).to eq(false) expect(build(:integration).operating?).to eq(false)
end end
it 'is false when the service is not persisted' do it 'is false when the integration is not persisted' do
expect(build(:service, active: true).operating?).to eq(false) expect(build(:integration, active: true).operating?).to eq(false)
end end
it 'is true when the service is active and persisted' do it 'is true when the integration is active and persisted' do
expect(create(:service, active: true).operating?).to eq(true) expect(create(:integration, active: true).operating?).to eq(true)
end end
end end
describe '#testable?' do describe '#testable?' do
context 'when integration is project-level' do context 'when integration is project-level' do
subject { build(:service, project: project) } subject { build(:integration, project: project) }
it { is_expected.to be_testable } it { is_expected.to be_testable }
end end
context 'when integration is not project-level' do context 'when integration is not project-level' do
subject { build(:service, project: nil) } subject { build(:integration, project: nil) }
it { is_expected.not_to be_testable } it { is_expected.not_to be_testable }
end end
end end
describe '#test' do describe '#test' do
let(:integration) { build(:service, project: project) } let(:integration) { build(:integration, project: project) }
let(:data) { 'test' } let(:data) { 'test' }
it 'calls #execute' do it 'calls #execute' do
...@@ -186,32 +186,32 @@ RSpec.describe Integration do ...@@ -186,32 +186,32 @@ RSpec.describe Integration do
end end
describe '#project_level?' do describe '#project_level?' do
it 'is true when service has a project' do it 'is true when integration has a project' do
expect(build(:service, project: project)).to be_project_level expect(build(:integration, project: project)).to be_project_level
end end
it 'is false when service has no project' do it 'is false when integration has no project' do
expect(build(:service, project: nil)).not_to be_project_level expect(build(:integration, project: nil)).not_to be_project_level
end end
end end
describe '#group_level?' do describe '#group_level?' do
it 'is true when service has a group' do it 'is true when integration has a group' do
expect(build(:service, group: group)).to be_group_level expect(build(:integration, group: group)).to be_group_level
end end
it 'is false when service has no group' do it 'is false when integration has no group' do
expect(build(:service, group: nil)).not_to be_group_level expect(build(:integration, group: nil)).not_to be_group_level
end end
end end
describe '#instance_level?' do describe '#instance_level?' do
it 'is true when service has instance-level integration' do it 'is true when integration has instance-level integration' do
expect(build(:service, :instance)).to be_instance_level expect(build(:integration, :instance)).to be_instance_level
end end
it 'is false when service does not have instance-level integration' do it 'is false when integration does not have instance-level integration' do
expect(build(:service, instance: false)).not_to be_instance_level expect(build(:integration, instance: false)).not_to be_instance_level
end end
end end
...@@ -231,19 +231,19 @@ RSpec.describe Integration do ...@@ -231,19 +231,19 @@ RSpec.describe Integration do
end end
describe '.find_or_initialize_all_non_project_specific' do describe '.find_or_initialize_all_non_project_specific' do
shared_examples 'service instances' do shared_examples 'integration instances' do
it 'returns the available service instances' do it 'returns the available integration instances' do
expect(Integration.find_or_initialize_all_non_project_specific(Integration.for_instance).map(&:to_param)) expect(Integration.find_or_initialize_all_non_project_specific(Integration.for_instance).map(&:to_param))
.to match_array(Integration.available_integration_names(include_project_specific: false)) .to match_array(Integration.available_integration_names(include_project_specific: false))
end end
it 'does not create service instances' do it 'does not create integration instances' do
expect { Integration.find_or_initialize_all_non_project_specific(Integration.for_instance) } expect { Integration.find_or_initialize_all_non_project_specific(Integration.for_instance) }
.not_to change(Integration, :count) .not_to change(Integration, :count)
end end
end end
it_behaves_like 'service instances' it_behaves_like 'integration instances'
context 'with all existing instances' do context 'with all existing instances' do
before do before do
...@@ -252,15 +252,15 @@ RSpec.describe Integration do ...@@ -252,15 +252,15 @@ RSpec.describe Integration do
) )
end end
it_behaves_like 'service instances' it_behaves_like 'integration instances'
context 'with a previous existing service (MockCiService) and a new service (Asana)' do context 'with a previous existing integration (MockCiService) and a new integration (Asana)' do
before do before do
Integration.insert({ type: 'MockCiService', instance: true }) Integration.insert({ type: 'MockCiService', instance: true })
Integration.delete_by(type: 'AsanaService', instance: true) Integration.delete_by(type: 'AsanaService', instance: true)
end end
it_behaves_like 'service instances' it_behaves_like 'integration instances'
end end
end end
...@@ -269,7 +269,7 @@ RSpec.describe Integration do ...@@ -269,7 +269,7 @@ RSpec.describe Integration do
create(:jira_integration, :instance) create(:jira_integration, :instance)
end end
it_behaves_like 'service instances' it_behaves_like 'integration instances'
end end
end end
...@@ -320,31 +320,31 @@ RSpec.describe Integration do ...@@ -320,31 +320,31 @@ RSpec.describe Integration do
} }
end end
shared_examples 'service creation from an integration' do shared_examples 'integration creation from an integration' do
it 'creates a correct service for a project integration' do it 'creates a correct integration for a project integration' do
service = described_class.build_from_integration(integration, project_id: project.id) new_integration = described_class.build_from_integration(integration, project_id: project.id)
expect(service).to be_active expect(new_integration).to be_active
expect(service.url).to eq(url) expect(new_integration.url).to eq(url)
expect(service.api_url).to eq(api_url) expect(new_integration.api_url).to eq(api_url)
expect(service.username).to eq(username) expect(new_integration.username).to eq(username)
expect(service.password).to eq(password) expect(new_integration.password).to eq(password)
expect(service.instance).to eq(false) expect(new_integration.instance).to eq(false)
expect(service.project).to eq(project) expect(new_integration.project).to eq(project)
expect(service.group).to eq(nil) expect(new_integration.group).to eq(nil)
end end
it 'creates a correct service for a group integration' do it 'creates a correct integration for a group integration' do
service = described_class.build_from_integration(integration, group_id: group.id) new_integration = described_class.build_from_integration(integration, group_id: group.id)
expect(service).to be_active expect(new_integration).to be_active
expect(service.url).to eq(url) expect(new_integration.url).to eq(url)
expect(service.api_url).to eq(api_url) expect(new_integration.api_url).to eq(api_url)
expect(service.username).to eq(username) expect(new_integration.username).to eq(username)
expect(service.password).to eq(password) expect(new_integration.password).to eq(password)
expect(service.instance).to eq(false) expect(new_integration.instance).to eq(false)
expect(service.project).to eq(nil) expect(new_integration.project).to eq(nil)
expect(service.group).to eq(group) expect(new_integration.group).to eq(group)
end end
end end
...@@ -355,7 +355,7 @@ RSpec.describe Integration do ...@@ -355,7 +355,7 @@ RSpec.describe Integration do
create(:jira_integration, :without_properties_callback, properties: properties.merge(additional: 'something')) create(:jira_integration, :without_properties_callback, properties: properties.merge(additional: 'something'))
end end
it_behaves_like 'service creation from an integration' it_behaves_like 'integration creation from an integration'
end end
context 'when data are stored in separated fields' do context 'when data are stored in separated fields' do
...@@ -363,7 +363,7 @@ RSpec.describe Integration do ...@@ -363,7 +363,7 @@ RSpec.describe Integration do
create(:jira_integration, data_params.merge(properties: {})) create(:jira_integration, data_params.merge(properties: {}))
end end
it_behaves_like 'service creation from an integration' it_behaves_like 'integration creation from an integration'
end end
context 'when data are stored in both properties and separated fields' do context 'when data are stored in both properties and separated fields' do
...@@ -374,7 +374,7 @@ RSpec.describe Integration do ...@@ -374,7 +374,7 @@ RSpec.describe Integration do
end end
end end
it_behaves_like 'service creation from an integration' it_behaves_like 'integration creation from an integration'
end end
end end
end end
...@@ -565,17 +565,17 @@ RSpec.describe Integration do ...@@ -565,17 +565,17 @@ RSpec.describe Integration do
end end
describe '.integration_name_to_model' do describe '.integration_name_to_model' do
it 'returns the model for the given service name' do it 'returns the model for the given integration name' do
expect(described_class.integration_name_to_model('asana')).to eq(Integrations::Asana) expect(described_class.integration_name_to_model('asana')).to eq(Integrations::Asana)
end end
it 'raises an error if service name is invalid' do it 'raises an error if integration name is invalid' do
expect { described_class.integration_name_to_model('foo') }.to raise_exception(NameError, /uninitialized constant FooService/) expect { described_class.integration_name_to_model('foo') }.to raise_exception(NameError, /uninitialized constant FooService/)
end end
end end
describe "{property}_changed?" do describe "{property}_changed?" do
let(:service) do let(:integration) do
Integrations::Bamboo.create!( Integrations::Bamboo.create!(
project: project, project: project,
properties: { properties: {
...@@ -587,35 +587,35 @@ RSpec.describe Integration do ...@@ -587,35 +587,35 @@ RSpec.describe Integration do
end end
it "returns false when the property has not been assigned a new value" do it "returns false when the property has not been assigned a new value" do
service.username = "key_changed" integration.username = "key_changed"
expect(service.bamboo_url_changed?).to be_falsy expect(integration.bamboo_url_changed?).to be_falsy
end end
it "returns true when the property has been assigned a different value" do it "returns true when the property has been assigned a different value" do
service.bamboo_url = "http://example.com" integration.bamboo_url = "http://example.com"
expect(service.bamboo_url_changed?).to be_truthy expect(integration.bamboo_url_changed?).to be_truthy
end end
it "returns true when the property has been assigned a different value twice" do it "returns true when the property has been assigned a different value twice" do
service.bamboo_url = "http://example.com" integration.bamboo_url = "http://example.com"
service.bamboo_url = "http://example.com" integration.bamboo_url = "http://example.com"
expect(service.bamboo_url_changed?).to be_truthy expect(integration.bamboo_url_changed?).to be_truthy
end end
it "returns false when the property has been re-assigned the same value" do it "returns false when the property has been re-assigned the same value" do
service.bamboo_url = 'http://gitlab.com' integration.bamboo_url = 'http://gitlab.com'
expect(service.bamboo_url_changed?).to be_falsy expect(integration.bamboo_url_changed?).to be_falsy
end end
it "returns false when the property has been assigned a new value then saved" do it "returns false when the property has been assigned a new value then saved" do
service.bamboo_url = 'http://example.com' integration.bamboo_url = 'http://example.com'
service.save! integration.save!
expect(service.bamboo_url_changed?).to be_falsy expect(integration.bamboo_url_changed?).to be_falsy
end end
end end
describe "{property}_touched?" do describe "{property}_touched?" do
let(:service) do let(:integration) do
Integrations::Bamboo.create!( Integrations::Bamboo.create!(
project: project, project: project,
properties: { properties: {
...@@ -627,35 +627,35 @@ RSpec.describe Integration do ...@@ -627,35 +627,35 @@ RSpec.describe Integration do
end end
it "returns false when the property has not been assigned a new value" do it "returns false when the property has not been assigned a new value" do
service.username = "key_changed" integration.username = "key_changed"
expect(service.bamboo_url_touched?).to be_falsy expect(integration.bamboo_url_touched?).to be_falsy
end end
it "returns true when the property has been assigned a different value" do it "returns true when the property has been assigned a different value" do
service.bamboo_url = "http://example.com" integration.bamboo_url = "http://example.com"
expect(service.bamboo_url_touched?).to be_truthy expect(integration.bamboo_url_touched?).to be_truthy
end end
it "returns true when the property has been assigned a different value twice" do it "returns true when the property has been assigned a different value twice" do
service.bamboo_url = "http://example.com" integration.bamboo_url = "http://example.com"
service.bamboo_url = "http://example.com" integration.bamboo_url = "http://example.com"
expect(service.bamboo_url_touched?).to be_truthy expect(integration.bamboo_url_touched?).to be_truthy
end end
it "returns true when the property has been re-assigned the same value" do it "returns true when the property has been re-assigned the same value" do
service.bamboo_url = 'http://gitlab.com' integration.bamboo_url = 'http://gitlab.com'
expect(service.bamboo_url_touched?).to be_truthy expect(integration.bamboo_url_touched?).to be_truthy
end end
it "returns false when the property has been assigned a new value then saved" do it "returns false when the property has been assigned a new value then saved" do
service.bamboo_url = 'http://example.com' integration.bamboo_url = 'http://example.com'
service.save! integration.save!
expect(service.bamboo_url_changed?).to be_falsy expect(integration.bamboo_url_changed?).to be_falsy
end end
end end
describe "{property}_was" do describe "{property}_was" do
let(:service) do let(:integration) do
Integrations::Bamboo.create!( Integrations::Bamboo.create!(
project: project, project: project,
properties: { properties: {
...@@ -667,35 +667,35 @@ RSpec.describe Integration do ...@@ -667,35 +667,35 @@ RSpec.describe Integration do
end end
it "returns nil when the property has not been assigned a new value" do it "returns nil when the property has not been assigned a new value" do
service.username = "key_changed" integration.username = "key_changed"
expect(service.bamboo_url_was).to be_nil expect(integration.bamboo_url_was).to be_nil
end end
it "returns the previous value when the property has been assigned a different value" do it "returns the previous value when the property has been assigned a different value" do
service.bamboo_url = "http://example.com" integration.bamboo_url = "http://example.com"
expect(service.bamboo_url_was).to eq('http://gitlab.com') expect(integration.bamboo_url_was).to eq('http://gitlab.com')
end end
it "returns initial value when the property has been re-assigned the same value" do it "returns initial value when the property has been re-assigned the same value" do
service.bamboo_url = 'http://gitlab.com' integration.bamboo_url = 'http://gitlab.com'
expect(service.bamboo_url_was).to eq('http://gitlab.com') expect(integration.bamboo_url_was).to eq('http://gitlab.com')
end end
it "returns initial value when the property has been assigned multiple values" do it "returns initial value when the property has been assigned multiple values" do
service.bamboo_url = "http://example.com" integration.bamboo_url = "http://example.com"
service.bamboo_url = "http://example.org" integration.bamboo_url = "http://example.org"
expect(service.bamboo_url_was).to eq('http://gitlab.com') expect(integration.bamboo_url_was).to eq('http://gitlab.com')
end end
it "returns nil when the property has been assigned a new value then saved" do it "returns nil when the property has been assigned a new value then saved" do
service.bamboo_url = 'http://example.com' integration.bamboo_url = 'http://example.com'
service.save! integration.save!
expect(service.bamboo_url_was).to be_nil expect(integration.bamboo_url_was).to be_nil
end end
end end
describe 'initialize service with no properties' do describe 'initialize integration with no properties' do
let(:service) do let(:integration) do
Integrations::Bugzilla.create!( Integrations::Bugzilla.create!(
project: project, project: project,
project_url: 'http://gitlab.example.com' project_url: 'http://gitlab.example.com'
...@@ -703,16 +703,16 @@ RSpec.describe Integration do ...@@ -703,16 +703,16 @@ RSpec.describe Integration do
end end
it 'does not raise error' do it 'does not raise error' do
expect { service }.not_to raise_error expect { integration }.not_to raise_error
end end
it 'sets data correctly' do it 'sets data correctly' do
expect(service.data_fields.project_url).to eq('http://gitlab.example.com') expect(integration.data_fields.project_url).to eq('http://gitlab.example.com')
end end
end end
describe '#api_field_names' do describe '#api_field_names' do
let(:fake_service) do let(:fake_integration) do
Class.new(Integration) do Class.new(Integration) do
def fields def fields
[ [
...@@ -728,8 +728,8 @@ RSpec.describe Integration do ...@@ -728,8 +728,8 @@ RSpec.describe Integration do
end end
end end
let(:service) do let(:integration) do
fake_service.new(properties: [ fake_integration.new(properties: [
{ token: 'token-value' }, { token: 'token-value' },
{ api_token: 'api_token-value' }, { api_token: 'api_token-value' },
{ key: 'key-value' }, { key: 'key-value' },
...@@ -741,16 +741,16 @@ RSpec.describe Integration do ...@@ -741,16 +741,16 @@ RSpec.describe Integration do
end end
it 'filters out sensitive fields' do it 'filters out sensitive fields' do
expect(service.api_field_names).to eq(['safe_field']) expect(integration.api_field_names).to eq(['safe_field'])
end end
end end
context 'logging' do context 'logging' do
let(:service) { build(:service, project: project) } let(:integration) { build(:integration, project: project) }
let(:test_message) { "test message" } let(:test_message) { "test message" }
let(:arguments) do let(:arguments) do
{ {
service_class: service.class.name, service_class: integration.class.name,
project_path: project.full_path, project_path: project.full_path,
project_id: project.id, project_id: project.id,
message: test_message, message: test_message,
...@@ -761,20 +761,20 @@ RSpec.describe Integration do ...@@ -761,20 +761,20 @@ RSpec.describe Integration do
it 'logs info messages using json logger' do it 'logs info messages using json logger' do
expect(Gitlab::JsonLogger).to receive(:info).with(arguments) expect(Gitlab::JsonLogger).to receive(:info).with(arguments)
service.log_info(test_message, additional_argument: 'some argument') integration.log_info(test_message, additional_argument: 'some argument')
end end
it 'logs error messages using json logger' do it 'logs error messages using json logger' do
expect(Gitlab::JsonLogger).to receive(:error).with(arguments) expect(Gitlab::JsonLogger).to receive(:error).with(arguments)
service.log_error(test_message, additional_argument: 'some argument') integration.log_error(test_message, additional_argument: 'some argument')
end end
context 'when project is nil' do context 'when project is nil' do
let(:project) { nil } let(:project) { nil }
let(:arguments) do let(:arguments) do
{ {
service_class: service.class.name, service_class: integration.class.name,
project_path: nil, project_path: nil,
project_id: nil, project_id: nil,
message: test_message, message: test_message,
...@@ -785,7 +785,7 @@ RSpec.describe Integration do ...@@ -785,7 +785,7 @@ RSpec.describe Integration do
it 'logs info messages using json logger' do it 'logs info messages using json logger' do
expect(Gitlab::JsonLogger).to receive(:info).with(arguments) expect(Gitlab::JsonLogger).to receive(:info).with(arguments)
service.log_info(test_message, additional_argument: 'some argument') integration.log_info(test_message, additional_argument: 'some argument')
end end
end end
end end
......
...@@ -1359,51 +1359,51 @@ RSpec.describe Project, factory_default: :keep do ...@@ -1359,51 +1359,51 @@ RSpec.describe Project, factory_default: :keep do
project.reload.has_external_issue_tracker project.reload.has_external_issue_tracker
end end
it 'is false when external issue tracker service is not active' do it 'is false when external issue tracker integration is not active' do
create(:service, project: project, category: 'issue_tracker', active: false) create(:integration, project: project, category: 'issue_tracker', active: false)
is_expected.to eq(false) is_expected.to eq(false)
end end
it 'is false when other service is active' do it 'is false when other integration is active' do
create(:service, project: project, category: 'not_issue_tracker', active: true) create(:integration, project: project, category: 'not_issue_tracker', active: true)
is_expected.to eq(false) is_expected.to eq(false)
end end
context 'when there is an active external issue tracker service' do context 'when there is an active external issue tracker integration' do
let!(:service) do let!(:integration) do
create(:service, project: project, type: 'JiraService', category: 'issue_tracker', active: true) create(:integration, project: project, type: 'JiraService', category: 'issue_tracker', active: true)
end end
specify { is_expected.to eq(true) } specify { is_expected.to eq(true) }
it 'becomes false when external issue tracker service is destroyed' do it 'becomes false when external issue tracker integration is destroyed' do
expect do expect do
Integration.find(service.id).delete Integration.find(integration.id).delete
end.to change { subject }.to(false) end.to change { subject }.to(false)
end end
it 'becomes false when external issue tracker service becomes inactive' do it 'becomes false when external issue tracker integration becomes inactive' do
expect do expect do
service.update_column(:active, false) integration.update_column(:active, false)
end.to change { subject }.to(false) end.to change { subject }.to(false)
end end
context 'when there are two active external issue tracker services' do context 'when there are two active external issue tracker integrations' do
let_it_be(:second_service) do let_it_be(:second_integration) do
create(:service, project: project, type: 'CustomIssueTracker', category: 'issue_tracker', active: true) create(:integration, project: project, type: 'CustomIssueTracker', category: 'issue_tracker', active: true)
end end
it 'does not become false when external issue tracker service is destroyed' do it 'does not become false when external issue tracker integration is destroyed' do
expect do expect do
Integration.find(service.id).delete Integration.find(integration.id).delete
end.not_to change { subject } end.not_to change { subject }
end end
it 'does not become false when external issue tracker service becomes inactive' do it 'does not become false when external issue tracker integration becomes inactive' do
expect do expect do
service.update_column(:active, false) integration.update_column(:active, false)
end.not_to change { subject } end.not_to change { subject }
end end
end end
...@@ -1455,13 +1455,13 @@ RSpec.describe Project, factory_default: :keep do ...@@ -1455,13 +1455,13 @@ RSpec.describe Project, factory_default: :keep do
specify { expect(has_external_wiki).to eq(true) } specify { expect(has_external_wiki).to eq(true) }
it 'becomes false if the external wiki service is destroyed' do it 'becomes false if the external wiki integration is destroyed' do
expect do expect do
Integration.find(integration.id).delete Integration.find(integration.id).delete
end.to change { has_external_wiki }.to(false) end.to change { has_external_wiki }.to(false)
end end
it 'becomes false if the external wiki service becomes inactive' do it 'becomes false if the external wiki integration becomes inactive' do
expect do expect do
integration.update_column(:active, false) integration.update_column(:active, false)
end.to change { has_external_wiki }.to(false) end.to change { has_external_wiki }.to(false)
...@@ -6836,7 +6836,7 @@ RSpec.describe Project, factory_default: :keep do ...@@ -6836,7 +6836,7 @@ RSpec.describe Project, factory_default: :keep do
describe 'with integrations and chat names' do describe 'with integrations and chat names' do
subject { create(:project) } subject { create(:project) }
let(:integration) { create(:service, project: subject) } let(:integration) { create(:integration, project: subject) }
before do before do
create_list(:chat_name, 5, integration: integration) create_list(:chat_name, 5, integration: integration)
......
...@@ -4,10 +4,10 @@ require 'spec_helper' ...@@ -4,10 +4,10 @@ require 'spec_helper'
RSpec.describe ChatNames::AuthorizeUserService do RSpec.describe ChatNames::AuthorizeUserService do
describe '#execute' do describe '#execute' do
subject { described_class.new(service, params) } let(:integration) { create(:integration) }
let(:result) { subject.execute } let(:result) { subject.execute }
let(:service) { create(:service) }
subject { described_class.new(integration, params) }
context 'when all parameters are valid' do context 'when all parameters are valid' do
let(:params) { { team_id: 'T0001', team_domain: 'myteam', user_id: 'U0001', user_name: 'user' } } let(:params) { { team_id: 'T0001', team_domain: 'myteam', user_id: 'U0001', user_name: 'user' } }
......
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe ChatNames::FindUserService, :clean_gitlab_redis_shared_state do RSpec.describe ChatNames::FindUserService, :clean_gitlab_redis_shared_state do
describe '#execute' do describe '#execute' do
let(:integration) { create(:service) } let(:integration) { create(:integration) }
subject { described_class.new(integration, params).execute } subject { described_class.new(integration, params).execute }
......
...@@ -44,7 +44,7 @@ module ExportFileHelper ...@@ -44,7 +44,7 @@ module ExportFileHelper
create(:ci_trigger, project: project) create(:ci_trigger, project: project)
key = create(:deploy_key) key = create(:deploy_key)
key.projects << project key.projects << project
create(:service, project: project) create(:integration, project: project)
create(:project_hook, project: project, token: 'token') create(:project_hook, project: project, token: 'token')
create(:protected_branch, project: project) create(:protected_branch, project: project)
......
...@@ -13,7 +13,7 @@ RSpec.describe Deployments::HooksWorker do ...@@ -13,7 +13,7 @@ RSpec.describe Deployments::HooksWorker do
it 'executes project services for deployment_hooks' do it 'executes project services for deployment_hooks' do
deployment = create(:deployment, :running) deployment = create(:deployment, :running)
project = deployment.project project = deployment.project
service = create(:service, type: 'SlackService', project: project, deployment_events: true, active: true) service = create(:integration, type: 'SlackService', project: project, deployment_events: true, active: true)
expect(ProjectServiceWorker).to receive(:perform_async).with(service.id, an_instance_of(Hash)) expect(ProjectServiceWorker).to receive(:perform_async).with(service.id, an_instance_of(Hash))
...@@ -23,7 +23,7 @@ RSpec.describe Deployments::HooksWorker do ...@@ -23,7 +23,7 @@ RSpec.describe Deployments::HooksWorker do
it 'does not execute an inactive service' do it 'does not execute an inactive service' do
deployment = create(:deployment, :running) deployment = create(:deployment, :running)
project = deployment.project project = deployment.project
create(:service, type: 'SlackService', project: project, deployment_events: true, active: false) create(:integration, type: 'SlackService', project: project, deployment_events: true, active: false)
expect(ProjectServiceWorker).not_to receive(:perform_async) expect(ProjectServiceWorker).not_to receive(:perform_async)
......
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