Skip to content
Snippets Groups Projects
Verified Commit ac3de7a0 authored by Nicolas Dular's avatar Nicolas Dular Committed by GitLab
Browse files

Merge branch 'prevent-errors-parent-rollup-dates-handler' into 'master'

Prevent errors when work item does not exist

See merge request !147032



Merged-by: Nicolas Dular's avatarNicolas Dular <ndular@gitlab.com>
Approved-by: Kassio Borges's avatarKassio Borges <kborges@gitlab.com>
Approved-by: Nicolas Dular's avatarNicolas Dular <ndular@gitlab.com>
Co-authored-by: Heinrich Lee Yu's avatarHeinrich Lee Yu <heinrich@gitlab.com>
parents adfee545 b34b747a
No related branches found
No related tags found
1 merge request!147032Prevent errors when work item does not exist
Pipeline #1220359108 passed
......@@ -25,7 +25,7 @@ def self.can_handle_update?(event)
end
def handle_event(event)
parent = ::WorkItem.find(event.data[:id])&.work_item_parent
parent = ::WorkItem.find_by_id(event.data[:id])&.work_item_parent
return if parent.blank?
::WorkItems::Widgets::RolledupDatesService::HierarchyUpdateService
......
......@@ -40,7 +40,7 @@
parent = instance_double(::WorkItem)
expect(::WorkItem)
.to receive(:find)
.to receive(:find_by_id)
.with(1)
.and_return(instance_double(::WorkItem, work_item_parent: parent))
......@@ -58,7 +58,7 @@
context "when work item does not have a parent" do
it "updates the work_item hierarchy" do
expect(::WorkItem)
.to receive(:find)
.to receive(:find_by_id)
.with(1)
.and_return(instance_double(::WorkItem, work_item_parent: nil))
......@@ -71,5 +71,15 @@
handler.handle_event(event)
end
end
context 'when the work item no longer exists' do
it 'does not raise an error' do
event = ::WorkItems::WorkItemCreatedEvent.new(data: { id: non_existing_record_id, namespace_id: 2 })
handler = described_class.new
expect { handler.handle_event(event) }.not_to raise_error
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment