From 89f41f823683b7c7eb5d3e7e23470788320476f2 Mon Sep 17 00:00:00 2001 From: Leo McArdle Date: Sun, 11 Mar 2018 12:22:11 +0000 Subject: [PATCH] FIX: error when group_in_subject enabled but no group in pm --- app/mailers/user_notifications.rb | 12 +++++------- spec/mailers/user_notifications_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index c9cd1a032d2..9b268908370 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -435,13 +435,11 @@ class UserNotifications < ActionMailer::Base if post.topic.private_message? subject_pm = - if opts[:show_group_in_subject] - if group = post.topic.allowed_groups&.first - if group.full_name - "[#{group.full_name}] " - else - "[#{group.name}] " - end + if opts[:show_group_in_subject] and group = post.topic.allowed_groups&.first + if group.full_name + "[#{group.full_name}] " + else + "[#{group.name}] " end else I18n.t('subject_pm') diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb index a86424b323d..4067b6559b1 100644 --- a/spec/mailers/user_notifications_spec.rb +++ b/spec/mailers/user_notifications_spec.rb @@ -467,6 +467,12 @@ describe UserNotifications do include_examples "includes first group name" end + + context "no groups in pm" do + it "includes %{optional_pm} in subject" do + expect(mail.subject).to include("[PM] ") + end + end end end