2013-02-06 03:16:51 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'jobs/process_post'
|
|
|
|
|
|
|
|
describe Jobs::FeatureTopicUsers do
|
|
|
|
|
|
|
|
it "raises an error without a topic_id" do
|
|
|
|
lambda { Jobs::FeatureTopicUsers.new.execute({}) }.should raise_error(Discourse::InvalidParameters)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error with a missing topic_id" do
|
|
|
|
lambda { Jobs::FeatureTopicUsers.new.execute(topic_id: 123) }.should raise_error(Discourse::InvalidParameters)
|
|
|
|
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 }
|
|
|
|
let!(:coding_horror) { Fabricate(:coding_horror) }
|
|
|
|
let!(:evil_trout) { Fabricate(: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)
|
|
|
|
topic.reload.featured_user_ids.include?(topic.user_id).should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "features the second poster" do
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
|
|
|
topic.reload.featured_user_ids.include?(coding_horror.id).should be_true
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
it "will not feature the second poster if we supply their post to be ignored" do
|
2013-02-06 03:16:51 +08:00
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id, except_post_id: second_post.id)
|
|
|
|
topic.reload.featured_user_ids.include?(coding_horror.id).should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "won't feature the last poster" do
|
|
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
|
|
|
topic.reload.featured_user_ids.include?(evil_trout.id).should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|