Commit 68b1650f authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix timebox events to track only issue events

Also renames the hook to be more specific.
Also changes resource state event to make the hooks consistent.
parent 925ea029
......@@ -11,7 +11,7 @@ class ResourceStateEvent < ResourceEvent
# state is used for issue and merge request states.
enum state: Issue.available_states.merge(MergeRequest.available_states).merge(reopened: 5)
after_save :usage_metrics
after_create :issue_usage_metrics
def self.issuable_attrs
%i(issue merge_request).freeze
......@@ -27,7 +27,7 @@ class ResourceStateEvent < ResourceEvent
private
def usage_metrics
def issue_usage_metrics
return unless for_issue?
case state
......
......@@ -13,7 +13,7 @@ class ResourceTimeboxEvent < ResourceEvent
remove: 2
}
after_save :usage_metrics
after_create :issue_usage_metrics
def self.issuable_attrs
%i(issue merge_request).freeze
......@@ -25,7 +25,13 @@ class ResourceTimeboxEvent < ResourceEvent
private
def usage_metrics
def for_issue?
issue_id.present?
end
def issue_usage_metrics
return unless for_issue?
case self
when ResourceMilestoneEvent
Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_milestone_changed_action(author: user)
......
......@@ -6,8 +6,10 @@ module EE
private
override :usage_metrics
def usage_metrics
override :issue_usage_metrics
def issue_usage_metrics
return unless for_issue?
case self
when ResourceIterationEvent
::Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_iteration_changed_action(author: user)
......
......@@ -41,7 +41,7 @@ RSpec.describe ResourceStateEvent, type: :model do
end
context 'callbacks' do
describe '#usage_metrics' do
describe '#issue_usage_metrics' do
it 'tracks closed issues' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_closed_action)
......@@ -53,6 +53,12 @@ RSpec.describe ResourceStateEvent, type: :model do
create(described_class.name.underscore.to_sym, issue: issue, state: described_class.states[:reopened])
end
it 'does not track merge requests' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_closed_action)
create(described_class.name.underscore.to_sym, merge_request: merge_request, state: described_class.states[:closed])
end
end
end
end
......@@ -75,11 +75,17 @@ RSpec.shared_examples 'timebox resource event actions' do
end
RSpec.shared_examples 'timebox resource tracks issue metrics' do |type|
describe '#usage_metrics' do
it 'tracks usage' do
describe '#issue_usage_metrics' do
it 'tracks usage for issues' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:"track_issue_#{type}_changed_action")
create(described_class.name.underscore.to_sym, issue: create(:issue))
end
it 'does not track usage for merge requests' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:"track_issue_#{type}_changed_action")
create(described_class.name.underscore.to_sym, merge_request: create(:merge_request))
end
end
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