Commit 10789483 authored by allison.browne's avatar allison.browne

Make tests more efficent

Make tests more efficent by updating merge train
settings only once in a number of tests
parent 89517623
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe AutoMerge::MergeTrainService do
include ExclusiveLeaseHelpers
let_it_be(:project) { create(:project, :repository) }
let_it_be(:project) { create(:project, :repository, merge_pipelines_enabled: true, merge_trains_enabled: true) }
let_it_be(:user) { create(:user) }
let(:service) { described_class.new(project, user, params) }
let(:params) { {} }
......@@ -17,7 +17,6 @@ RSpec.describe AutoMerge::MergeTrainService do
before do
project.add_maintainer(user)
project.update!(merge_pipelines_enabled: true, merge_trains_enabled: true)
allow(AutoMergeProcessWorker).to receive(:perform_async) { }
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe MergeTrains::CheckStatusService do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:project) { create(:project, :repository, merge_pipelines_enabled: true, merge_trains_enabled: true) }
let_it_be(:maintainer) { create(:user).tap { |u| project.add_maintainer(u)} }
let(:service) { described_class.new(project, maintainer) }
let(:previous_ref) { 'refs/heads/master' }
......@@ -11,7 +11,6 @@ RSpec.describe MergeTrains::CheckStatusService do
before do
stub_feature_flags(disable_merge_trains: false)
stub_licensed_features(merge_pipelines: true, merge_trains: true)
project.update!(merge_pipelines_enabled: true, merge_trains_enabled: true)
end
describe '#execute' do
......
......@@ -3,17 +3,17 @@
require 'spec_helper'
RSpec.describe MergeTrains::CreatePipelineService do
let(:project) { create(:project, :repository, :auto_devops) }
let_it_be(:project) { create(:project, :repository, :auto_devops, merge_pipelines_enabled: true, merge_trains_enabled: true) }
let_it_be(:maintainer) { create(:user) }
let(:service) { described_class.new(project, maintainer) }
let(:previous_ref) { 'refs/heads/master' }
before do
project.add_maintainer(maintainer)
project.update!(merge_pipelines_enabled: true, merge_trains_enabled: true)
stub_feature_flags(ci_disallow_to_create_merge_request_pipelines_in_target_project: false)
stub_feature_flags(disable_merge_trains: false)
stub_licensed_features(merge_pipelines: true, merge_trains: true)
project.update!(merge_pipelines_enabled: true, merge_trains_enabled: true) unless project.merge_pipelines_enabled == true && project.merge_trains_enabled == true
end
describe '#execute' do
......@@ -125,6 +125,10 @@ RSpec.describe MergeTrains::CreatePipelineService do
expect(commit.parent_ids[1]).to eq(merge_request.diff_head_sha)
expect(commit.parent_ids[0]).to eq(previous_ref_sha)
end
after do
project.repository.delete_refs(previous_ref)
end
end
context 'when previous_ref does not exist' do
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe MergeTrains::RefreshMergeRequestService do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:project) { create(:project, :repository, merge_pipelines_enabled: true, merge_trains_enabled: true) }
let_it_be(:maintainer) { create(:user) }
let(:service) { described_class.new(project, maintainer, require_recreate: require_recreate) }
let(:require_recreate) { false }
......@@ -12,7 +12,7 @@ RSpec.describe MergeTrains::RefreshMergeRequestService do
stub_feature_flags(disable_merge_trains: false)
project.add_maintainer(maintainer)
stub_licensed_features(merge_pipelines: true, merge_trains: true)
project.update!(merge_pipelines_enabled: true, merge_trains_enabled: true)
project.update!(merge_pipelines_enabled: true, merge_trains_enabled: true) unless project.merge_pipelines_enabled == true && project.merge_trains_enabled == true
end
describe '#execute' do
......@@ -90,10 +90,6 @@ RSpec.describe MergeTrains::RefreshMergeRequestService do
it_behaves_like 'drops the merge request from the merge train' do
let(:expected_reason) { 'project disabled merge trains' }
end
after do
project.update!(merge_pipelines_enabled: true)
end
end
context 'when merge trains not enabled' do
......@@ -104,10 +100,6 @@ RSpec.describe MergeTrains::RefreshMergeRequestService do
it_behaves_like 'drops the merge request from the merge train' do
let(:expected_reason) { 'project disabled merge trains' }
end
after do
project.update!(merge_pipelines_enabled: true)
end
end
context 'when merge request is not under a mergeable state' do
......
......@@ -37,6 +37,8 @@ FactoryBot.define do
# we can't assign the delegated `#ci_cd_settings` attributes directly, as the
# `#ci_cd_settings` relation needs to be created first
group_runners_enabled { nil }
merge_pipelines_enabled { nil }
merge_trains_enabled { nil }
import_status { nil }
import_jid { nil }
import_correlation_id { nil }
......@@ -77,7 +79,9 @@ FactoryBot.define do
project.group&.refresh_members_authorized_projects
# assign the delegated `#ci_cd_settings` attributes after create
project.reload.group_runners_enabled = evaluator.group_runners_enabled unless evaluator.group_runners_enabled.nil?
project.group_runners_enabled = evaluator.group_runners_enabled unless evaluator.group_runners_enabled.nil?
project.merge_pipelines_enabled = evaluator.merge_pipelines_enabled unless evaluator.merge_pipelines_enabled.nil?
project.merge_trains_enabled = evaluator.merge_trains_enabled unless evaluator.merge_trains_enabled.nil?
if evaluator.import_status
import_state = project.import_state || project.build_import_state
......
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