Commit 3fc1d220 authored by Axel García's avatar Axel García

Fix EE override of Tracking.definition

parent ac138099
......@@ -20,7 +20,7 @@ module EE
definition = YAML.load_file(Rails.root.join(*events_path, "#{basename}.yml"))
super.dispatch_from_definition(definition, label: label, property: property, value: value, context: context,
self.dispatch_from_definition(definition, label: label, property: property, value: value, context: context,
project: project, user: user, namespace: namespace, **extra)
end
end
......
......@@ -2,10 +2,23 @@
require 'spec_helper'
RSpec.describe Gitlab::Tracking do
RSpec.describe ::Gitlab::Tracking do
describe '.definition' do
let_it_be(:test_definition) {{ 'category': 'category', 'action': 'action' }}
let_it_be(:filepath) { Rails.root.join('ee/config/events/filename.yml') }
before do
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:event)
end
allow_next_instance_of(Gitlab::Tracking::Destinations::Snowplow) do |instance|
allow(instance).to receive(:event)
end
allow(YAML).to receive(:load_file).with(filepath).and_return(test_definition)
end
it 'fetch EE definitions when prefixed with ee_' do
expect(YAML).to receive(:load_file).with(Rails.root.join('ee/config/events/filename.yml'))
expect(YAML).to receive(:load_file).with(filepath)
described_class.definition(+'ee_filename')
end
......
......@@ -22,6 +22,8 @@ module Gitlab
end
def dispatch_from_definition(definition, **event_data)
definition = definition.with_indifferent_access
category ||= definition[:category]
action ||= definition[:action]
......
......@@ -156,11 +156,15 @@ RSpec.describe Gitlab::Tracking do
let_it_be(:definition_action) { 'definition_action' }
let_it_be(:definition_category) { 'definition_category' }
let_it_be(:label_description) { 'definition label description' }
let_it_be(:test_definition) {{ description: 'Test definition', category: definition_category, action: definition_action }}
let_it_be(:test_definition) {{ 'category': definition_category, 'action': definition_action }}
before do
allow_any_instance_of(described_class).to receive(:event)
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow).to receive(:event)
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:event)
end
allow_next_instance_of(Gitlab::Tracking::Destinations::Snowplow) do |instance|
allow(instance).to receive(:event)
end
allow(YAML).to receive(:load_file).with(Rails.root.join('config/events/filename.yml')).and_return(test_definition)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment