2020-01-17 16:08:29 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('db', 'post_migrate', '20190924152703_migrate_issue_trackers_data.rb')
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe MigrateIssueTrackersData do
|
2020-01-17 16:08:29 -05:00
|
|
|
let(:services) { table(:services) }
|
|
|
|
let(:migration_class) { Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData }
|
|
|
|
let(:migration_name) { migration_class.to_s.demodulize }
|
|
|
|
|
|
|
|
let(:properties) do
|
|
|
|
{
|
|
|
|
'url' => 'http://example.com'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let!(:jira_service) do
|
2020-02-06 13:08:54 -05:00
|
|
|
services.create(type: 'JiraService', properties: properties, category: 'issue_tracker')
|
2020-01-17 16:08:29 -05:00
|
|
|
end
|
|
|
|
let!(:jira_service_nil) do
|
2020-02-06 13:08:54 -05:00
|
|
|
services.create(type: 'JiraService', properties: nil, category: 'issue_tracker')
|
2020-01-17 16:08:29 -05:00
|
|
|
end
|
|
|
|
let!(:bugzilla_service) do
|
2020-02-06 13:08:54 -05:00
|
|
|
services.create(type: 'BugzillaService', properties: properties, category: 'issue_tracker')
|
2020-01-17 16:08:29 -05:00
|
|
|
end
|
|
|
|
let!(:youtrack_service) do
|
2020-02-06 13:08:54 -05:00
|
|
|
services.create(type: 'YoutrackService', properties: properties, category: 'issue_tracker')
|
2020-01-17 16:08:29 -05:00
|
|
|
end
|
|
|
|
let!(:youtrack_service_empty) do
|
2020-02-06 13:08:54 -05:00
|
|
|
services.create(type: 'YoutrackService', properties: '', category: 'issue_tracker')
|
2020-01-17 16:08:29 -05:00
|
|
|
end
|
|
|
|
let!(:gitlab_service) do
|
2020-02-06 13:08:54 -05:00
|
|
|
services.create(type: 'GitlabIssueTrackerService', properties: properties, category: 'issue_tracker')
|
2020-01-17 16:08:29 -05:00
|
|
|
end
|
|
|
|
let!(:gitlab_service_empty) do
|
2020-02-06 13:08:54 -05:00
|
|
|
services.create(type: 'GitlabIssueTrackerService', properties: {}, category: 'issue_tracker')
|
2020-01-17 16:08:29 -05:00
|
|
|
end
|
|
|
|
let!(:other_service) do
|
2020-02-06 13:08:54 -05:00
|
|
|
services.create(type: 'OtherService', properties: properties, category: 'other_category')
|
2020-01-17 16:08:29 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const("#{described_class}::BATCH_SIZE", 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'schedules background migrations at correct time' do
|
|
|
|
Sidekiq::Testing.fake! do
|
|
|
|
Timecop.freeze do
|
|
|
|
migrate!
|
|
|
|
|
|
|
|
expect(migration_name).to be_scheduled_delayed_migration(3.minutes, jira_service.id, bugzilla_service.id)
|
|
|
|
expect(migration_name).to be_scheduled_delayed_migration(6.minutes, youtrack_service.id, gitlab_service.id)
|
|
|
|
expect(BackgroundMigrationWorker.jobs.size).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|