DEV: Spec clarification example (#7458)

This commit is contained in:
Daniel Waterworth 2019-04-30 01:41:24 +00:00 committed by Guo Xiang Tan
parent 7b1783bae8
commit 75a6c440f7

View File

@ -4,27 +4,18 @@ require 'rails_helper'
describe TopicPostersSummary do
describe '#summary' do
let(:summary) { described_class.new(topic).summary }
let!(:topic_creator) { Fabricate(:user) }
let(:topic) do
context "when there are no other posters" do
let!(:topic) do
Fabricate(:topic,
user: topic_creator,
last_poster: last_poster,
featured_user1: featured_user1,
featured_user2: featured_user2,
featured_user3: featured_user3,
featured_user4: featured_user4
)
end
let(:topic_creator) { Fabricate(:user) }
let(:last_poster) { nil }
let(:featured_user1) { nil }
let(:featured_user2) { nil }
let(:featured_user3) { nil }
let(:featured_user4) { nil }
let!(:summary) { described_class.new(topic).summary }
it 'contains only the topic creator when there are no other posters' do
it 'contains only the topic creator' do
expect(summary.count).to eq 1
summary.first.tap do |topic_poster|
@ -34,17 +25,21 @@ describe TopicPostersSummary do
)
end
end
context 'when the lastest poster is also the topic creator' do
let(:last_poster) { topic_creator }
let(:featured_user1) { Fabricate(:user) }
before do
topic.last_poster = topic_creator
topic.featured_user1 = featured_user1
topic.save!
end
context 'when the last poster is also the topic creator' do
let!(:featured_user1) { Fabricate(:user) }
let!(:topic) do
Fabricate(:topic,
user: topic_creator,
last_poster: topic_creator,
featured_user1: featured_user1,
)
end
let!(:summary) { described_class.new(topic).summary }
it 'keeps the topic creator at the front of the summary' do
expect(summary.map(&:user)).to eq([
topic_creator,
@ -54,11 +49,24 @@ describe TopicPostersSummary do
end
context 'when the topic has many posters' do
let(:last_poster) { Fabricate(:user) }
let(:featured_user1) { Fabricate(:user) }
let(:featured_user2) { Fabricate(:user) }
let(:featured_user3) { Fabricate(:user) }
let(:featured_user4) { Fabricate(:user) }
let!(:last_poster) { Fabricate(:user) }
let!(:featured_user1) { Fabricate(:user) }
let!(:featured_user2) { Fabricate(:user) }
let!(:featured_user3) { Fabricate(:user) }
let!(:featured_user4) { Fabricate(:user) }
let!(:topic) do
Fabricate(:topic,
user: topic_creator,
last_poster: last_poster,
featured_user1: featured_user1,
featured_user2: featured_user2,
featured_user3: featured_user3,
featured_user4: featured_user4
)
end
let!(:summary) { described_class.new(topic).summary }
it 'contains only five posters with latest poster at the end' do
expect(summary.map(&:user)).to eq([