FIX: when a user got multiple replies to a topic, emails were missing

This commit is contained in:
Sam
2016-01-27 12:19:49 +11:00
parent 12b85b9ef9
commit 1bb485fca5
8 changed files with 226 additions and 130 deletions

View File

@ -99,7 +99,11 @@ describe UserNotifications do
it 'generates a correct email' do
SiteSetting.enable_names = true
SiteSetting.display_name_on_posts = true
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)
mail = UserNotifications.user_replied(response.user,
post: response,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash
)
# from should include full user name
expect(mail[:from].display_names).to eql(['John Doe'])
@ -119,22 +123,21 @@ describe UserNotifications do
# in mailing list mode user_replies is not sent through
response.user.mailing_list_mode = true
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)
mail = UserNotifications.user_replied(response.user, post: response,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash
)
if Rails.version >= "4.2.0"
expect(mail.message.class).to eq(ActionMailer::Base::NullMail)
else
expect(mail.class).to eq(ActionMailer::Base::NullMail)
end
expect(mail.message.class).to eq(ActionMailer::Base::NullMail)
response.user.mailing_list_mode = nil
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)
mail = UserNotifications.user_replied(response.user,
post: response,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash
)
if Rails.version >= "4.2.0"
expect(mail.message.class).not_to eq(ActionMailer::Base::NullMail)
else
expect(mail.class).not_to eq(ActionMailer::Base::NullMail)
end
expect(mail.message.class).not_to eq(ActionMailer::Base::NullMail)
end
end
@ -147,7 +150,11 @@ describe UserNotifications do
it 'generates a correct email' do
SiteSetting.enable_names = false
mail = UserNotifications.user_posted(response.user, post: response, notification: notification)
mail = UserNotifications.user_posted(response.user,
post: response,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash
)
# from should not include full user name if "show user full names" is disabled
expect(mail[:from].display_names).to_not eql(['John Doe'])
@ -179,7 +186,12 @@ describe UserNotifications do
it 'generates a correct email' do
SiteSetting.enable_names = true
mail = UserNotifications.user_private_message(response.user, post: response, notification: notification)
mail = UserNotifications.user_private_message(
response.user,
post: response,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash
)
# from should include username if full user name is not provided
expect(mail[:from].display_names).to eql(['john'])
@ -201,16 +213,11 @@ describe UserNotifications do
def expects_build_with(condition)
UserNotifications.any_instance.expects(:build_email).with(user.email, condition)
mailer = UserNotifications.send(mail_type, user, notification: notification, post: notification.post)
if Rails.version >= "4.2.0"
# Starting from Rails 4.2, calling MyMailer.some_method no longer result
# in an immediate call to MyMailer#some_method. Instead, a "lazy proxy" is
# returned (this is changed to support #deliver_later). As a quick hack to
# fix the test, calling #message (or anything, really) would force the
# Mailer object to be created and the method invoked.
mailer.message
end
mailer = UserNotifications.send(mail_type, user,
notification_type: Notification.types[notification.notification_type],
notification_data_hash: notification.data_hash,
post: notification.post)
mailer.message
end
shared_examples "supports reply by email" do