mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 22:21:55 +08:00
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:
parent
b988f13817
commit
3abc542e63
|
@ -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
|
||||
|
|
40
spec/serializers/poster_serializer_spec.rb
Normal file
40
spec/serializers/poster_serializer_spec.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user