Welcome to mirror list, hosted at ThFree Co, Russian Federation.

project_stats_refresh_conflicts_helpers_spec.rb « helpers « api « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ae5c21e01c332a87e9b8f248081c82e2331c486f (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::Helpers::ProjectStatsRefreshConflictsHelpers do
  let_it_be(:project) { create(:project) }

  let(:api_class) do
    Class.new do
      include API::Helpers::ProjectStatsRefreshConflictsHelpers
    end
  end

  let(:api_controller) { api_class.new }

  describe '#reject_if_build_artifacts_size_refreshing!' do
    let(:entrypoint) { '/some/thing' }

    before do
      allow(project).to receive(:refreshing_build_artifacts_size?).and_return(refreshing)
      allow(api_controller).to receive_message_chain(:request, :path).and_return(entrypoint)
    end

    context 'when project is undergoing stats refresh' do
      let(:refreshing) { true }

      it 'logs and returns a 409 conflict error' do
        expect(Gitlab::ProjectStatsRefreshConflictsLogger)
          .to receive(:warn_request_rejected_during_stats_refresh)
          .with(project.id)

        expect(api_controller).to receive(:conflict!)

        api_controller.reject_if_build_artifacts_size_refreshing!(project)
      end
    end

    context 'when project is not undergoing stats refresh' do
      let(:refreshing) { false }

      it 'does nothing' do
        expect(Gitlab::ProjectStatsRefreshConflictsLogger).not_to receive(:warn_request_rejected_during_stats_refresh)
        expect(api_controller).not_to receive(:conflict)

        api_controller.reject_if_build_artifacts_size_refreshing!(project)
      end
    end
  end
end