blob: 2e70a85fd5b5287a80c8d9467751d593debf6a11 (
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) }
let(:observation) { Gitlab::Database::Migrations::Observation.new(migration_version, migration_name) }
let(:connection) { ActiveRecord::Base.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_version}_#{migration_name}.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
|