Notify users posting sequential replies that there's a better way to do it.

This commit is contained in:
Robin Ward
2013-09-13 13:49:34 -04:00
parent 5d8cfd69f7
commit c365bd0070
5 changed files with 116 additions and 4 deletions

View File

@ -11,8 +11,8 @@ describe ComposerMessagesFinder do
it "calls all the message finders" do
finder.expects(:check_education_message).once
finder.expects(:check_avatar_notification).once
finder.expects(:check_sequential_replies).once
finder.find
end
end
@ -86,7 +86,7 @@ describe ComposerMessagesFinder do
end
it "doesn't return notifications for new users" do
user.trust_level = 0
user.trust_level = TrustLevel.levels[:newuser]
finder.check_avatar_notification.should be_blank
end
@ -101,6 +101,72 @@ describe ComposerMessagesFinder do
end
end
end
context '.check_sequential_replies' do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic) }
before do
SiteSetting.stubs(:educate_until_posts).returns(10)
user.topic_reply_count = 11
Fabricate(:post, topic: topic, user: user)
Fabricate(:post, topic: topic, user: user)
SiteSetting.stubs(:sequential_replies_threshold).returns(2)
end
it "does not give a message for new topics" do
finder = ComposerMessagesFinder.new(user, composerAction: 'createTopic')
finder.check_sequential_replies.should be_blank
end
it "does not give a message without a topic id" do
ComposerMessagesFinder.new(user, composerAction: 'reply').check_sequential_replies.should be_blank
end
context "reply" do
let(:finder) { ComposerMessagesFinder.new(user, composerAction: 'reply', topic_id: topic.id) }
it "does not give a message to new users" do
user.trust_level = TrustLevel.levels[:newuser]
finder.check_sequential_replies.should be_blank
end
it "does not give a message to users who are still in the 'education' phase" do
user.topic_reply_count = 10
finder.check_sequential_replies.should be_blank
end
it "doesn't notify a user it has already notified about sequential replies" do
UserHistory.create!(action: UserHistory.actions[:notified_about_sequential_replies], target_user_id: user.id )
finder.check_sequential_replies.should be_blank
end
it "doesn't notify a user who has less than the `sequential_replies_threshold` threshold posts" do
SiteSetting.stubs(:sequential_replies_threshold).returns(5)
finder.check_sequential_replies.should be_blank
end
it "doesn't notify a user if another user posted" do
Fabricate(:post, topic: topic, user: Fabricate(:user))
finder.check_sequential_replies.should be_blank
end
context "success" do
let!(:message) { finder.check_sequential_replies }
it "returns a message" do
message.should be_present
end
it "creates a notified_about_sequential_replies log" do
UserHistory.exists_for_user?(user, :notified_about_sequential_replies).should be_true
end
end
end
end