2015-10-11 05:41:23 -04:00
|
|
|
require "rails_helper"
|
2014-11-24 11:40:21 -05:00
|
|
|
|
|
|
|
describe Jobs::NotifyMailingListSubscribers do
|
|
|
|
|
|
|
|
context "with mailing list on" do
|
2015-08-21 14:39:21 -04:00
|
|
|
before { SiteSetting.stubs(:default_email_mailing_list_mode).returns(true) }
|
2016-02-03 13:27:58 -05:00
|
|
|
let(:user) { Fabricate(:user) }
|
2014-11-24 11:40:21 -05:00
|
|
|
|
2016-02-03 13:27:58 -05:00
|
|
|
context "with a valid post" do
|
|
|
|
let!(:post) { Fabricate(:post, user: user) }
|
2015-08-21 14:39:21 -04:00
|
|
|
|
2016-02-03 13:27:58 -05:00
|
|
|
it "sends the email to the user" do
|
|
|
|
UserNotifications.expects(:mailing_list_notify).with(user, post).once
|
|
|
|
Jobs::NotifyMailingListSubscribers.new.execute(post_id: post.id)
|
2014-11-24 11:40:21 -05:00
|
|
|
end
|
2016-02-03 13:27:58 -05:00
|
|
|
end
|
2014-11-24 11:40:21 -05:00
|
|
|
|
2016-02-03 13:27:58 -05:00
|
|
|
context "with a deleted post" do
|
|
|
|
let!(:post) { Fabricate(:post, user: user, deleted_at: Time.now) }
|
2014-11-24 11:40:21 -05:00
|
|
|
|
2016-02-03 13:27:58 -05:00
|
|
|
it "doesn't send the email to the user" do
|
|
|
|
UserNotifications.expects(:mailing_list_notify).with(user, post).never
|
|
|
|
Jobs::NotifyMailingListSubscribers.new.execute(post_id: post.id)
|
2014-11-24 11:40:21 -05:00
|
|
|
end
|
2016-02-03 13:27:58 -05:00
|
|
|
end
|
2014-11-24 11:40:21 -05:00
|
|
|
|
2016-02-03 13:27:58 -05:00
|
|
|
context "with a user_deleted post" do
|
|
|
|
let!(:post) { Fabricate(:post, user: user, user_deleted: true) }
|
2014-11-24 11:40:21 -05:00
|
|
|
|
2016-02-03 13:27:58 -05:00
|
|
|
it "doesn't send the email to the user" do
|
|
|
|
UserNotifications.expects(:mailing_list_notify).with(user, post).never
|
|
|
|
Jobs::NotifyMailingListSubscribers.new.execute(post_id: post.id)
|
2014-11-24 11:40:21 -05:00
|
|
|
end
|
2016-02-03 13:27:58 -05:00
|
|
|
end
|
2014-11-24 11:40:21 -05:00
|
|
|
|
2016-02-03 13:27:58 -05:00
|
|
|
context "with a deleted topic" do
|
|
|
|
let!(:post) { Fabricate(:post, user: user) }
|
2015-08-21 14:39:21 -04:00
|
|
|
|
2016-02-03 13:27:58 -05:00
|
|
|
before do
|
|
|
|
post.topic.update_column(:deleted_at, Time.now)
|
2014-11-24 11:40:21 -05:00
|
|
|
end
|
|
|
|
|
2016-02-03 13:27:58 -05:00
|
|
|
it "doesn't send the email to the user" do
|
|
|
|
UserNotifications.expects(:mailing_list_notify).with(user, post).never
|
|
|
|
Jobs::NotifyMailingListSubscribers.new.execute(post_id: post.id)
|
|
|
|
end
|
2015-08-21 14:39:21 -04:00
|
|
|
end
|
|
|
|
|
2016-02-03 13:27:58 -05:00
|
|
|
context "to an anonymous user" do
|
2015-08-21 14:39:21 -04:00
|
|
|
let(:user) { Fabricate(:anonymous) }
|
|
|
|
let!(:post) { Fabricate(:post, user: user) }
|
|
|
|
|
2014-11-24 11:40:21 -05:00
|
|
|
it "doesn't send the email to the user" do
|
|
|
|
UserNotifications.expects(:mailing_list_notify).with(user, post).never
|
|
|
|
Jobs::NotifyMailingListSubscribers.new.execute(post_id: post.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with mailing list off" do
|
2015-08-21 14:39:21 -04:00
|
|
|
before { SiteSetting.stubs(:default_email_mailing_list_mode).returns(false) }
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user) }
|
2014-11-24 11:40:21 -05:00
|
|
|
let!(:post) { Fabricate(:post, user: user) }
|
|
|
|
|
|
|
|
it "doesn't send the email to the user" do
|
|
|
|
UserNotifications.expects(:mailing_list_notify).never
|
|
|
|
Jobs::NotifyMailingListSubscribers.new.execute(post_id: post.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|