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

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

require 'spec_helper'

RSpec.describe Gitlab::QueryLimiting::ActiveSupportSubscriber do
  let(:transaction) { instance_double(Gitlab::QueryLimiting::Transaction, increment: true) }

  before do
    allow(Gitlab::QueryLimiting::Transaction)
      .to receive(:current)
      .and_return(transaction)
  end

  describe '#sql' do
    it 'increments the number of executed SQL queries' do
      User.count

      expect(transaction)
        .to have_received(:increment)
        .once
    end

    context 'when the query is actually a rails cache hit' do
      it 'does not increment the number of executed SQL queries' do
        ActiveRecord::Base.connection.cache do
          User.count
          User.count
        end

        expect(transaction)
          .to have_received(:increment)
          .once
      end
    end
  end
end