do not check for journals when date alert notifications

pull/11602/head
Dmitrii 2 years ago
parent f12b2f608c
commit 077b362c41
  1. 8
      app/mailers/digest_mailer.rb
  2. 2
      app/models/notification.rb
  3. 50
      spec/mailers/digest_mailer_spec.rb

@ -86,7 +86,11 @@ class DigestMailer < ApplicationMailer
def load_notifications(notification_ids)
Notification
.where(id: notification_ids)
.includes(:project, :resource, journal: %i[data attachable_journals customizable_journals])
.reject { |notification| notification.resource.nil? || notification.project.nil? || notification.journal.nil? }
.includes(:project, :resource)
.reject do |notification|
notification.resource.nil? ||
notification.project.nil? ||
(notification.journal.nil? && !notification.date_alert?)
end
end
end

@ -31,6 +31,6 @@ class Notification < ApplicationRecord
:visible
def date_alert?
reason.in?(["date_alert_start_date", "date_alert_due_date"]) || resource&.milestone?
reason.in?(["date_alert_start_date", "date_alert_due_date"])
end
end

@ -135,13 +135,6 @@ describe DigestMailer do
let!(:color) { create(:color) }
let!(:project1) { create(:project) }
let!(:recipient) { create(:user) }
let!(:work_package_journal) do
create(:work_package_journal,
journable_id: work_package.id,
version: 2,
data: build(:journal_work_package_journal,
description: 'text'))
end
let(:notifications) { [notification] }
context 'when notification_wp_start_past' do
@ -153,8 +146,7 @@ describe DigestMailer do
reason: :date_alert_start_date,
recipient:,
resource: work_package,
project: project1,
journal: work_package_journal)
project: project1)
end
it 'matches generated text' do
@ -171,8 +163,7 @@ describe DigestMailer do
reason: :date_alert_start_date,
recipient:,
resource: work_package,
project: project1,
journal: work_package_journal)
project: project1)
end
it 'matches generated text' do
@ -189,8 +180,7 @@ describe DigestMailer do
reason: :date_alert_due_date,
recipient:,
resource: work_package,
project: project1,
journal: work_package_journal)
project: project1)
end
it 'matches generated text' do
@ -207,8 +197,7 @@ describe DigestMailer do
reason: :date_alert_due_date,
recipient:,
resource: work_package,
project: project1,
journal: work_package_journal)
project: project1)
end
it 'matches generated text' do
@ -226,8 +215,7 @@ describe DigestMailer do
reason: :date_alert_due_date,
recipient:,
resource: work_package,
project: project1,
journal: work_package_journal)
project: project1)
end
it 'matches generated text' do
@ -245,8 +233,7 @@ describe DigestMailer do
reason: :date_alert_due_date,
recipient:,
resource: work_package,
project: project1,
journal: work_package_journal)
project: project1)
end
it 'matches generated text' do
@ -261,8 +248,7 @@ describe DigestMailer do
reason: :date_alert_due_date,
recipient:,
resource: work_package,
project: project1,
journal: work_package_journal)
project: project1)
end
it 'matches generated text' do
@ -279,8 +265,7 @@ describe DigestMailer do
reason: :date_alert_due_date,
recipient:,
resource: work_package,
project: project1,
journal: work_package_journal)
project: project1)
end
it 'matches generated text' do
@ -297,14 +282,29 @@ describe DigestMailer do
reason: :date_alert_due_date,
recipient:,
resource: work_package,
project: project1,
journal: work_package_journal)
project: project1)
end
it 'matches generated text' do
expect(mail_body).to have_text('Finish date is in 1 day')
end
end
context 'when notification is mentioned and no journal' do
let(:work_package) { create(:work_package, subject: 'Unset date', project: project1, due_date: nil, type: Type.first) }
let(:notification) do
create(:notification,
reason: :mentioned,
recipient:,
resource: work_package,
project: project1,
journal: nil)
end
it 'does not send the email' do
expect(mail.body).to eq("")
end
end
end
end
end

Loading…
Cancel
Save