forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: Migrated TicketOnlineNotificationSeenJob from Delayed::J…
…ob to Active Job.
- Loading branch information
1 parent
4044394
commit 953d902
Showing
5 changed files
with
46 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class TicketOnlineNotificationSeenJob < ApplicationJob | ||
def perform(ticket_id, user_id) | ||
user_id = user_id || 1 | ||
|
||
# set all online notifications to seen | ||
Transaction.execute do | ||
ticket = Ticket.lookup(id: ticket_id) | ||
OnlineNotification.list_by_object('Ticket', ticket_id).each do |notification| | ||
next if notification.seen | ||
|
||
seen = ticket.online_notification_seen_state(notification.user_id) | ||
next if !seen | ||
next if seen == notification.seen | ||
|
||
notification.seen = true | ||
notification.updated_by_id = user_id | ||
notification.save! | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
app/models/observer/ticket/online_notification_seen/background_job.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe TicketOnlineNotificationSeenJob, type: :job do | ||
let!(:user) { create(:user) } | ||
let!(:other_user) { create(:user) } | ||
let!(:ticket) { create(:ticket, owner: user, created_by_id: user.id) } | ||
let!(:online_notification) do | ||
create(:online_notification, o_id: ticket.id, user_id: user.id) | ||
end | ||
|
||
it 'checks if online notification has not been seen' do | ||
expect(online_notification.reload.seen).to be false | ||
end | ||
|
||
it 'checks if online notification has been seen' do | ||
ticket.state_id = Ticket::State.lookup(name: 'closed').id | ||
ticket.save! | ||
|
||
expect do | ||
TicketOnlineNotificationSeenJob.perform_now(ticket.id, user.id) | ||
end.to change { online_notification.reload.seen } | ||
end | ||
end |