1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200311130802_schedule_populate_user_highest_roles_table.rb')
describe SchedulePopulateUserHighestRolesTable do
let(:users) { table(:users) }
def create_user(id, params = {})
user_params = {
id: id,
state: 'active',
user_type: nil,
bot_type: nil,
ghost: nil,
email: "user#{id}@example.com",
projects_limit: 0
}.merge(params)
users.create!(user_params)
end
it 'correctly schedules background migrations' do
create_user(1)
create_user(2, state: 'blocked')
create_user(3, user_type: 2)
create_user(4)
create_user(5, bot_type: 1)
create_user(6, ghost: true)
create_user(7, ghost: false)
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, 4)
expect(described_class::MIGRATION).to be_scheduled_delayed_migration(10.minutes, 7, 7)
expect(BackgroundMigrationWorker.jobs.size).to eq(2)
end
end
end
end
|