BigW Consortium Gitlab

authorized_projects_worker_spec.rb 1.26 KB
Newer Older
1 2 3
require 'spec_helper'

describe AuthorizedProjectsWorker do
4
  let(:project) { create(:empty_project) }
5

6 7 8 9 10 11 12 13 14 15
  describe '.bulk_perform_and_wait' do
    it 'schedules the ids and waits for the jobs to complete' do
      project.owner.project_authorizations.delete_all

      described_class.bulk_perform_and_wait([[project.owner.id]])

      expect(project.owner.project_authorizations.count).to eq(1)
    end
  end

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  describe '.bulk_perform_async' do
    it "uses it's respective sidekiq queue" do
      args = [[project.owner.id]]
      push_bulk_args = {
        'class' => described_class,
        'queue' => described_class.sidekiq_options['queue'],
        'args' => args
      }

      expect(Sidekiq::Client).to receive(:push_bulk).with(push_bulk_args).once

      described_class.bulk_perform_async(args)
    end
  end

31
  describe '#perform' do
32 33
    subject { described_class.new }

34 35 36
    it "refreshes user's authorized projects" do
      user = create(:user)

37
      expect_any_instance_of(User).to receive(:refresh_authorized_projects)
38

39
      subject.perform(user.id)
40 41
    end

42
    context "when the user is not found" do
43
      it "does nothing" do
44
        expect_any_instance_of(User).not_to receive(:refresh_authorized_projects)
45

46
        subject.perform(-1)
47 48 49 50
      end
    end
  end
end