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

query_analyzer_spec.rb « middleware « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5ebe6a92da62f79043da077e6bed4273ad926da9 (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
55
56
57
58
59
60
61
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Middleware::QueryAnalyzer, query_analyzers: false do
  describe 'the PreventCrossDatabaseModification' do
    describe '#call' do
      let(:app) { double(:app) }
      let(:middleware) { described_class.new(app) }
      let(:env) { {} }

      subject { middleware.call(env) }

      context 'when there is a cross modification' do
        before do
          allow(app).to receive(:call) do
            Project.transaction do
              Project.where(id: -1).update_all(id: -1)
              ::Ci::Pipeline.where(id: -1).update_all(id: -1)
            end
          end
        end

        it 'detects cross modifications and tracks exception' do
          expect(::Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)

          expect { subject }.not_to raise_error
        end

        context 'when the detect_cross_database_modification is disabled' do
          before do
            stub_feature_flags(detect_cross_database_modification: false)
          end

          it 'does not detect cross modifications' do
            expect(::Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)

            subject
          end
        end
      end

      context 'when there is no cross modification' do
        before do
          allow(app).to receive(:call) do
            Project.transaction do
              Project.where(id: -1).update_all(id: -1)
              Namespace.where(id: -1).update_all(id: -1)
            end
          end
        end

        it 'does not log anything' do
          expect(::Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)

          subject
        end
      end
    end
  end
end