2020-06-22 15:09:27 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-26 09:08:59 +00:00
|
|
|
RSpec.describe AuthorizedProjectUpdate::PeriodicRecalculateService do
|
2020-06-22 15:09:27 +00:00
|
|
|
subject(:service) { described_class.new }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
let(:batch_size) { 2 }
|
|
|
|
|
|
|
|
let_it_be(:users) { create_list(:user, 4) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const('AuthorizedProjectUpdate::PeriodicRecalculateService::BATCH_SIZE', batch_size)
|
|
|
|
|
|
|
|
User.delete([users[1], users[2]])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker' do
|
|
|
|
(1..User.maximum(:id)).each_slice(batch_size).with_index do |batch, index|
|
|
|
|
delay = AuthorizedProjectUpdate::PeriodicRecalculateService::DELAY_INTERVAL * index
|
|
|
|
|
|
|
|
expect(AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker).to(
|
|
|
|
receive(:perform_in).with(delay, *batch.minmax))
|
|
|
|
end
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|