mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
Notify users posting sequential replies that there's a better way to do it.
This commit is contained in:
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user