diff --git a/app/serializers/concerns/user_primary_group_mixin.rb b/app/serializers/concerns/user_primary_group_mixin.rb index 0bd2538b1eb..3a0de3e4c45 100644 --- a/app/serializers/concerns/user_primary_group_mixin.rb +++ b/app/serializers/concerns/user_primary_group_mixin.rb @@ -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 diff --git a/spec/serializers/poster_serializer_spec.rb b/spec/serializers/poster_serializer_spec.rb new file mode 100644 index 00000000000..d982165fbf6 --- /dev/null +++ b/spec/serializers/poster_serializer_spec.rb @@ -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