From 5e0f9eadb8d24de9502be49c6f430156a12fabbf Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Fri, 11 Jan 2019 23:39:06 +0530 Subject: [PATCH] FIX: show user avatar on User summary page (#6872) --- app/serializers/user_summary_serializer.rb | 8 +++++-- .../serializers/basic_user_serializer_spec.rb | 4 +++- .../user_summary_serializer_spec.rb | 24 +++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 spec/serializers/user_summary_serializer_spec.rb diff --git a/app/serializers/user_summary_serializer.rb b/app/serializers/user_summary_serializer.rb index fcb5a00aeb7..cf09cde0641 100644 --- a/app/serializers/user_summary_serializer.rb +++ b/app/serializers/user_summary_serializer.rb @@ -18,8 +18,12 @@ class UserSummarySerializer < ApplicationSerializer end end - class UserWithCountSerializer < BasicUserSerializer - attributes :count, :name + class UserWithCountSerializer < ApplicationSerializer + attributes :id, :username, :name, :count, :avatar_template + + def avatar_template + User.avatar_template(object[:username], object[:uploaded_avatar_id]) + end end class CategoryWithCountsSerializer < ApplicationSerializer diff --git a/spec/serializers/basic_user_serializer_spec.rb b/spec/serializers/basic_user_serializer_spec.rb index 551df2c3aab..7480f07f87c 100644 --- a/spec/serializers/basic_user_serializer_spec.rb +++ b/spec/serializers/basic_user_serializer_spec.rb @@ -22,6 +22,8 @@ describe BasicUserSerializer do expect(json[:name]).to be_blank end + it "returns the avatar_template" do + expect(json[:avatar_template]).to be_present + end end - end diff --git a/spec/serializers/user_summary_serializer_spec.rb b/spec/serializers/user_summary_serializer_spec.rb new file mode 100644 index 00000000000..80db2ad008f --- /dev/null +++ b/spec/serializers/user_summary_serializer_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +describe UserSummarySerializer do + it "returns expected data" do + UserActionCreator.enable + user = Fabricate(:user) + liked_post = create_post + PostAction.act(user, liked_post, PostActionType.types[:like]) + + guardian = Guardian.new(user) + summary = UserSummary.new(user, guardian) + serializer = UserSummarySerializer.new(summary, scope: guardian, root: false) + json = serializer.as_json + + expect(json[:likes_given]).to be_present + expect(json[:likes_received]).to be_present + expect(json[:posts_read_count]).to be_present + expect(json[:topic_count]).to be_present + expect(json[:time_read]).to be_present + expect(json[:most_liked_users][0][:count]).to be_present + expect(json[:most_liked_users][0][:username]).to be_present + expect(json[:most_liked_users][0][:avatar_template]).to be_present + end +end