discourse/spec/models/topic_posters_summary_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
RSpec.describe TopicPostersSummary do
2013-05-23 02:21:19 -04:00
describe "#summary" do
let!(:topic_creator) { Fabricate(:user) }
2013-05-23 02:21:19 -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
let!(:summary) { described_class.new(topic).summary }
2013-05-23 02:21:19 -04:00
it "contains only the topic creator" do
expect(summary.count).to eq 1
2013-05-23 02:21:19 -04:00
summary.first.tap do |topic_poster|
expect(topic_poster.user).to eq topic_creator
Fix i18n issues reported on Crowdin (#11747) * Pluralize `groups.errors.adding_too_many_users` This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/248/en-ar#53882 * Pluralize `js.composer.error.title_too_short` This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#41172 * Pluralize `js.composer.error.title_too_long` This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#41174 * Pluralize `js.composer.error.post_length` This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#41178 * Pluralize `js.topic.progress.jump_prompt_of` This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#41958 * Use translations to join strings about posters This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/248/en-ar#49334 It also makes some changes to the crawler view: * Removes `poster.moreCount` which is only available on the client for PMs * CSS class names are actually stored in `poster.extras` instead of `poster.extraClasses` * Stop concatenating category stats This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#40740 * Pluralize `js.summary.description` This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#40782 * Pluralize `js.summary.description_time_MF` This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#40784 * Use translation to join list of tags This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#43372 * Pluralize `admin_js.admin.groups.manage.membership.automatic_membership_user_count` This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#43720 * Pluralize `js.post.controls.delete_topic_confirm_modal` This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#54804 * Stop concatenating `js.post.last_edited_on` This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#42358 * Stop concatenating `js.post.wiki_last_edited_on` This fixes https://discourse.crowdin.com/translate/f3230e7607a36bb0a2f97fd90605a44e/246/en-ar#42356 It also fixes a regression because `js.post.wiki_last_edited_on` wasn't used anymore since 2017.
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),
),
)
end
2013-05-23 02:21:19 -04:00
end
end
context "when the last poster is also the topic creator" do
fab!(:featured_user1) { Fabricate(:user) }
2013-05-23 02:21:19 -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
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
let!(:last_poster) { Fabricate(:user) }
fab!(:featured_user1) { Fabricate(:user) }
fab!(:featured_user2) { Fabricate(:user) }
fab!(:featured_user3) { Fabricate(:user) }
fab!(: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 }
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],
)
# 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