gitlab-org--gitlab-foss/spec/migrations/enqueue_reset_merge_status_spec.rb
Oswaldo Ferreira f3efec2029 Reset merge status from mergeable MRs
Adds migrations to reset the merge_status of opened,
mergeable MRs. That's required by
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/28513
so we're able to sync the status update along merge-ref,
without leaving MRs with a stale merge-ref.
2019-05-31 15:21:20 -03:00

49 lines
1.6 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20190528180441_enqueue_reset_merge_status.rb')
describe EnqueueResetMergeStatus, :migration, :sidekiq do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') }
let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') }
let(:merge_requests) { table(:merge_requests) }
def create_merge_request(id, extra_params = {})
params = {
id: id,
target_project_id: project.id,
target_branch: 'master',
source_project_id: project.id,
source_branch: 'mr name',
title: "mr name#{id}"
}.merge(extra_params)
merge_requests.create!(params)
end
it 'correctly schedules background migrations' do
create_merge_request(1, state: 'opened', merge_status: 'can_be_merged')
create_merge_request(2, state: 'opened', merge_status: 'can_be_merged')
create_merge_request(3, state: 'opened', merge_status: 'can_be_merged')
create_merge_request(4, state: 'merged', merge_status: 'can_be_merged')
create_merge_request(5, state: 'opened', merge_status: 'unchecked')
stub_const("#{described_class.name}::BATCH_SIZE", 2)
Sidekiq::Testing.fake! do
Timecop.freeze do
migrate!
expect(described_class::MIGRATION)
.to be_scheduled_delayed_migration(5.minutes, 1, 2)
expect(described_class::MIGRATION)
.to be_scheduled_delayed_migration(10.minutes, 3, 3)
expect(BackgroundMigrationWorker.jobs.size).to eq(2)
end
end
end
end