BigW Consortium Gitlab

batch_worker_spec.rb 1.7 KB
Newer Older
1 2
require 'spec_helper'

3 4
describe RepositoryCheck::BatchWorker do
  subject { described_class.new }
5 6

  it 'prefers projects that have never been checked' do
7
    projects = create_list(:project, 3, created_at: 1.week.ago)
8 9
    projects[0].update_column(:last_repository_check_at, 4.months.ago)
    projects[2].update_column(:last_repository_check_at, 3.months.ago)
10 11 12 13 14

    expect(subject.perform).to eq(projects.values_at(1, 0, 2).map(&:id))
  end

  it 'sorts projects by last_repository_check_at' do
15
    projects = create_list(:project, 3, created_at: 1.week.ago)
16 17 18
    projects[0].update_column(:last_repository_check_at, 2.months.ago)
    projects[1].update_column(:last_repository_check_at, 4.months.ago)
    projects[2].update_column(:last_repository_check_at, 3.months.ago)
19 20 21 22 23

    expect(subject.perform).to eq(projects.values_at(1, 2, 0).map(&:id))
  end

  it 'excludes projects that were checked recently' do
24
    projects = create_list(:project, 3, created_at: 1.week.ago)
25
    projects[0].update_column(:last_repository_check_at, 2.days.ago)
26
    projects[1].update_column(:last_repository_check_at, 2.months.ago)
27 28 29 30
    projects[2].update_column(:last_repository_check_at, 3.days.ago)

    expect(subject.perform).to eq([projects[1].id])
  end
31 32

  it 'does nothing when repository checks are disabled' do
33
    create(:empty_project, created_at: 1.week.ago)
34 35 36 37 38
    current_settings = double('settings', repository_checks_enabled: false)
    expect(subject).to receive(:current_settings) { current_settings }

    expect(subject.perform).to eq(nil)
  end
39 40 41 42 43 44 45

  it 'skips projects created less than 24 hours ago' do
    project = create(:empty_project)
    project.update_column(:created_at, 23.hours.ago)
  
    expect(subject.perform).to eq([])
  end
46
end