2013-09-12 16:46:43 -05:00
|
|
|
# encoding: utf-8
|
2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
require "composer_messages_finder"
|
2013-09-12 16:46:43 -05:00
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe ComposerMessagesFinder do
|
2022-07-27 11:14:14 -05:00
|
|
|
describe "delegates work" do
|
2013-09-12 16:46:43 -05:00
|
|
|
let(:user) { Fabricate.build(:user) }
|
2023-01-09 05:18:21 -06:00
|
|
|
let(:finder) { ComposerMessagesFinder.new(user, composer_action: "createTopic") }
|
2013-09-12 16:46:43 -05:00
|
|
|
|
|
|
|
it "calls all the message finders" do
|
|
|
|
finder.expects(:check_education_message).once
|
2013-12-19 12:45:55 -06:00
|
|
|
finder.expects(:check_new_user_many_replies).once
|
2013-09-12 16:46:43 -05:00
|
|
|
finder.expects(:check_avatar_notification).once
|
2013-09-13 12:49:34 -05:00
|
|
|
finder.expects(:check_sequential_replies).once
|
2013-09-17 13:38:39 -05:00
|
|
|
finder.expects(:check_dominating_topic).once
|
2014-03-12 09:44:08 -05:00
|
|
|
finder.expects(:check_reviving_old_topic).once
|
2017-02-03 15:59:05 -06:00
|
|
|
finder.expects(:check_get_a_room).once
|
2013-09-12 16:46:43 -05:00
|
|
|
finder.find
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe ".check_education_message" do
|
2013-09-12 16:46:43 -05:00
|
|
|
let(:user) { Fabricate.build(:user) }
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
context "when creating topic" do
|
|
|
|
let(:finder) { ComposerMessagesFinder.new(user, composer_action: "createTopic") }
|
2013-09-12 16:46:43 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
before { SiteSetting.educate_until_posts = 10 }
|
2013-09-12 16:46:43 -05:00
|
|
|
|
|
|
|
it "returns a message for a user who has not posted any topics" do
|
2013-09-17 11:11:17 -05:00
|
|
|
user.expects(:created_topic_count).returns(9)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_education_message).to be_present
|
2013-09-12 16:46:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns no message when the user has posted enough topics" do
|
2013-09-17 11:11:17 -05:00
|
|
|
user.expects(:created_topic_count).returns(10)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_education_message).to be_blank
|
2013-09-12 16:46:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
context "with private message" do
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:topic) { Fabricate(:private_message_topic) }
|
2016-11-04 04:06:53 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
context "when starting a new private message" do
|
|
|
|
let(:finder) do
|
|
|
|
ComposerMessagesFinder.new(user, composer_action: "createTopic", topic_id: topic.id)
|
|
|
|
end
|
2016-11-04 04:06:53 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "should return an empty string" do
|
2016-11-08 21:31:53 -06:00
|
|
|
expect(finder.check_education_message).to eq(nil)
|
2016-11-04 04:06:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
context "when replying to a private message" do
|
|
|
|
let(:finder) do
|
|
|
|
ComposerMessagesFinder.new(user, composer_action: "reply", topic_id: topic.id)
|
|
|
|
end
|
2016-11-04 04:06:53 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "should return an empty string" do
|
2016-11-08 21:31:53 -06:00
|
|
|
expect(finder.check_education_message).to eq(nil)
|
2016-11-04 04:06:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
context "when creating reply" do
|
|
|
|
let(:finder) { ComposerMessagesFinder.new(user, composer_action: "reply") }
|
2013-09-12 16:46:43 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
before { SiteSetting.educate_until_posts = 10 }
|
2013-09-12 16:46:43 -05:00
|
|
|
|
|
|
|
it "returns a message for a user who has not posted any topics" do
|
2013-09-17 11:11:17 -05:00
|
|
|
user.expects(:post_count).returns(9)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_education_message).to be_present
|
2013-09-12 16:46:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns no message when the user has posted enough topics" do
|
2013-09-17 11:11:17 -05:00
|
|
|
user.expects(:post_count).returns(10)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_education_message).to be_blank
|
2013-09-12 16:46:43 -05:00
|
|
|
end
|
|
|
|
end
|
2013-12-19 12:45:55 -06:00
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe ".check_new_user_many_replies" do
|
2013-12-19 12:45:55 -06:00
|
|
|
let(:user) { Fabricate.build(:user) }
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
context "when replying" do
|
|
|
|
let(:finder) { ComposerMessagesFinder.new(user, composer_action: "reply") }
|
2013-12-19 12:45:55 -06:00
|
|
|
|
|
|
|
it "has no message when `posted_too_much_in_topic?` is false" do
|
|
|
|
user.expects(:posted_too_much_in_topic?).returns(false)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_new_user_many_replies).to be_blank
|
2013-12-19 12:45:55 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has a message when a user has posted too much" do
|
|
|
|
user.expects(:posted_too_much_in_topic?).returns(true)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_new_user_many_replies).to be_present
|
2013-12-19 12:45:55 -06:00
|
|
|
end
|
|
|
|
end
|
2013-09-12 16:46:43 -05:00
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe ".check_avatar_notification" do
|
|
|
|
let(:finder) { ComposerMessagesFinder.new(user, composer_action: "createTopic") }
|
2023-12-12 17:53:19 -06:00
|
|
|
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
2013-09-12 16:46:43 -05:00
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with success" do
|
2015-01-02 05:37:17 -06:00
|
|
|
let!(:message) { finder.check_avatar_notification }
|
2013-09-12 16:46:43 -05:00
|
|
|
|
2015-01-02 05:37:17 -06:00
|
|
|
it "returns an avatar upgrade message" do
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(message).to be_present
|
2013-09-12 16:46:43 -05:00
|
|
|
end
|
|
|
|
|
2015-01-02 05:37:17 -06:00
|
|
|
it "creates a notified_about_avatar log" do
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(UserHistory.exists_for_user?(user, :notified_about_avatar)).to eq(true)
|
2013-09-12 16:46:43 -05:00
|
|
|
end
|
2015-01-02 05:37:17 -06:00
|
|
|
end
|
2013-09-12 16:46:43 -05:00
|
|
|
|
2015-01-02 05:37:17 -06:00
|
|
|
it "doesn't return notifications for new users" do
|
|
|
|
user.trust_level = TrustLevel[0]
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_avatar_notification).to be_blank
|
2015-01-02 05:37:17 -06:00
|
|
|
end
|
2013-09-12 16:46:43 -05:00
|
|
|
|
2015-01-02 05:37:17 -06:00
|
|
|
it "doesn't return notifications for users who have custom avatars" do
|
|
|
|
user.uploaded_avatar_id = 1
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_avatar_notification).to be_blank
|
2015-01-02 05:37:17 -06:00
|
|
|
end
|
2013-09-12 16:46:43 -05:00
|
|
|
|
2015-01-02 05:37:17 -06:00
|
|
|
it "doesn't notify users who have been notified already" do
|
2023-01-09 05:18:21 -06:00
|
|
|
UserHistory.create!(
|
|
|
|
action: UserHistory.actions[:notified_about_avatar],
|
|
|
|
target_user_id: user.id,
|
|
|
|
)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_avatar_notification).to be_blank
|
2013-09-12 16:46:43 -05:00
|
|
|
end
|
2015-12-14 11:02:40 -06:00
|
|
|
|
|
|
|
it "doesn't notify users if 'disable_avatar_education_message' setting is enabled" do
|
|
|
|
SiteSetting.disable_avatar_education_message = true
|
|
|
|
expect(finder.check_avatar_notification).to be_blank
|
|
|
|
end
|
|
|
|
|
2021-02-08 04:04:33 -06:00
|
|
|
it "doesn't notify users if 'discourse_connect_overrides_avatar' setting is enabled" do
|
|
|
|
SiteSetting.discourse_connect_overrides_avatar = true
|
2015-12-14 11:02:40 -06:00
|
|
|
expect(finder.check_avatar_notification).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify users if 'allow_uploaded_avatars' setting is disabled" do
|
2023-12-12 17:53:19 -06:00
|
|
|
user.update!(trust_level: 3)
|
|
|
|
Group.refresh_automatic_groups!
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
SiteSetting.uploaded_avatars_allowed_groups = ""
|
2015-12-14 11:02:40 -06:00
|
|
|
expect(finder.check_avatar_notification).to be_blank
|
2023-12-12 17:53:19 -06:00
|
|
|
|
|
|
|
SiteSetting.uploaded_avatars_allowed_groups = "13"
|
|
|
|
expect(finder.check_avatar_notification).to be_present
|
2015-12-14 11:02:40 -06:00
|
|
|
end
|
2013-09-13 12:49:34 -05:00
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe ".check_sequential_replies" do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:user)
|
|
|
|
fab!(:topic)
|
2013-09-13 12:49:34 -05:00
|
|
|
|
|
|
|
before do
|
2017-07-07 01:09:14 -05:00
|
|
|
SiteSetting.educate_until_posts = 10
|
2013-09-13 23:32:18 -05:00
|
|
|
user.stubs(:post_count).returns(11)
|
2013-09-13 12:49:34 -05:00
|
|
|
|
2020-03-10 16:13:17 -05:00
|
|
|
freeze_time(5.minutes.ago) do
|
|
|
|
Fabricate(:post, topic: topic, user: user)
|
|
|
|
Fabricate(:post, topic: topic, user: user)
|
|
|
|
Fabricate(:post, topic: topic, user: user, post_type: Post.types[:small_action])
|
|
|
|
end
|
2013-09-13 12:49:34 -05:00
|
|
|
|
2017-07-07 01:09:14 -05:00
|
|
|
SiteSetting.sequential_replies_threshold = 2
|
2013-09-13 12:49:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not give a message for new topics" do
|
2023-01-09 05:18:21 -06:00
|
|
|
finder = ComposerMessagesFinder.new(user, composer_action: "createTopic")
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_sequential_replies).to be_blank
|
2013-09-13 12:49:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not give a message without a topic id" do
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(
|
|
|
|
ComposerMessagesFinder.new(user, composer_action: "reply").check_sequential_replies,
|
|
|
|
).to be_blank
|
2013-09-13 12:49:34 -05:00
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with reply" do
|
2023-01-09 05:18:21 -06:00
|
|
|
let(:finder) do
|
|
|
|
ComposerMessagesFinder.new(user, composer_action: "reply", topic_id: topic.id)
|
|
|
|
end
|
2013-09-13 12:49:34 -05:00
|
|
|
|
|
|
|
it "does not give a message to users who are still in the 'education' phase" do
|
2013-09-17 11:11:17 -05:00
|
|
|
user.stubs(:post_count).returns(9)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_sequential_replies).to be_blank
|
2013-09-13 12:49:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify a user it has already notified about sequential replies" do
|
2023-01-09 05:18:21 -06:00
|
|
|
UserHistory.create!(
|
|
|
|
action: UserHistory.actions[:notified_about_sequential_replies],
|
|
|
|
target_user_id: user.id,
|
|
|
|
topic_id: topic.id,
|
|
|
|
)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_sequential_replies).to be_blank
|
2013-09-13 12:49:34 -05:00
|
|
|
end
|
|
|
|
|
2013-09-17 13:38:39 -05:00
|
|
|
it "will notify you if it hasn't in the current topic" do
|
2023-01-09 05:18:21 -06:00
|
|
|
UserHistory.create!(
|
|
|
|
action: UserHistory.actions[:notified_about_sequential_replies],
|
|
|
|
target_user_id: user.id,
|
|
|
|
topic_id: topic.id + 1,
|
|
|
|
)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_sequential_replies).to be_present
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
2013-09-13 12:49:34 -05:00
|
|
|
it "doesn't notify a user who has less than the `sequential_replies_threshold` threshold posts" do
|
2017-07-07 01:09:14 -05:00
|
|
|
SiteSetting.sequential_replies_threshold = 5
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_sequential_replies).to be_blank
|
2013-09-13 12:49:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify a user if another user posted" do
|
|
|
|
Fabricate(:post, topic: topic, user: Fabricate(:user))
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_sequential_replies).to be_blank
|
2013-09-13 12:49:34 -05:00
|
|
|
end
|
|
|
|
|
2017-02-03 15:59:05 -06:00
|
|
|
it "doesn't notify in a message" do
|
2015-11-27 12:29:44 -06:00
|
|
|
Topic.any_instance.expects(:private_message?).returns(true)
|
|
|
|
expect(finder.check_sequential_replies).to be_blank
|
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with success" do
|
2013-09-13 12:49:34 -05:00
|
|
|
let!(:message) { finder.check_sequential_replies }
|
|
|
|
|
|
|
|
it "returns a message" do
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(message).to be_present
|
2013-09-13 12:49:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a notified_about_sequential_replies log" do
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(UserHistory.exists_for_user?(user, :notified_about_sequential_replies)).to eq(true)
|
2013-09-13 12:49:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-09-12 16:46:43 -05:00
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe ".check_dominating_topic" do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:user)
|
|
|
|
fab!(:topic)
|
2013-09-17 13:38:39 -05:00
|
|
|
|
|
|
|
before do
|
2017-07-07 01:09:14 -05:00
|
|
|
SiteSetting.educate_until_posts = 10
|
2013-09-17 13:38:39 -05:00
|
|
|
user.stubs(:post_count).returns(11)
|
|
|
|
|
2017-07-07 01:09:14 -05:00
|
|
|
SiteSetting.summary_posts_required = 1
|
2013-09-17 13:38:39 -05:00
|
|
|
|
|
|
|
Fabricate(:post, topic: topic, user: user)
|
|
|
|
Fabricate(:post, topic: topic, user: user)
|
|
|
|
Fabricate(:post, topic: topic, user: Fabricate(:user))
|
|
|
|
|
2017-07-07 01:09:14 -05:00
|
|
|
SiteSetting.sequential_replies_threshold = 2
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not give a message for new topics" do
|
2023-01-09 05:18:21 -06:00
|
|
|
finder = ComposerMessagesFinder.new(user, composer_action: "createTopic")
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_dominating_topic).to be_blank
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not give a message without a topic id" do
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(
|
|
|
|
ComposerMessagesFinder.new(user, composer_action: "reply").check_dominating_topic,
|
|
|
|
).to be_blank
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with reply" do
|
2023-01-09 05:18:21 -06:00
|
|
|
let(:finder) do
|
|
|
|
ComposerMessagesFinder.new(user, composer_action: "reply", topic_id: topic.id)
|
|
|
|
end
|
2013-09-17 13:38:39 -05:00
|
|
|
|
|
|
|
it "does not give a message to users who are still in the 'education' phase" do
|
|
|
|
user.stubs(:post_count).returns(9)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_dominating_topic).to be_blank
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
2013-11-18 11:48:26 -06:00
|
|
|
it "does not notify if the `summary_posts_required` has not been reached" do
|
2017-07-07 01:09:14 -05:00
|
|
|
SiteSetting.summary_posts_required = 100
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_dominating_topic).to be_blank
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify a user it has already notified in this topic" do
|
2023-01-09 05:18:21 -06:00
|
|
|
UserHistory.create!(
|
|
|
|
action: UserHistory.actions[:notified_about_dominating_topic],
|
|
|
|
topic_id: topic.id,
|
|
|
|
target_user_id: user.id,
|
|
|
|
)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_dominating_topic).to be_blank
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "notifies a user if the topic is different" do
|
2023-01-09 05:18:21 -06:00
|
|
|
UserHistory.create!(
|
|
|
|
action: UserHistory.actions[:notified_about_dominating_topic],
|
|
|
|
topic_id: topic.id + 1,
|
|
|
|
target_user_id: user.id,
|
|
|
|
)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_dominating_topic).to be_present
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
2013-11-18 11:48:26 -06:00
|
|
|
it "doesn't notify a user if the topic has less than `summary_posts_required` posts" do
|
2017-07-07 01:09:14 -05:00
|
|
|
SiteSetting.summary_posts_required = 5
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_dominating_topic).to be_blank
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify a user if they've posted less than the percentage" do
|
2017-07-07 01:09:14 -05:00
|
|
|
SiteSetting.dominating_topic_minimum_percent = 100
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_dominating_topic).to be_blank
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify you if it's your own topic" do
|
|
|
|
topic.update_column(:user_id, user.id)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_dominating_topic).to be_blank
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
2014-02-06 18:19:45 -06:00
|
|
|
it "doesn't notify you in a private message" do
|
2014-09-11 02:39:20 -05:00
|
|
|
topic.update_columns(category_id: nil, archetype: Archetype.private_message)
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(finder.check_dominating_topic).to be_blank
|
2014-02-06 18:19:45 -06:00
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with success" do
|
2013-09-17 13:38:39 -05:00
|
|
|
let!(:message) { finder.check_dominating_topic }
|
|
|
|
|
|
|
|
it "returns a message" do
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(message).to be_present
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
|
2014-02-06 18:19:45 -06:00
|
|
|
it "creates a notified_about_dominating_topic log" do
|
2015-01-09 10:34:37 -06:00
|
|
|
expect(UserHistory.exists_for_user?(user, :notified_about_dominating_topic)).to eq(true)
|
2013-09-17 13:38:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-20 02:49:35 -05:00
|
|
|
describe "#dont_feed_the_trolls" do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:user)
|
2023-04-20 02:49:35 -05:00
|
|
|
fab!(:author) { Fabricate(:user) }
|
|
|
|
fab!(:other_user) { Fabricate(:user) }
|
|
|
|
fab!(:third_user) { Fabricate(:user) }
|
|
|
|
fab!(:topic) { Fabricate(:topic, user: author) }
|
|
|
|
fab!(:original_post) { Fabricate(:post, topic: topic, user: author) }
|
|
|
|
fab!(:unflagged_post) { Fabricate(:post, topic: topic, user: author) }
|
|
|
|
fab!(:self_flagged_post) { Fabricate(:post, topic: topic, user: author) }
|
|
|
|
fab!(:under_flagged_post) { Fabricate(:post, topic: topic, user: author) }
|
|
|
|
fab!(:over_flagged_post) { Fabricate(:post, topic: topic, user: author) }
|
2023-07-25 02:12:22 -05:00
|
|
|
fab!(:resolved_flag_post) { Fabricate(:post, topic: topic, user: author) }
|
2023-04-20 02:49:35 -05:00
|
|
|
|
|
|
|
before { SiteSetting.dont_feed_the_trolls_threshold = 2 }
|
|
|
|
|
|
|
|
it "does not show a message for unflagged posts" do
|
|
|
|
finder =
|
|
|
|
ComposerMessagesFinder.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
post_id: unflagged_post.id,
|
|
|
|
)
|
|
|
|
expect(finder.check_dont_feed_the_trolls).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows a message when the replier has already flagged the post" do
|
|
|
|
Fabricate(:flag, post: self_flagged_post, user: user)
|
|
|
|
finder =
|
|
|
|
ComposerMessagesFinder.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
post_id: self_flagged_post.id,
|
|
|
|
)
|
|
|
|
expect(finder.check_dont_feed_the_trolls).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows a message when replying to flagged topic (first post)" do
|
|
|
|
Fabricate(:flag, post: original_post, user: user)
|
|
|
|
finder = ComposerMessagesFinder.new(user, composer_action: "reply", topic_id: topic.id)
|
|
|
|
expect(finder.check_dont_feed_the_trolls).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not show a message when not enough others have flagged the post" do
|
|
|
|
Fabricate(:flag, post: under_flagged_post, user: other_user)
|
|
|
|
finder =
|
|
|
|
ComposerMessagesFinder.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
post_id: under_flagged_post.id,
|
|
|
|
)
|
|
|
|
expect(finder.check_dont_feed_the_trolls).to be_blank
|
|
|
|
end
|
|
|
|
|
2023-07-25 02:12:22 -05:00
|
|
|
it "does not show a message when the flag has already been resolved" do
|
|
|
|
SiteSetting.dont_feed_the_trolls_threshold = 1
|
|
|
|
|
|
|
|
Fabricate(:flag, post: resolved_flag_post, user: other_user, disagreed_at: 1.hour.ago)
|
|
|
|
finder =
|
|
|
|
ComposerMessagesFinder.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
post_id: resolved_flag_post.id,
|
|
|
|
)
|
|
|
|
expect(finder.check_dont_feed_the_trolls).to be_blank
|
|
|
|
end
|
|
|
|
|
2023-04-20 02:49:35 -05:00
|
|
|
it "shows a message when enough others have already flagged the post" do
|
|
|
|
Fabricate(:flag, post: over_flagged_post, user: other_user)
|
|
|
|
Fabricate(:flag, post: over_flagged_post, user: third_user)
|
|
|
|
finder =
|
|
|
|
ComposerMessagesFinder.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
post_id: over_flagged_post.id,
|
|
|
|
)
|
|
|
|
expect(finder.check_dont_feed_the_trolls).to be_present
|
|
|
|
end
|
2023-04-25 10:08:00 -05:00
|
|
|
|
|
|
|
it "safely returns from not finding a post" do
|
|
|
|
finder = ComposerMessagesFinder.new(user, composer_action: "reply", topic_id: nil)
|
|
|
|
expect(finder.check_dont_feed_the_trolls).to be_blank
|
|
|
|
end
|
2023-04-20 02:49:35 -05:00
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe ".check_get_a_room" do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:user)
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:other_user) { Fabricate(:user) }
|
|
|
|
fab!(:third_user) { Fabricate(:user) }
|
|
|
|
fab!(:topic) { Fabricate(:topic, user: other_user) }
|
|
|
|
fab!(:op) { Fabricate(:post, topic_id: topic.id, user: other_user) }
|
2017-02-03 15:59:05 -06:00
|
|
|
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:other_user_reply) do
|
2017-02-03 15:59:05 -06:00
|
|
|
Fabricate(:post, topic: topic, user: third_user, reply_to_user_id: op.user_id)
|
2017-02-08 11:24:02 -06:00
|
|
|
end
|
2017-02-03 15:59:05 -06:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
fab!(:first_reply) { Fabricate(:post, topic: topic, user: user, reply_to_user_id: op.user_id) }
|
2017-02-03 15:59:05 -06:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
fab!(:second_reply) { Fabricate(:post, topic: topic, user: user, reply_to_user_id: op.user_id) }
|
2017-02-03 15:59:05 -06:00
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.educate_until_posts = 10
|
|
|
|
user.stubs(:post_count).returns(11)
|
|
|
|
SiteSetting.get_a_room_threshold = 2
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not show the message for new topics" do
|
2023-01-09 05:18:21 -06:00
|
|
|
finder = ComposerMessagesFinder.new(user, composer_action: "createTopic")
|
2017-02-28 15:47:16 -06:00
|
|
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
2017-02-03 15:59:05 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not give a message without a topic id" do
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(
|
|
|
|
ComposerMessagesFinder.new(user, composer_action: "reply").check_get_a_room(
|
|
|
|
min_users_posted: 2,
|
|
|
|
),
|
|
|
|
).to be_blank
|
2017-02-03 15:59:05 -06:00
|
|
|
end
|
|
|
|
|
2021-04-14 12:34:13 -05:00
|
|
|
it "does not give a message if the topic's category is read_restricted" do
|
|
|
|
topic.category.update(read_restricted: true)
|
2023-01-09 05:18:21 -06:00
|
|
|
finder =
|
|
|
|
ComposerMessagesFinder.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
post_id: op.id,
|
|
|
|
)
|
2021-04-14 12:34:13 -05:00
|
|
|
finder.check_get_a_room(min_users_posted: 2)
|
|
|
|
expect(UserHistory.exists_for_user?(user, :notified_about_get_a_room)).to eq(false)
|
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with reply" do
|
2023-01-09 05:18:21 -06:00
|
|
|
let(:finder) do
|
|
|
|
ComposerMessagesFinder.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
post_id: op.id,
|
|
|
|
)
|
|
|
|
end
|
2017-02-03 15:59:05 -06:00
|
|
|
|
|
|
|
it "does not give a message to users who are still in the 'education' phase" do
|
|
|
|
user.stubs(:post_count).returns(9)
|
2017-02-28 15:47:16 -06:00
|
|
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
2017-02-03 15:59:05 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify a user it has already notified about sequential replies" do
|
|
|
|
UserHistory.create!(
|
|
|
|
action: UserHistory.actions[:notified_about_get_a_room],
|
|
|
|
target_user_id: user.id,
|
2023-01-09 05:18:21 -06:00
|
|
|
topic_id: topic.id,
|
2017-02-03 15:59:05 -06:00
|
|
|
)
|
2017-02-28 15:47:16 -06:00
|
|
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
2017-02-03 15:59:05 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "will notify you if it hasn't in the current topic" do
|
|
|
|
UserHistory.create!(
|
|
|
|
action: UserHistory.actions[:notified_about_get_a_room],
|
|
|
|
target_user_id: user.id,
|
2023-01-09 05:18:21 -06:00
|
|
|
topic_id: topic.id + 1,
|
2017-02-03 15:59:05 -06:00
|
|
|
)
|
2017-02-28 15:47:16 -06:00
|
|
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_present
|
2017-02-03 15:59:05 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "won't notify you if you haven't had enough posts" do
|
|
|
|
SiteSetting.get_a_room_threshold = 10
|
2017-02-28 15:47:16 -06:00
|
|
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
2017-02-03 15:59:05 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify you if the posts aren't all to the same person" do
|
|
|
|
first_reply.update_column(:reply_to_user_id, user.id)
|
2017-02-28 15:47:16 -06:00
|
|
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
2017-02-03 15:59:05 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify you of posts to yourself" do
|
|
|
|
first_reply.update_column(:reply_to_user_id, user.id)
|
|
|
|
second_reply.update_column(:reply_to_user_id, user.id)
|
2017-02-28 15:47:16 -06:00
|
|
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
2017-02-03 15:59:05 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify in a message" do
|
2023-01-09 05:18:21 -06:00
|
|
|
topic.update_columns(category_id: nil, archetype: "private_message")
|
2017-02-28 15:47:16 -06:00
|
|
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
2017-02-03 15:59:05 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify when replying to a different user" do
|
2023-01-09 05:18:21 -06:00
|
|
|
other_finder =
|
|
|
|
ComposerMessagesFinder.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
post_id: other_user_reply.id,
|
|
|
|
)
|
2017-02-03 15:59:05 -06:00
|
|
|
|
2017-02-28 15:47:16 -06:00
|
|
|
expect(other_finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
2017-02-03 15:59:05 -06:00
|
|
|
end
|
|
|
|
|
2017-02-28 15:47:16 -06:00
|
|
|
context "with a default min_users_posted value" do
|
2017-02-03 15:59:05 -06:00
|
|
|
let!(:message) { finder.check_get_a_room }
|
|
|
|
|
2017-02-28 15:47:16 -06:00
|
|
|
it "works as expected" do
|
|
|
|
expect(message).to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with success" do
|
2017-02-28 15:47:16 -06:00
|
|
|
let!(:message) { finder.check_get_a_room(min_users_posted: 2) }
|
|
|
|
|
2017-02-03 15:59:05 -06:00
|
|
|
it "works as expected" do
|
|
|
|
expect(message).to be_present
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(message[:id]).to eq("get_a_room")
|
2017-02-08 11:24:02 -06:00
|
|
|
expect(message[:wait_for_typing]).to eq(true)
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(message[:templateName]).to eq("get-a-room")
|
2017-02-08 11:24:02 -06:00
|
|
|
|
2017-02-03 15:59:05 -06:00
|
|
|
expect(UserHistory.exists_for_user?(user, :notified_about_get_a_room)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe ".check_reviving_old_topic" do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:user)
|
|
|
|
fab!(:topic)
|
2014-03-12 09:44:08 -05:00
|
|
|
|
|
|
|
it "does not give a message without a topic id" do
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(
|
|
|
|
described_class.new(user, composer_action: "createTopic").check_reviving_old_topic,
|
|
|
|
).to be_blank
|
|
|
|
expect(
|
|
|
|
described_class.new(user, composer_action: "reply").check_reviving_old_topic,
|
|
|
|
).to be_blank
|
2014-03-12 09:44:08 -05:00
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with a reply" do
|
|
|
|
context "when warn_reviving_old_topic_age is 180 days" do
|
2023-01-09 05:18:21 -06:00
|
|
|
before { SiteSetting.warn_reviving_old_topic_age = 180 }
|
2014-03-12 09:44:08 -05:00
|
|
|
|
|
|
|
it "does not notify if last post is recent" do
|
|
|
|
topic = Fabricate(:topic, last_posted_at: 1.hour.ago)
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(
|
|
|
|
described_class.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
).check_reviving_old_topic,
|
|
|
|
).to be_blank
|
2014-03-12 09:44:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "notifies if last post is old" do
|
|
|
|
topic = Fabricate(:topic, last_posted_at: 181.days.ago)
|
2023-01-09 05:18:21 -06:00
|
|
|
message =
|
|
|
|
described_class.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
).check_reviving_old_topic
|
2018-01-25 12:36:53 -06:00
|
|
|
expect(message).not_to be_blank
|
|
|
|
expect(message[:body]).to match(/6 months ago/)
|
2014-03-12 09:44:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "when warn_reviving_old_topic_age is 0" do
|
2023-01-09 05:18:21 -06:00
|
|
|
before { SiteSetting.warn_reviving_old_topic_age = 0 }
|
2014-03-12 09:44:08 -05:00
|
|
|
|
|
|
|
it "does not notify if last post is new" do
|
|
|
|
topic = Fabricate(:topic, last_posted_at: 1.hour.ago)
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(
|
|
|
|
described_class.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
).check_reviving_old_topic,
|
|
|
|
).to be_blank
|
2014-03-12 09:44:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not notify if last post is old" do
|
|
|
|
topic = Fabricate(:topic, last_posted_at: 365.days.ago)
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(
|
|
|
|
described_class.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
).check_reviving_old_topic,
|
|
|
|
).to be_blank
|
2014-03-12 09:44:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
context "when editing a post" do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:user)
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:topic) { Fabricate(:post).topic }
|
2018-10-03 19:21:53 -05:00
|
|
|
|
|
|
|
let!(:post) do
|
2023-01-09 05:18:21 -06:00
|
|
|
PostCreator.create!(user, topic_id: topic.id, post_number: 1, raw: "omg my first post")
|
2018-10-03 19:21:53 -05:00
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
let(:edit_post_finder) { ComposerMessagesFinder.new(user, composer_action: "edit") }
|
2018-10-03 19:21:53 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.disable_avatar_education_message = true
|
|
|
|
SiteSetting.educate_until_posts = 2
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nothing even if it normally would" do
|
|
|
|
expect(edit_post_finder.find).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
2022-09-27 11:36:40 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe "#user_not_seen_in_a_while" do
|
2022-09-27 11:36:40 -05:00
|
|
|
fab!(:user_1) { Fabricate(:user, last_seen_at: 3.years.ago) }
|
|
|
|
fab!(:user_2) { Fabricate(:user, last_seen_at: 2.years.ago) }
|
|
|
|
fab!(:user_3) { Fabricate(:user, last_seen_at: 6.months.ago) }
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
before { SiteSetting.pm_warn_user_last_seen_months_ago = 24 }
|
2022-09-27 11:36:40 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "returns users that have not been seen recently" do
|
|
|
|
users =
|
|
|
|
ComposerMessagesFinder.user_not_seen_in_a_while(
|
|
|
|
[user_1.username, user_2.username, user_3.username],
|
|
|
|
)
|
2022-09-27 11:36:40 -05:00
|
|
|
expect(users).to contain_exactly(user_1.username, user_2.username)
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "accounts for pm_warn_user_last_seen_months_ago site setting" do
|
2022-09-27 11:36:40 -05:00
|
|
|
SiteSetting.pm_warn_user_last_seen_months_ago = 30
|
2023-01-09 05:18:21 -06:00
|
|
|
users =
|
|
|
|
ComposerMessagesFinder.user_not_seen_in_a_while(
|
|
|
|
[user_1.username, user_2.username, user_3.username],
|
|
|
|
)
|
2022-09-27 11:36:40 -05:00
|
|
|
expect(users).to contain_exactly(user_1.username)
|
|
|
|
end
|
|
|
|
end
|
2013-09-12 16:46:43 -05:00
|
|
|
end
|