2020-04-28 17:09:35 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('db', 'post_migrate', '20200420094444_backfill_snippet_repositories.rb')
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe BackfillSnippetRepositories do
|
2020-04-28 17:09:35 -04:00
|
|
|
let(:users) { table(:users) }
|
|
|
|
let(:snippets) { table(:snippets) }
|
|
|
|
let(:user) { users.create(id: 1, email: 'user@example.com', projects_limit: 10, username: 'test', name: 'Test', state: 'active') }
|
|
|
|
|
|
|
|
def create_snippet(id)
|
|
|
|
params = {
|
|
|
|
id: id,
|
|
|
|
type: 'PersonalSnippet',
|
|
|
|
author_id: user.id,
|
|
|
|
file_name: 'foo',
|
|
|
|
content: 'bar'
|
|
|
|
}
|
|
|
|
|
|
|
|
snippets.create!(params)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly schedules background migrations' do
|
|
|
|
create_snippet(1)
|
|
|
|
create_snippet(2)
|
|
|
|
create_snippet(3)
|
|
|
|
|
|
|
|
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(3.minutes, 1, 2)
|
|
|
|
|
|
|
|
expect(described_class::MIGRATION)
|
|
|
|
.to be_scheduled_delayed_migration(6.minutes, 3, 3)
|
|
|
|
|
|
|
|
expect(BackgroundMigrationWorker.jobs.size).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|