Welcome to mirror list, hosted at ThFree Co, Russian Federation.

periodic_recalculate_service_spec.rb « authorized_project_update « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c776e013fdf8c954d11275be80d44fce173f87b7 (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe AuthorizedProjectUpdate::PeriodicRecalculateService do
  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