blob: 56b36b3ea07ceea65aaba77f8983bdbd694a9626 (
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
RSpec.shared_examples 'database events tracking' do
describe 'events tracking' do
# required definitions:
# :record, :update_params
#
# other available attributes:
# :project, :namespace
let(:user) { nil }
let(:category) { described_class.to_s }
let(:label) { described_class.table_name }
let(:action) { "database_event_#{property}" }
let(:record_tracked_attributes) { record.attributes.slice(*described_class::SNOWPLOW_ATTRIBUTES.map(&:to_s)) }
let(:base_extra) { record_tracked_attributes.merge(project: try(:project), namespace: try(:namespace)) }
before do
allow(Gitlab::Tracking).to receive(:database_event).and_call_original
end
describe '#create' do
it_behaves_like 'Snowplow event tracking', overrides: { tracking_method: :database_event } do
subject(:create_record) { record }
let(:extra) { base_extra }
let(:property) { 'create' }
end
end
describe '#update', :freeze_time do
it_behaves_like 'Snowplow event tracking', overrides: { tracking_method: :database_event } do
subject(:update_record) { record.update!(update_params) }
let(:extra) { base_extra.merge(update_params.stringify_keys) }
let(:property) { 'update' }
end
end
describe '#destroy' do
it_behaves_like 'Snowplow event tracking', overrides: { tracking_method: :database_event } do
subject(:delete_record) { record.destroy! }
let(:extra) { base_extra }
let(:property) { 'destroy' }
end
end
end
end
|