mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 07:53:39 +08:00
b3d769ff4f
update rspec syntax to v3 change syntax to rspec v3 oops. fix typo mailers classes with rspec3 syntax helpers with rspec3 syntax jobs with rspec3 syntax serializers with rspec3 syntax views with rspec3 syntax support to rspec3 syntax category spec with rspec3 syntax
75 lines
2.4 KiB
Ruby
75 lines
2.4 KiB
Ruby
require 'spec_helper'
|
|
require_dependency 'jobs/base'
|
|
require 'jobs/regular/process_post'
|
|
|
|
describe Jobs::FeatureTopicUsers do
|
|
|
|
it "raises an error without a topic_id" do
|
|
expect { Jobs::FeatureTopicUsers.new.execute({}) }.to raise_error(Discourse::InvalidParameters)
|
|
end
|
|
|
|
it "raises an error with a missing topic_id" do
|
|
expect { Jobs::FeatureTopicUsers.new.execute(topic_id: 123) }.to raise_error(Discourse::InvalidParameters)
|
|
end
|
|
|
|
context 'with a topic' do
|
|
let!(:post) { create_post }
|
|
let(:topic) { post.topic }
|
|
let!(:coding_horror) { Fabricate(:coding_horror) }
|
|
let!(:evil_trout) { Fabricate(:evil_trout) }
|
|
let!(:second_post) { create_post(topic: topic, user: coding_horror)}
|
|
let!(:third_post) { create_post(topic: topic, user: evil_trout)}
|
|
|
|
it "won't feature the OP" do
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
|
expect(topic.reload.featured_user_ids.include?(topic.user_id)).to eq(false)
|
|
end
|
|
|
|
it "features the second poster" do
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
|
expect(topic.reload.featured_user_ids.include?(coding_horror.id)).to eq(true)
|
|
end
|
|
|
|
it "will not feature the second poster if we supply their post to be ignored" do
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id, except_post_id: second_post.id)
|
|
expect(topic.reload.featured_user_ids.include?(coding_horror.id)).to eq(false)
|
|
end
|
|
|
|
it "won't feature the last poster" do
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
|
expect(topic.reload.featured_user_ids.include?(evil_trout.id)).to eq(false)
|
|
end
|
|
|
|
end
|
|
|
|
context "participant count" do
|
|
|
|
let!(:post) { create_post }
|
|
let(:topic) { post.topic }
|
|
|
|
|
|
it "it works as expected" do
|
|
|
|
# It has 1 participant after creation
|
|
expect(topic.participant_count).to eq(1)
|
|
|
|
# It still has 1 after featuring
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
|
expect(topic.reload.participant_count).to eq(1)
|
|
|
|
# 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)
|
|
expect(topic.reload.participant_count).to eq(1)
|
|
|
|
# If another users posts, it's 2.
|
|
create_post(topic: topic, user: Fabricate(:evil_trout))
|
|
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
|
expect(topic.reload.participant_count).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|