From 5ff371f51bbb84b32c37a0adc5e05295f53fc9f9 Mon Sep 17 00:00:00 2001 From: Billy Zhou Date: Wed, 26 Sep 2018 21:33:17 +0800 Subject: [PATCH] Fixed issue #2246 - Records in Reporting not updated when single ActiveRecord can not be found (fixes #2246) --- lib/report/ticket_generic_time.rb | 6 ++-- spec/lib/report/ticket_generic_time_spec.rb | 40 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 spec/lib/report/ticket_generic_time_spec.rb diff --git a/lib/report/ticket_generic_time.rb b/lib/report/ticket_generic_time.rb index cd0a0bc59..d5c9df9ac 100644 --- a/lib/report/ticket_generic_time.rb +++ b/lib/report/ticket_generic_time.rb @@ -169,8 +169,10 @@ returns assets = {} result[:ticket_ids].each do |ticket_id| - ticket_full = Ticket.find(ticket_id) - assets = ticket_full.assets(assets) + suppress(ActiveRecord::RecordNotFound) do + ticket_full = Ticket.find(ticket_id) + assets = ticket_full.assets(assets) + end end result[:assets] = assets result diff --git a/spec/lib/report/ticket_generic_time_spec.rb b/spec/lib/report/ticket_generic_time_spec.rb new file mode 100644 index 000000000..fdc84d3f8 --- /dev/null +++ b/spec/lib/report/ticket_generic_time_spec.rb @@ -0,0 +1,40 @@ +require 'rails_helper' + +RSpec.describe Report::TicketGenericTime do + +=begin + + result = Report::TicketGenericTime.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: selector, # ticket selector to get only a collection of tickets + params: { field: 'created_at' }, + ) + +returns + + { + count: 123, + ticket_ids: [4,5,1,5,0,51,5,56,7,4], + assets: assets, + } + +=end + + describe 'items' do + + # Regression test for issue #2246 - Records in Reporting not updated when single ActiveRecord can not be found + it 'correctly handles missing tickets' do + class_double('SearchIndexBackend', selectors: { ticket_ids: [-1] } ).as_stubbed_const + + expect do + described_class.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: {}, # ticket selector to get only a collection of tickets + params: { field: 'created_at' }, + ) + end.to_not raise_error + end + end +end