2013-02-05 13:16:51 -06:00
|
|
|
require 'spec_helper'
|
2013-10-01 02:04:02 -05:00
|
|
|
require_dependency 'jobs/base'
|
|
|
|
require 'jobs/regular/process_post'
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
describe Jobs::FeatureTopicUsers do
|
|
|
|
|
|
|
|
it "raises an error without a topic_id" do
|
2014-12-31 08:55:03 -06:00
|
|
|
expect { Jobs::FeatureTopicUsers.new.execute({}) }.to raise_error(Discourse::InvalidParameters)
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error with a missing topic_id" do
|
2014-12-31 08:55:03 -06:00
|
|
|
expect { Jobs::FeatureTopicUsers.new.execute(topic_id: 123) }.to raise_error(Discourse::InvalidParameters)
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a topic' do
|
2013-07-22 00:06:53 -05:00
|
|
|
let!(:post) { create_post }
|
2013-02-05 13:16:51 -06:00
|
|
|
let(:topic) { post.topic }
|
|
|
|
let!(:coding_horror) { Fabricate(:coding_horror) }
|
|
|
|
let!(:evil_trout) { Fabricate(:evil_trout) }
|
2013-07-22 00:06:53 -05:00
|
|
|
let!(:second_post) { create_post(topic: topic, user: coding_horror)}
|
|
|
|
let!(:third_post) { create_post(topic: topic, user: evil_trout)}
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
it "won't feature the OP" do
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(topic.reload.featured_user_ids.include?(topic.user_id)).to eq(false)
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "features the second poster" do
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(topic.reload.featured_user_ids.include?(coding_horror.id)).to eq(true)
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
2013-02-25 10:42:20 -06:00
|
|
|
it "will not feature the second poster if we supply their post to be ignored" do
|
2013-02-05 13:16:51 -06:00
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id, except_post_id: second_post.id)
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(topic.reload.featured_user_ids.include?(coding_horror.id)).to eq(false)
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "won't feature the last poster" do
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(topic.reload.featured_user_ids.include?(evil_trout.id)).to eq(false)
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-11-14 13:32:41 -06:00
|
|
|
context "participant count" do
|
|
|
|
|
|
|
|
let!(:post) { create_post }
|
|
|
|
let(:topic) { post.topic }
|
|
|
|
|
|
|
|
|
|
|
|
it "it works as expected" do
|
|
|
|
|
|
|
|
# It has 1 participant after creation
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(topic.participant_count).to eq(1)
|
2013-11-14 13:32:41 -06:00
|
|
|
|
|
|
|
# It still has 1 after featuring
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(topic.reload.participant_count).to eq(1)
|
2013-11-14 13:32:41 -06: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 08:55:03 -06:00
|
|
|
expect(topic.reload.participant_count).to eq(1)
|
2013-11-14 13:32:41 -06: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 08:55:03 -06:00
|
|
|
expect(topic.reload.participant_count).to eq(2)
|
2013-11-14 13:32:41 -06:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|