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

query_log_spec.rb « observers « migrations « database « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 34678b77a0f8074309a3db3363f9320149f59513 (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
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Gitlab::Database::Migrations::Observers::QueryLog do
  subject { described_class.new(observation, directory_path, connection) }

  let(:observation) { Gitlab::Database::Migrations::Observation.new(version: migration_version, name: migration_name) }
  let(:connection) { ActiveRecord::Migration.connection }
  let(:query) { 'select 1' }
  let(:directory_path) { Dir.mktmpdir }
  let(:migration_version) { 20210422152437 }
  let(:migration_name) { 'test' }

  after do
    FileUtils.remove_entry(directory_path)
  end

  it 'writes a file with the query log' do
    observe

    expect(File.read("#{directory_path}/migration.log")).to include(query)
  end

  it 'does not change the default logger' do
    expect { observe }.not_to change { ActiveRecord::Base.logger }
  end

  def observe
    subject.before
    connection.execute(query)
    subject.after
    subject.record
  end
end