summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/models/concerns/update_namespace_statistics_shared_examples.rb
blob: 255b6efa518ab29282af0d5a300299b7c1055993 (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
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

RSpec.shared_examples 'updates namespace statistics' do
  let(:namespace_statistics_name) { described_class.namespace_statistics_name }
  let(:statistic_attribute) { described_class.statistic_attribute }

  context 'when creating' do
    before do
      statistic_source.send("#{statistic_attribute}=", 10)
    end

    it 'schedules a statistic refresh' do
      expect(Groups::UpdateStatisticsWorker)
        .to receive(:perform_async)

      statistic_source.save!
    end
  end

  context 'when updating' do
    before do
      statistic_source.save!

      expect(statistic_source).to be_persisted
    end

    context 'when the statistic attribute has not changed' do
      it 'does not schedule a statistic refresh' do
        expect(Groups::UpdateStatisticsWorker)
          .not_to receive(:perform_async)

        statistic_source.update!(file_name: 'new-file-name.txt')
      end
    end

    context 'when the statistic attribute has changed' do
      it 'schedules a statistic refresh' do
        expect(Groups::UpdateStatisticsWorker)
          .to receive(:perform_async)

        statistic_source.update!(statistic_attribute => 20)
      end
    end
  end

  context 'when deleting' do
    it 'schedules a statistic refresh' do
      expect(Groups::UpdateStatisticsWorker)
        .to receive(:perform_async)

      statistic_source.destroy!
    end
  end
end