2013-02-06 03:16:51 +08:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
describe UserNotifications do
|
2013-02-26 00:42:20 +08:00
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
describe ".signup" do
|
|
|
|
subject { UserNotifications.signup(user) }
|
|
|
|
|
|
|
|
its(:to) { should == [user.email] }
|
|
|
|
its(:subject) { should be_present }
|
|
|
|
its(:from) { should == [SiteSetting.notification_email] }
|
|
|
|
its(:body) { should be_present }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".forgot_password" do
|
|
|
|
subject { UserNotifications.forgot_password(user) }
|
|
|
|
|
|
|
|
its(:to) { should == [user.email] }
|
|
|
|
its(:subject) { should be_present }
|
|
|
|
its(:from) { should == [SiteSetting.notification_email] }
|
2013-02-26 00:42:20 +08:00
|
|
|
its(:body) { should be_present }
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.daily_digest' do
|
|
|
|
subject { UserNotifications.digest(user) }
|
|
|
|
|
|
|
|
context "without new topics" do
|
|
|
|
its(:to) { should be_blank }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with new topics" do
|
|
|
|
before do
|
|
|
|
Topic.expects(:new_topics).returns([Fabricate(:topic, user: Fabricate(:coding_horror))])
|
|
|
|
end
|
|
|
|
|
|
|
|
its(:to) { should == [user.email] }
|
|
|
|
its(:subject) { should be_present }
|
|
|
|
its(:from) { should == [SiteSetting.notification_email] }
|
2013-02-26 00:42:20 +08:00
|
|
|
its(:body) { should be_present }
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.user_mentioned' do
|
|
|
|
|
|
|
|
let(:post) { Fabricate(:post, user: user) }
|
2013-02-28 07:30:14 +08:00
|
|
|
let(:username) { "walterwhite"}
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
let(:notification) do
|
2013-02-28 07:30:14 +08:00
|
|
|
Fabricate(:notification, user: user, topic: post.topic, post_number: post.post_number, data: {display_username: username}.to_json )
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { UserNotifications.user_mentioned(user, notification: notification, post: notification.post) }
|
|
|
|
|
|
|
|
its(:to) { should == [user.email] }
|
|
|
|
its(:subject) { should be_present }
|
|
|
|
its(:from) { should == [SiteSetting.notification_email] }
|
2013-02-28 07:30:14 +08:00
|
|
|
|
|
|
|
it "should have the correct from address" do
|
2013-02-28 08:01:45 +08:00
|
|
|
subject.header['from'].to_s.should == "#{username} via #{SiteSetting.title} <#{SiteSetting.notification_email}>"
|
2013-02-28 07:30:14 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
its(:body) { should be_present }
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|