FIX: Include group flair in homepage category topic lists (#21268)

Followup to c03f83bbea.

The `flair_group_id` parameter is now required to show the flair, and this serializer was missing that detail. 

This also fixes a typo in the `include_flair_group_name?` method.
This commit is contained in:
Penar Musaraj 2023-04-26 22:18:16 -04:00 committed by GitHub
parent b988f13817
commit 3abc542e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 1 deletions

View File

@ -7,6 +7,7 @@ module UserPrimaryGroupMixin
:flair_url,
:flair_bg_color,
:flair_color,
:flair_group_id,
:admin,
:moderator,
:trust_level
@ -24,7 +25,7 @@ module UserPrimaryGroupMixin
object&.flair_group&.name
end
def include_flair_group_name?
def include_flair_name?
object&.flair_group.present?
end
@ -44,6 +45,14 @@ module UserPrimaryGroupMixin
object&.flair_group&.flair_bg_color.present?
end
def flair_group_id
object&.flair_group_id
end
def include_flair_group_id?
object&.flair_group_id.present?
end
def flair_color
object&.flair_group&.flair_color
end

View File

@ -0,0 +1,40 @@
# frozen_string_literal: true
RSpec.describe PosterSerializer do
let(:poster) { Fabricate(:user, admin: false, moderator: false) }
it "serializes the correct attributes" do
expect(PosterSerializer.new(poster).attributes.keys).to contain_exactly(
:trust_level,
:avatar_template,
:id,
:name,
:username,
)
end
it "includes group flair attributes when appropriate" do
group =
Fabricate(
:group,
name: "Groupster",
flair_bg_color: "#111111",
flair_color: "#999999",
flair_icon: "icon",
)
groupie = Fabricate(:user, flair_group: group)
expect(PosterSerializer.new(groupie).attributes.keys).to contain_exactly(
:trust_level,
:avatar_template,
:id,
:name,
:username,
:flair_bg_color,
:flair_color,
:flair_group_id,
:flair_name,
:flair_url,
)
end
end