2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe TopicPostersSummary do
|
2013-05-23 02:21:19 -04:00
|
|
|
describe "#summary" do
|
2019-04-29 21:41:24 -04:00
|
|
|
let!(:topic_creator) { Fabricate(:user) }
|
2013-05-23 02:21:19 -04:00
|
|
|
|
2019-04-29 21:41:24 -04:00
|
|
|
context "when there are no other posters" do
|
|
|
|
let!(:topic) { Fabricate(:topic, user: topic_creator) }
|
2013-05-23 02:21:19 -04:00
|
|
|
|
2019-04-29 21:41:24 -04:00
|
|
|
let!(:summary) { described_class.new(topic).summary }
|
2013-05-23 02:21:19 -04:00
|
|
|
|
2019-04-29 21:41:24 -04:00
|
|
|
it "contains only the topic creator" do
|
|
|
|
expect(summary.count).to eq 1
|
2013-05-23 02:21:19 -04:00
|
|
|
|
2019-04-29 21:41:24 -04:00
|
|
|
summary.first.tap do |topic_poster|
|
|
|
|
expect(topic_poster.user).to eq topic_creator
|
2021-02-02 04:50:04 -05:00
|
|
|
expect(topic_poster.description).to eq(
|
|
|
|
[I18n.t(:original_poster), I18n.t(:most_recent_poster)].join(
|
|
|
|
I18n.t(:poster_description_joiner),
|
2023-01-09 06:18:21 -05:00
|
|
|
),
|
2019-04-29 21:41:24 -04:00
|
|
|
)
|
|
|
|
end
|
2013-05-23 02:21:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-29 21:41:24 -04:00
|
|
|
context "when the last poster is also the topic creator" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:featured_user1) { Fabricate(:user) }
|
2013-05-23 02:21:19 -04:00
|
|
|
|
2019-04-29 21:41:24 -04:00
|
|
|
let!(:topic) do
|
|
|
|
Fabricate(
|
|
|
|
:topic,
|
|
|
|
user: topic_creator,
|
|
|
|
last_poster: topic_creator,
|
|
|
|
featured_user1: featured_user1,
|
|
|
|
)
|
2013-05-23 02:21:19 -04:00
|
|
|
end
|
|
|
|
|
2019-04-29 21:41:24 -04:00
|
|
|
let!(:summary) { described_class.new(topic).summary }
|
|
|
|
|
2013-05-23 02:21:19 -04:00
|
|
|
it "keeps the topic creator at the front of the summary" do
|
|
|
|
expect(summary.map(&:user)).to eq([topic_creator, featured_user1])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the topic has many posters" do
|
2019-04-29 21:41:24 -04:00
|
|
|
let!(:last_poster) { Fabricate(:user) }
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:featured_user1) { Fabricate(:user) }
|
|
|
|
fab!(:featured_user2) { Fabricate(:user) }
|
|
|
|
fab!(:featured_user3) { Fabricate(:user) }
|
|
|
|
fab!(:featured_user4) { Fabricate(:user) }
|
2019-04-29 21:41:24 -04:00
|
|
|
|
|
|
|
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 }
|
2013-05-23 02:21:19 -04:00
|
|
|
|
|
|
|
it "contains only five posters with latest poster at the end" do
|
|
|
|
expect(summary.map(&:user)).to eq(
|
|
|
|
[topic_creator, featured_user1, featured_user2, featured_user3, last_poster],
|
|
|
|
)
|
2014-08-20 12:09:39 -04:00
|
|
|
# If more than one user, attach the latest class
|
|
|
|
expect(summary.last.extras).to eq "latest"
|
2013-05-23 02:21:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|