2015-10-11 05:41:23 -04:00
|
|
|
require "rails_helper"
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
describe UserNotifications do
|
2013-02-25 11:42:20 -05:00
|
|
|
|
2013-06-18 15:54:02 -04:00
|
|
|
let(:user) { Fabricate(:admin) }
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2014-01-31 00:37:40 -05:00
|
|
|
describe "#get_context_posts" do
|
|
|
|
it "does not include hidden/deleted/user_deleted posts in context" do
|
2016-02-12 06:10:30 -05:00
|
|
|
post1 = create_post
|
2016-02-18 21:56:52 -05:00
|
|
|
_post2 = Fabricate(:post, topic: post1.topic, deleted_at: 1.day.ago)
|
|
|
|
_post3 = Fabricate(:post, topic: post1.topic, user_deleted: true)
|
|
|
|
_post4 = Fabricate(:post, topic: post1.topic, hidden: true)
|
|
|
|
_post5 = Fabricate(:post, topic: post1.topic, post_type: Post.types[:moderator_action])
|
|
|
|
_post6 = Fabricate(:post, topic: post1.topic, post_type: Post.types[:small_action])
|
|
|
|
_post7 = Fabricate(:post, topic: post1.topic, post_type: Post.types[:whisper])
|
2016-02-12 06:10:30 -05:00
|
|
|
last = Fabricate(:post, topic: post1.topic)
|
|
|
|
|
2016-02-25 08:05:40 -05:00
|
|
|
post1.user.user_option.email_previous_replies = UserOption.previous_replies_type[:always]
|
|
|
|
|
2016-02-12 06:10:30 -05:00
|
|
|
# default is only post #1
|
2016-02-25 08:05:40 -05:00
|
|
|
expect(UserNotifications.get_context_posts(last, nil, post1.user).count).to eq(1)
|
2016-02-12 06:10:30 -05:00
|
|
|
# staff members can also see the whisper
|
2016-02-25 08:05:40 -05:00
|
|
|
moderator = build(:moderator)
|
|
|
|
moderator.user_option = UserOption.new
|
|
|
|
moderator.user_option.email_previous_replies = UserOption.previous_replies_type[:always]
|
|
|
|
tu = TopicUser.new(topic: post1.topic, user: moderator)
|
|
|
|
expect(UserNotifications.get_context_posts(last, tu, tu.user).count).to eq(2)
|
2014-01-31 00:37:40 -05:00
|
|
|
end
|
2016-02-18 21:56:52 -05:00
|
|
|
|
|
|
|
it "allows users to control context" do
|
|
|
|
post1 = create_post
|
|
|
|
_post2 = Fabricate(:post, topic: post1.topic)
|
|
|
|
post3 = Fabricate(:post, topic: post1.topic)
|
|
|
|
|
|
|
|
user = Fabricate(:user)
|
|
|
|
TopicUser.change(user.id, post1.topic_id, last_emailed_post_number: 1)
|
|
|
|
topic_user = TopicUser.find_by(user_id: user.id, topic_id: post1.topic_id)
|
|
|
|
# to avoid reloads after update_columns
|
|
|
|
user = topic_user.user
|
2016-02-25 08:05:40 -05:00
|
|
|
user.user_option.update_columns(email_previous_replies: UserOption.previous_replies_type[:unless_emailed])
|
|
|
|
|
|
|
|
expect(UserNotifications.get_context_posts(post3, topic_user, user).count).to eq(1)
|
2016-02-18 21:56:52 -05:00
|
|
|
|
|
|
|
user.user_option.update_columns(email_previous_replies: UserOption.previous_replies_type[:never])
|
2016-02-25 08:05:40 -05:00
|
|
|
expect(UserNotifications.get_context_posts(post3, topic_user, user).count).to eq(0)
|
2016-02-18 21:56:52 -05:00
|
|
|
|
|
|
|
user.user_option.update_columns(email_previous_replies: UserOption.previous_replies_type[:always])
|
2016-02-25 08:05:40 -05:00
|
|
|
expect(UserNotifications.get_context_posts(post3, topic_user, user).count).to eq(2)
|
2016-02-18 21:56:52 -05:00
|
|
|
|
|
|
|
end
|
2014-01-31 00:37:40 -05:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
describe ".signup" do
|
2014-10-29 11:06:50 -04:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
subject { UserNotifications.signup(user) }
|
|
|
|
|
2014-10-29 11:06:50 -04:00
|
|
|
it "works" do
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject.to).to eq([user.email])
|
|
|
|
expect(subject.subject).to be_present
|
|
|
|
expect(subject.from).to eq([SiteSetting.notification_email])
|
|
|
|
expect(subject.body).to be_present
|
2014-10-29 11:06:50 -04:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe ".forgot_password" do
|
2014-10-29 11:06:50 -04:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
subject { UserNotifications.forgot_password(user) }
|
|
|
|
|
2014-10-29 11:06:50 -04:00
|
|
|
it "works" do
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject.to).to eq([user.email])
|
|
|
|
expect(subject.subject).to be_present
|
|
|
|
expect(subject.from).to eq([SiteSetting.notification_email])
|
|
|
|
expect(subject.body).to be_present
|
2014-10-29 11:06:50 -04:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-06-10 16:46:08 -04:00
|
|
|
describe '.digest' do
|
2014-10-29 11:06:50 -04:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
subject { UserNotifications.digest(user) }
|
|
|
|
|
|
|
|
context "without new topics" do
|
2014-10-29 11:06:50 -04:00
|
|
|
|
|
|
|
it "doesn't send the email" do
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject.to).to be_blank
|
2014-10-29 11:06:50 -04:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with new topics" do
|
2014-10-29 11:06:50 -04:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
before do
|
2013-06-03 16:12:24 -04:00
|
|
|
Topic.expects(:for_digest).returns([Fabricate(:topic, user: Fabricate(:coding_horror))])
|
2014-04-17 16:42:40 -04:00
|
|
|
Topic.expects(:new_since_last_seen).returns(Topic.none)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2014-10-29 11:06:50 -04:00
|
|
|
it "works" do
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject.to).to eq([user.email])
|
|
|
|
expect(subject.subject).to be_present
|
|
|
|
expect(subject.from).to eq([SiteSetting.notification_email])
|
|
|
|
expect(subject.html_part.body.to_s).to be_present
|
|
|
|
expect(subject.text_part.body.to_s).to be_present
|
2013-11-28 17:20:56 -05:00
|
|
|
end
|
|
|
|
|
2015-06-03 12:49:51 -04:00
|
|
|
it "includes email_prefix in email subject instead of site title" do
|
|
|
|
SiteSetting.email_prefix = "Try Discourse"
|
|
|
|
SiteSetting.title = "Discourse Meta"
|
|
|
|
|
|
|
|
expect(subject.subject).to match(/Try Discourse/)
|
|
|
|
expect(subject.subject).not_to match(/Discourse Meta/)
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-26 03:27:46 -04:00
|
|
|
describe '.user_replied' do
|
2014-10-21 10:06:55 -04:00
|
|
|
let(:response_by_user) { Fabricate(:user, name: "John Doe") }
|
2014-10-03 07:44:08 -04:00
|
|
|
let(:category) { Fabricate(:category, name: 'India') }
|
|
|
|
let(:topic) { Fabricate(:topic, category: category) }
|
2016-02-25 08:05:40 -05:00
|
|
|
let(:post) { Fabricate(:post, topic: topic, raw: 'This is My super duper cool topic') }
|
|
|
|
let(:response) { Fabricate(:post, reply_to_post_number: 1, topic: post.topic, user: response_by_user)}
|
2014-02-12 00:51:26 -05:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:notification) { Fabricate(:notification, user: user) }
|
|
|
|
|
2013-07-26 03:27:46 -04:00
|
|
|
it 'generates a correct email' do
|
2016-02-25 08:05:40 -05:00
|
|
|
|
|
|
|
# Fabricator is not fabricating this ...
|
2015-02-17 14:37:22 -05:00
|
|
|
SiteSetting.enable_names = true
|
|
|
|
SiteSetting.display_name_on_posts = true
|
2016-01-26 20:19:49 -05:00
|
|
|
mail = UserNotifications.user_replied(response.user,
|
|
|
|
post: response,
|
|
|
|
notification_type: notification.notification_type,
|
|
|
|
notification_data_hash: notification.data_hash
|
|
|
|
)
|
2014-10-21 10:06:55 -04:00
|
|
|
# from should include full user name
|
|
|
|
expect(mail[:from].display_names).to eql(['John Doe'])
|
|
|
|
|
2014-10-03 07:44:08 -04:00
|
|
|
# subject should include category name
|
|
|
|
expect(mail.subject).to match(/India/)
|
|
|
|
|
2016-02-25 08:05:40 -05:00
|
|
|
mail_html = mail.html_part.to_s
|
|
|
|
|
|
|
|
expect(mail_html.scan(/My super duper cool topic/).count).to eq(1)
|
|
|
|
expect(mail_html.scan(/In Reply To/).count).to eq(1)
|
|
|
|
|
2016-02-09 03:09:10 -05:00
|
|
|
# 2 "visit topic" link
|
2016-02-25 08:05:40 -05:00
|
|
|
expect(mail_html.scan(/Visit Topic/).count).to eq(2)
|
2016-02-09 03:09:10 -05:00
|
|
|
|
2013-07-26 03:27:46 -04:00
|
|
|
# 2 respond to links cause we have 1 context post
|
2016-02-25 08:05:40 -05:00
|
|
|
expect(mail_html.scan(/to respond/).count).to eq(2)
|
2013-07-26 03:27:46 -04:00
|
|
|
|
|
|
|
# 1 unsubscribe
|
2016-02-25 08:05:40 -05:00
|
|
|
expect(mail_html.scan(/To unsubscribe/).count).to eq(1)
|
2013-07-26 03:27:46 -04:00
|
|
|
|
2013-12-29 21:02:12 -05:00
|
|
|
# side effect, topic user is updated with post number
|
|
|
|
tu = TopicUser.get(post.topic_id, response.user)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(tu.last_emailed_post_number).to eq(response.post_number)
|
2016-02-25 08:05:40 -05:00
|
|
|
|
|
|
|
|
|
|
|
# no In Reply To if user opts out
|
|
|
|
response.user.user_option.email_in_reply_to = false
|
|
|
|
mail = UserNotifications.user_replied(response.user,
|
|
|
|
post: response,
|
|
|
|
notification_type: notification.notification_type,
|
|
|
|
notification_data_hash: notification.data_hash
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
expect(mail.html_part.to_s.scan(/In Reply To/).count).to eq(0)
|
2013-07-26 03:27:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-29 01:16:55 -04:00
|
|
|
describe '.user_posted' do
|
2014-12-03 02:42:05 -05:00
|
|
|
let(:response_by_user) { Fabricate(:user, name: "John Doe", username: "john") }
|
2014-09-29 01:16:55 -04:00
|
|
|
let(:post) { Fabricate(:post) }
|
2014-10-21 10:06:55 -04:00
|
|
|
let(:response) { Fabricate(:post, topic: post.topic, user: response_by_user)}
|
2014-09-29 01:16:55 -04:00
|
|
|
let(:user) { Fabricate(:user) }
|
2014-12-03 02:42:05 -05:00
|
|
|
let(:notification) { Fabricate(:notification, user: user, data: {original_username: response_by_user.username}.to_json) }
|
2014-09-29 01:16:55 -04:00
|
|
|
|
|
|
|
it 'generates a correct email' do
|
2015-02-17 14:37:22 -05:00
|
|
|
SiteSetting.enable_names = false
|
2016-01-26 20:19:49 -05:00
|
|
|
mail = UserNotifications.user_posted(response.user,
|
|
|
|
post: response,
|
|
|
|
notification_type: notification.notification_type,
|
|
|
|
notification_data_hash: notification.data_hash
|
|
|
|
)
|
2014-09-29 01:16:55 -04:00
|
|
|
|
2014-10-21 10:06:55 -04:00
|
|
|
# from should not include full user name if "show user full names" is disabled
|
|
|
|
expect(mail[:from].display_names).to_not eql(['John Doe'])
|
|
|
|
|
2014-12-03 02:42:05 -05:00
|
|
|
# from should include username if "show user full names" is disabled
|
|
|
|
expect(mail[:from].display_names).to eql(['john'])
|
|
|
|
|
2014-10-03 07:44:08 -04:00
|
|
|
# subject should not include category name
|
|
|
|
expect(mail.subject).not_to match(/Uncategorized/)
|
|
|
|
|
2016-02-25 08:05:40 -05:00
|
|
|
# 1 respond to links as no context by default
|
|
|
|
expect(mail.html_part.to_s.scan(/to respond/).count).to eq(1)
|
2014-09-29 01:16:55 -04:00
|
|
|
|
|
|
|
# 1 unsubscribe link
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(mail.html_part.to_s.scan(/To unsubscribe/).count).to eq(1)
|
2014-09-29 01:16:55 -04:00
|
|
|
|
|
|
|
# side effect, topic user is updated with post number
|
|
|
|
tu = TopicUser.get(post.topic_id, response.user)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(tu.last_emailed_post_number).to eq(response.post_number)
|
2014-09-29 01:16:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.user_private_message' do
|
2014-12-03 02:42:05 -05:00
|
|
|
let(:response_by_user) { Fabricate(:user, name: "", username: "john") }
|
2014-09-29 01:16:55 -04:00
|
|
|
let(:topic) { Fabricate(:private_message_topic) }
|
2014-10-21 10:06:55 -04:00
|
|
|
let(:response) { Fabricate(:post, topic: topic, user: response_by_user)}
|
2014-09-29 01:16:55 -04:00
|
|
|
let(:user) { Fabricate(:user) }
|
2014-12-03 02:42:05 -05:00
|
|
|
let(:notification) { Fabricate(:notification, user: user, data: {original_username: response_by_user.username}.to_json) }
|
2014-09-29 01:16:55 -04:00
|
|
|
|
|
|
|
it 'generates a correct email' do
|
2015-02-17 14:37:22 -05:00
|
|
|
SiteSetting.enable_names = true
|
2016-01-26 20:19:49 -05:00
|
|
|
mail = UserNotifications.user_private_message(
|
|
|
|
response.user,
|
|
|
|
post: response,
|
|
|
|
notification_type: notification.notification_type,
|
|
|
|
notification_data_hash: notification.data_hash
|
|
|
|
)
|
2014-09-29 01:16:55 -04:00
|
|
|
|
2014-12-03 02:42:05 -05:00
|
|
|
# from should include username if full user name is not provided
|
|
|
|
expect(mail[:from].display_names).to eql(['john'])
|
2014-10-21 10:06:55 -04:00
|
|
|
|
2014-09-29 01:16:55 -04:00
|
|
|
# subject should include "[PM]"
|
|
|
|
expect(mail.subject).to match("[PM]")
|
|
|
|
|
2016-02-09 03:09:10 -05:00
|
|
|
# 1 "visit message" link
|
|
|
|
expect(mail.html_part.to_s.scan(/Visit Message/).count).to eq(1)
|
|
|
|
|
2014-09-29 01:16:55 -04:00
|
|
|
# 1 respond to link
|
2016-01-11 21:56:58 -05:00
|
|
|
expect(mail.html_part.to_s.scan(/to respond/).count).to eq(1)
|
2014-09-29 01:16:55 -04:00
|
|
|
|
|
|
|
# 1 unsubscribe link
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(mail.html_part.to_s.scan(/To unsubscribe/).count).to eq(1)
|
2014-09-29 01:16:55 -04:00
|
|
|
|
|
|
|
# side effect, topic user is updated with post number
|
|
|
|
tu = TopicUser.get(topic.id, response.user)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(tu.last_emailed_post_number).to eq(response.post_number)
|
2014-09-29 01:16:55 -04:00
|
|
|
end
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-06-12 16:35:46 -04:00
|
|
|
def expects_build_with(condition)
|
|
|
|
UserNotifications.any_instance.expects(:build_email).with(user.email, condition)
|
2016-01-26 20:19:49 -05:00
|
|
|
mailer = UserNotifications.send(mail_type, user,
|
|
|
|
notification_type: Notification.types[notification.notification_type],
|
|
|
|
notification_data_hash: notification.data_hash,
|
|
|
|
post: notification.post)
|
|
|
|
mailer.message
|
2013-06-12 16:35:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples "supports reply by email" do
|
|
|
|
context "reply_by_email" do
|
|
|
|
it "should have allow_reply_by_email set when that feature is enabled" do
|
|
|
|
expects_build_with(has_entry(:allow_reply_by_email, true))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples "no reply by email" do
|
|
|
|
context "reply_by_email" do
|
2013-06-13 10:56:16 -04:00
|
|
|
it "doesn't support reply by email" do
|
2013-06-12 16:35:46 -04:00
|
|
|
expects_build_with(Not(has_entry(:allow_reply_by_email, true)))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-09 18:54:13 -05:00
|
|
|
# The parts of emails that are derived from templates are translated
|
|
|
|
shared_examples "sets user locale" do
|
|
|
|
context "set locale for translating templates" do
|
|
|
|
it "sets the locale" do
|
|
|
|
expects_build_with(has_key(:locale))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-12 16:35:46 -04:00
|
|
|
shared_examples "notification email building" do
|
2013-02-05 14:16:51 -05:00
|
|
|
let(:post) { Fabricate(:post, user: user) }
|
2013-06-12 16:35:46 -04:00
|
|
|
let(:mail_type) { "user_#{notification_type}"}
|
2013-02-27 18:30:14 -05:00
|
|
|
let(:username) { "walterwhite"}
|
2013-02-05 14:16:51 -05:00
|
|
|
let(:notification) do
|
2013-06-12 16:35:46 -04:00
|
|
|
Fabricate(:notification,
|
|
|
|
user: user,
|
|
|
|
topic: post.topic,
|
|
|
|
notification_type: Notification.types[notification_type],
|
|
|
|
post_number: post.post_number,
|
2014-02-03 20:56:28 -05:00
|
|
|
data: {original_username: username}.to_json )
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-06-12 16:35:46 -04:00
|
|
|
describe '.user_mentioned' do
|
|
|
|
it "has a username" do
|
|
|
|
expects_build_with(has_entry(:username, username))
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-06-12 16:35:46 -04:00
|
|
|
it "has a url" do
|
|
|
|
expects_build_with(has_key(:url))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a template" do
|
|
|
|
expects_build_with(has_entry(:template, "user_notifications.#{mail_type}"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a message" do
|
2013-07-22 15:06:37 -04:00
|
|
|
expects_build_with(has_key(:message))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a context" do
|
|
|
|
expects_build_with(has_key(:context))
|
2013-06-12 16:35:46 -04:00
|
|
|
end
|
2013-02-27 18:30:14 -05:00
|
|
|
|
2013-06-12 16:35:46 -04:00
|
|
|
it "has an unsubscribe link" do
|
|
|
|
expects_build_with(has_key(:add_unsubscribe_link))
|
|
|
|
end
|
|
|
|
|
2013-06-13 18:11:10 -04:00
|
|
|
it "has an post_id" do
|
|
|
|
expects_build_with(has_key(:post_id))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has an topic_id" do
|
|
|
|
expects_build_with(has_key(:topic_id))
|
|
|
|
end
|
|
|
|
|
2015-02-17 14:37:22 -05:00
|
|
|
it "should have user name as from_alias" do
|
|
|
|
SiteSetting.enable_names = true
|
|
|
|
SiteSetting.display_name_on_posts = true
|
2014-10-21 10:06:55 -04:00
|
|
|
expects_build_with(has_entry(:from_alias, "#{user.name}"))
|
2013-06-12 16:35:46 -04:00
|
|
|
end
|
2014-05-06 15:01:19 -04:00
|
|
|
|
2015-02-17 14:37:22 -05:00
|
|
|
it "should not have user name as from_alias if display_name_on_posts is disabled" do
|
|
|
|
SiteSetting.enable_names = false
|
|
|
|
SiteSetting.display_name_on_posts = false
|
|
|
|
expects_build_with(has_entry(:from_alias, "walterwhite"))
|
|
|
|
end
|
|
|
|
|
2014-05-06 15:01:19 -04:00
|
|
|
it "should explain how to respond" do
|
|
|
|
expects_build_with(Not(has_entry(:include_respond_instructions, false)))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not explain how to respond if the user is suspended" do
|
|
|
|
User.any_instance.stubs(:suspended?).returns(true)
|
|
|
|
expects_build_with(has_entry(:include_respond_instructions, false))
|
|
|
|
end
|
2013-02-27 18:30:14 -05:00
|
|
|
end
|
2013-06-12 16:35:46 -04:00
|
|
|
end
|
2013-02-27 18:30:14 -05:00
|
|
|
|
2013-06-12 16:35:46 -04:00
|
|
|
describe "user mentioned email" do
|
|
|
|
include_examples "notification email building" do
|
|
|
|
let(:notification_type) { :mentioned }
|
|
|
|
include_examples "supports reply by email"
|
2016-02-09 18:54:13 -05:00
|
|
|
include_examples "sets user locale"
|
2013-06-12 16:35:46 -04:00
|
|
|
end
|
|
|
|
end
|
2013-02-27 18:30:14 -05:00
|
|
|
|
2013-06-12 16:35:46 -04:00
|
|
|
describe "user replied" do
|
|
|
|
include_examples "notification email building" do
|
|
|
|
let(:notification_type) { :replied }
|
|
|
|
include_examples "supports reply by email"
|
2016-02-09 18:54:13 -05:00
|
|
|
include_examples "sets user locale"
|
2013-06-12 16:35:46 -04:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-06-12 16:35:46 -04:00
|
|
|
describe "user quoted" do
|
|
|
|
include_examples "notification email building" do
|
|
|
|
let(:notification_type) { :quoted }
|
|
|
|
include_examples "supports reply by email"
|
2016-02-09 18:54:13 -05:00
|
|
|
include_examples "sets user locale"
|
2013-06-12 16:35:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "user posted" do
|
|
|
|
include_examples "notification email building" do
|
|
|
|
let(:notification_type) { :posted }
|
|
|
|
include_examples "supports reply by email"
|
2016-02-09 18:54:13 -05:00
|
|
|
include_examples "sets user locale"
|
2013-06-12 16:35:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "user invited to a private message" do
|
|
|
|
include_examples "notification email building" do
|
|
|
|
let(:notification_type) { :invited_to_private_message }
|
|
|
|
include_examples "no reply by email"
|
2016-02-09 18:54:13 -05:00
|
|
|
include_examples "sets user locale"
|
2013-06-12 16:35:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-30 14:36:47 -04:00
|
|
|
describe "user invited to a topic" do
|
|
|
|
include_examples "notification email building" do
|
|
|
|
let(:notification_type) { :invited_to_topic }
|
|
|
|
include_examples "no reply by email"
|
2016-02-09 18:54:13 -05:00
|
|
|
include_examples "sets user locale"
|
2015-03-30 14:36:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-09 18:54:13 -05:00
|
|
|
# notification emails derived from templates are translated into the user's locale
|
|
|
|
shared_examples "notification derived from template" do
|
|
|
|
let(:user) { Fabricate(:user, locale: locale) }
|
|
|
|
let(:mail_type) { mail_type }
|
|
|
|
let(:notification) { Fabricate(:notification, user: user) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "notifications from template" do
|
|
|
|
|
|
|
|
context "user locale has been set" do
|
|
|
|
|
|
|
|
%w(signup signup_after_approval authorize_email forgot_password admin_login account_created).each do |mail_type|
|
|
|
|
include_examples "notification derived from template" do
|
|
|
|
SiteSetting.default_locale = "en"
|
|
|
|
let(:locale) { "fr" }
|
|
|
|
let(:mail_type) { mail_type }
|
|
|
|
it "sets the locale" do
|
|
|
|
expects_build_with(has_entry(:locale, "fr"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "user locale has not been set" do
|
|
|
|
%w(signup signup_after_approval authorize_email forgot_password admin_login account_created).each do |mail_type|
|
|
|
|
include_examples "notification derived from template" do
|
|
|
|
SiteSetting.default_locale = "en"
|
|
|
|
let(:locale) { nil }
|
|
|
|
let(:mail_type) { mail_type }
|
|
|
|
it "sets the locale" do
|
|
|
|
expects_build_with(has_entry(:locale, nil))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-03-04 16:21:30 -05:00
|
|
|
|
|
|
|
context "user locale is not a valid locale" do
|
|
|
|
%w(signup signup_after_approval authorize_email forgot_password admin_login account_created).each do |mail_type|
|
|
|
|
include_examples "notification derived from template" do
|
|
|
|
SiteSetting.default_locale = "en"
|
|
|
|
let(:locale) { "invalid" }
|
|
|
|
let(:mail_type) { mail_type }
|
|
|
|
it "sets the locale" do
|
|
|
|
expects_build_with(has_entry(:locale, nil))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-09 18:54:13 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|