discourse/spec/jobs/feature_topic_users_spec.rb
Andy Waite 3e50313fdc Prepare for separation of RSpec helper files
Since rspec-rails 3, the default installation creates two helper files:
* `spec_helper.rb`
* `rails_helper.rb`

`spec_helper.rb` is intended as a way of running specs that do not
require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's
current `spec_helper.rb` does).

For more information:

https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files

In this commit, I've simply replaced all instances of `spec_helper` with
`rails_helper`, and renamed the original `spec_helper.rb`.

This brings the Discourse project closer to the standard usage of RSpec
in a Rails app.

At present, every spec relies on loading Rails, but there are likely
many that don't need to. In a future pull request, I hope to introduce a
separate, minimal `spec_helper.rb` which can be used in tests which
don't rely on Rails.
2015-12-01 20:39:42 +00:00

70 lines
2.1 KiB
Ruby

require 'rails_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 no error with a missing topic_id" do
Jobs::FeatureTopicUsers.new.execute(topic_id: 123)
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 "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