summaryrefslogtreecommitdiff
path: root/spec/services/projects/update_statistics_service_spec.rb
blob: 5000ea58e5f43ef773b476d16a04908f26149b22 (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
36
37
38
39
40
41
42
# frozen_string_literal: true

require 'spec_helper'

describe Projects::UpdateStatisticsService do
  let(:service) { described_class.new(project, nil, statistics: statistics)}
  let(:statistics) { %w(repository_size) }

  describe '#execute' do
    context 'with a non-existing project' do
      let(:project) { nil }

      it 'does nothing' do
        expect_any_instance_of(ProjectStatistics).not_to receive(:refresh!)

        service.execute
      end
    end

    context 'with an existing project without a repository' do
      let(:project) { create(:project) }

      it 'does nothing' do
        expect_any_instance_of(ProjectStatistics).not_to receive(:refresh!)

        service.execute
      end
    end

    context 'with an existing project with a repository' do
      let(:project) { create(:project, :repository) }

      it 'refreshes the project statistics' do
        expect_any_instance_of(ProjectStatistics).to receive(:refresh!)
          .with(only: statistics.map(&:to_sym))
          .and_call_original

        service.execute
      end
    end
  end
end