Skip to content
代码片段 群组 项目
未验证 提交 bbdd32d6 编辑于 作者: Kassio Borges's avatar Kassio Borges 提交者: GitLab
浏览文件

Merge branch 'kassio/add-missing-synthetic_note_class-to-ResourceLinkEvent' into 'master'

Add missing ResourceLinkEvent#synthetic_note_class

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/156204



Merged-by: default avatarKassio Borges <kborges@gitlab.com>
Approved-by: default avatarDavid Fernandez <dfernandez@gitlab.com>
Reviewed-by: default avatarKassio Borges <kborges@gitlab.com>
Reviewed-by: default avatarDavid Fernandez <dfernandez@gitlab.com>
Co-authored-by: default avatarKassio Borges <kassioborgesm@gmail.com>
No related branches found
No related tags found
无相关合并请求
...@@ -20,8 +20,10 @@ def trigger_note_subscription_create(events: self) ...@@ -20,8 +20,10 @@ def trigger_note_subscription_create(events: self)
end end
def work_item_synthetic_system_note(events: nil) def work_item_synthetic_system_note(events: nil)
# System notes for label resource events are handled in batches, so that we have single system note for multiple return unless synthetic_note_class
# label changes.
# System notes for label resource events are handled in batches,
# so that we have single system note for multiple label changes.
if is_a?(ResourceLabelEvent) && events.present? if is_a?(ResourceLabelEvent) && events.present?
return synthetic_note_class.from_events(events, resource: work_item, resource_parent: work_item.project) return synthetic_note_class.from_events(events, resource: work_item, resource_parent: work_item.project)
end end
...@@ -29,7 +31,12 @@ def work_item_synthetic_system_note(events: nil) ...@@ -29,7 +31,12 @@ def work_item_synthetic_system_note(events: nil)
synthetic_note_class.from_event(self, resource: work_item, resource_parent: work_item.project) synthetic_note_class.from_event(self, resource: work_item, resource_parent: work_item.project)
end end
# Class used to create the even synthetic note
# If the event does not require a synthetic note the method must return false
def synthetic_note_class def synthetic_note_class
raise NoMethodError, 'must implement `synthetic_note_class` method' raise NoMethodError, <<~MESSAGE.squish
`#{self.class.name}#synthetic_note_class` method must be implemented
(return nil if event does not require a note)
MESSAGE
end end
end end
...@@ -21,7 +21,7 @@ def discussion_id ...@@ -21,7 +21,7 @@ def discussion_id
end end
def issuable def issuable
raise NoMethodError, 'must implement `issuable` method' raise NoMethodError, "`#{self.class.name}#issuable` method must be implemented"
end end
private private
......
...@@ -10,6 +10,10 @@ class ResourceLinkEvent < ResourceEvent ...@@ -10,6 +10,10 @@ class ResourceLinkEvent < ResourceEvent
add: 1, add: 1,
remove: 2 remove: 2
} }
def synthetic_note_class
nil
end
end end
end end
......
...@@ -3,17 +3,62 @@ ...@@ -3,17 +3,62 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ResourceEvent, feature_category: :team_planning, type: :model do RSpec.describe ResourceEvent, feature_category: :team_planning, type: :model do
let(:dummy_resource_label_event_class) do context 'when inheriting from ResourceEvent' do
Class.new(ResourceEvent) do context 'when it does not implement the #issuable method' do
self.table_name = 'resource_label_events' let(:dummy_resource_label_event_class) do
Class.new(ResourceEvent) do
self.table_name = 'resource_label_events'
def self.name
'DummyResourceLabelEventClass'
end
end
end
it 'raises error on not implemented `issuable` method' do
expect { dummy_resource_label_event_class.new.issuable }
.to raise_error(
NoMethodError,
"`DummyResourceLabelEventClass#issuable` method must be implemented"
)
end
end end
end
it 'raises error on not implemented `issuable` method' do context 'when it does not implement the #synthetic_note_class method' do
expect { dummy_resource_label_event_class.new.issuable }.to raise_error(NoMethodError) let(:dummy_resource_label_event_class) do
end Class.new(ResourceEvent) do
self.table_name = 'resource_label_events'
def self.name
'DummyResourceLabelEventClass'
end
def issuable
:issuable
end
end
end
it 'raises error on not implemented `synthetic_note_class` method' do it 'raises error on not implemented `issuable` method' do
expect { dummy_resource_label_event_class.new.synthetic_note_class }.to raise_error(NoMethodError) expect { dummy_resource_label_event_class.new.synthetic_note_class }
.to raise_error(NoMethodError, <<~MESSAGE.squish)
`DummyResourceLabelEventClass#synthetic_note_class` method must be implemented
(return nil if event does not require a note)
MESSAGE
end
end
it 'must implement #synthetic_note_class method', :aggregate_failures do
Dir['{ee/,}app/models/**/resource*event.rb'].each do |klass|
require(Rails.root.join(klass))
end
described_class.subclasses.each do |klass|
next if klass.abstract_class?
expect { klass.new.synthetic_note_class }
.not_to(raise_error)
end
end
end end
end end
...@@ -53,6 +53,13 @@ ...@@ -53,6 +53,13 @@
expect(events).to be_empty expect(events).to be_empty
end end
end end
describe '#synthetic_note_class' do
it 'must implement #synthetic_note_class method' do
expect { described_class.new.synthetic_note_class }
.not_to raise_error
end
end
end end
RSpec.shared_examples 'a resource event that responds to imported' do RSpec.shared_examples 'a resource event that responds to imported' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册