Fixed issue #2574 - Every night tickets are updated (system need to use SLAs).

This commit is contained in:
Martin Edenhofer 2019-05-20 14:18:15 +02:00
parent 1fd0e82254
commit dd1a6c30fc
3 changed files with 34 additions and 8 deletions

View file

@ -166,9 +166,7 @@ returns
end
# sync with public_holidays
if !public_holidays
self.public_holidays = {}
end
self.public_holidays ||= {}
# remove old ical entries if feed has changed
public_holidays.each do |day, meta|
@ -180,13 +178,14 @@ returns
# sync new ical feed dates
events.each do |day, summary|
if !public_holidays[day]
public_holidays[day] = {}
end
public_holidays[day] ||= {}
# ignore if already added or changed
next if public_holidays[day].key?('active')
# entry already exists
next if summary == public_holidays[day][:summary]
# create new entry
public_holidays[day] = {
active: true,

View file

@ -4,6 +4,8 @@ class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer
observe 'sla', 'calendar'
def after_commit(record)
return if _check(record)
_rebuild(record)
end
@ -37,7 +39,7 @@ class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer
end
return true if !changed
_rebuild(record)
false
end
end

View file

@ -86,7 +86,7 @@ RSpec.describe Calendar, type: :model do
describe '#sync' do
subject(:calendar) do
create(:calendar, ical_url: Rails.root.join('test', 'data', 'calendar', 'calendar1.ics'))
create(:calendar, ical_url: Rails.root.join('test', 'data', 'calendar', 'calendar1.ics'), default: false)
end
before { travel_to Time.zone.parse('2017-08-24T01:04:44Z0') }
@ -105,6 +105,27 @@ RSpec.describe Calendar, type: :model do
expect { calendar.sync }
.not_to change { calendar.public_holidays }
end
it 'does not create a background job for escalation rebuild' do
calendar # create and sync (1 inital background job is created)
expect { calendar.sync } # a second sync right after calendar create
.to not_change { Delayed::Job.count }
end
end
context 'and current date has changed but neither public_holidays nor iCal URL have changed (past cache expiry)' do
before do
calendar # create and sync
travel 2.days
end
it 'is idempotent' do
expect { calendar.sync }
.not_to change { calendar.public_holidays }
end
it 'does not create a background job for escalation rebuild' do
expect { calendar.sync }
.not_to change { Delayed::Job.count }
end
end
context 'and current date has changed (past cache expiry)' do
@ -122,6 +143,10 @@ RSpec.describe Calendar, type: :model do
'2020-12-24' => { 'active' => true, 'summary' => 'Christmas1', 'feed' => Digest::MD5.hexdigest(calendar.ical_url) },
)
end
it 'does create a background job for escalation rebuild' do
expect { calendar.sync }.to change { Delayed::Job.count }.by(1)
end
end
context 'and iCal URL has changed' do