2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Jobs::FeatureTopicUsers do
|
2013-02-06 03:16:51 +08:00
|
|
|
it "raises an error without a topic_id" do
|
2014-12-31 22:55:03 +08:00
|
|
|
expect { Jobs::FeatureTopicUsers.new.execute({}) }.to raise_error(Discourse::InvalidParameters)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2015-08-14 14:26:53 +08:00
|
|
|
it "raises no error with a missing topic_id" do
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: 123)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with a topic" do
|
2013-07-22 13:06:53 +08:00
|
|
|
let!(:post) { create_post }
|
2013-02-06 03:16:51 +08:00
|
|
|
let(:topic) { post.topic }
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:coding_horror)
|
|
|
|
fab!(:evil_trout)
|
2013-07-22 13:06:53 +08:00
|
|
|
let!(:second_post) { create_post(topic: topic, user: coding_horror) }
|
|
|
|
let!(:third_post) { create_post(topic: topic, user: evil_trout) }
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
it "won't feature the OP" do
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.reload.featured_user_ids.include?(topic.user_id)).to eq(false)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "features the second poster" do
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.reload.featured_user_ids.include?(coding_horror.id)).to eq(true)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "won't feature the last poster" do
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.reload.featured_user_ids.include?(evil_trout.id)).to eq(false)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
context "with participant count" do
|
2013-11-15 03:32:41 +08:00
|
|
|
let!(:post) { create_post }
|
|
|
|
let(:topic) { post.topic }
|
|
|
|
|
|
|
|
it "it works as expected" do
|
|
|
|
# It has 1 participant after creation
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.participant_count).to eq(1)
|
2013-11-15 03:32:41 +08:00
|
|
|
|
|
|
|
# It still has 1 after featuring
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.reload.participant_count).to eq(1)
|
2013-11-15 03:32:41 +08:00
|
|
|
|
|
|
|
# If the OP makes another post, it's still 1.
|
|
|
|
create_post(topic: topic, user: post.user)
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.reload.participant_count).to eq(1)
|
2013-11-15 03:32:41 +08:00
|
|
|
|
|
|
|
# If another users posts, it's 2.
|
|
|
|
create_post(topic: topic, user: Fabricate(:evil_trout))
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.reload.participant_count).to eq(2)
|
2013-11-15 03:32:41 +08:00
|
|
|
end
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|