2018-09-06 19:20:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe AutoDevops::DisableWorker, '#perform' do
|
2019-04-11 15:21:18 +00:00
|
|
|
let(:user) { create(:user, developer_projects: [project]) }
|
2018-09-06 19:20:42 +00:00
|
|
|
let(:project) { create(:project, :repository, :auto_devops) }
|
|
|
|
let(:auto_devops) { project.auto_devops }
|
|
|
|
let(:pipeline) { create(:ci_pipeline, :failed, :auto_devops_source, project: project, user: user) }
|
|
|
|
|
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
before do
|
2019-04-11 15:21:18 +00:00
|
|
|
project.add_developer(user)
|
2018-09-06 19:20:42 +00:00
|
|
|
stub_application_setting(auto_devops_enabled: true)
|
|
|
|
auto_devops.update_attribute(:enabled, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disables auto devops for project' do
|
|
|
|
subject.perform(pipeline.id)
|
|
|
|
|
|
|
|
expect(auto_devops.reload.enabled).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project owner is a user' do
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
let(:namespace) { create(:namespace, owner: owner) }
|
|
|
|
let(:project) { create(:project, :repository, :auto_devops, namespace: namespace) }
|
|
|
|
|
|
|
|
it 'sends an email to pipeline user and project owner' do
|
|
|
|
expect(NotificationService).to receive_message_chain(:new, :autodevops_disabled).with(pipeline, [user.email, owner.email])
|
|
|
|
|
|
|
|
subject.perform(pipeline.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project does not have owner' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, :repository, :auto_devops, namespace: group) }
|
|
|
|
|
|
|
|
it 'sends an email to pipeline user' do
|
|
|
|
expect(NotificationService).to receive_message_chain(:new, :autodevops_disabled).with(pipeline, [user.email])
|
|
|
|
|
|
|
|
subject.perform(pipeline.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline is not related to a user and project does not have owner' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, :repository, :auto_devops, namespace: group) }
|
|
|
|
let(:pipeline) { create(:ci_pipeline, :failed, project: project) }
|
|
|
|
|
|
|
|
it 'does not send an email' do
|
|
|
|
expect(NotificationService).not_to receive(:new)
|
|
|
|
|
|
|
|
subject.perform(pipeline.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|