summaryrefslogtreecommitdiff
path: root/spec/workers/project_daily_statistics_worker_spec.rb
blob: 8640add99e5d8d888d1bd1c45281f4338a74bcf2 (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
31
32
33
34
35
# frozen_string_literal: true
require 'spec_helper'

describe ProjectDailyStatisticsWorker, '#perform' do
  let(:worker) { described_class.new }
  let(:project) { create(:project) }

  describe '#perform' do
    context 'with a non-existing project' do
      it 'does nothing' do
        expect(Projects::FetchStatisticsIncrementService).not_to receive(:new)

        worker.perform(-1)
      end
    end

    context 'with an existing project without a repository' do
      it 'does nothing' do
        expect(Projects::FetchStatisticsIncrementService).not_to receive(:new)

        worker.perform(project.id)
      end
    end

    it 'calls daily_statistics_service with the given project' do
      project = create(:project, :repository)

      expect_next_instance_of(Projects::FetchStatisticsIncrementService, project) do |service|
        expect(service).to receive(:execute)
      end

      worker.perform(project.id)
    end
  end
end