Fix crash when a notification is deleted while a bundle is being sent
This commit is contained in:
@@ -7,10 +7,14 @@ class Notification::BundleMailer < ApplicationMailer
|
||||
@user = bundle.user
|
||||
@bundle = bundle
|
||||
@notifications = bundle.notifications
|
||||
.preload(:card, :creator, source: [ :board, :creator ])
|
||||
.reject { |n| n.source.nil? || n.card.nil? }
|
||||
@unsubscribe_token = @user.generate_token_for(:unsubscribe)
|
||||
|
||||
if @notifications.any?
|
||||
mail \
|
||||
to: bundle.user.identity.email_address,
|
||||
subject: "Fizzy#{ " (#{ Current.account.name })" if @user.identity.accounts.many? }: New notifications"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -97,6 +97,15 @@ class Notification::BundleMailerTest < ActionMailer::TestCase
|
||||
assert_equal "#1 Fix the <code>bug</code> in production", title_link.inner_html
|
||||
end
|
||||
|
||||
test "skips notifications whose source event was deleted" do
|
||||
notification = create_notification(@user)
|
||||
notification.source.destroy
|
||||
|
||||
email = Notification::BundleMailer.notification(@bundle)
|
||||
assert_not email.respond_to?(:deliver) && email.message.is_a?(Mail::Message),
|
||||
"Should not generate a real email when all notifications are stale"
|
||||
end
|
||||
|
||||
private
|
||||
def create_notification(user, source: events(:logo_published))
|
||||
Notification.create!(user: user, creator: user, source: source, created_at: 30.minutes.ago)
|
||||
|
||||
Reference in New Issue
Block a user