From 5e9a7e41e9c4552cf8caf6e152f2f806f2f602ee Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 14 Jan 2019 07:19:37 +0530 Subject: [PATCH] DEV: improve UserSummarySerializer spec --- spec/serializers/user_summary_serializer_spec.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/spec/serializers/user_summary_serializer_spec.rb b/spec/serializers/user_summary_serializer_spec.rb index 80db2ad008f..cd7387c8b9f 100644 --- a/spec/serializers/user_summary_serializer_spec.rb +++ b/spec/serializers/user_summary_serializer_spec.rb @@ -4,7 +4,8 @@ describe UserSummarySerializer do it "returns expected data" do UserActionCreator.enable user = Fabricate(:user) - liked_post = create_post + liked_user = Fabricate(:user, name: "John Doe", username: "john_doe") + liked_post = create_post(user: liked_user) PostAction.act(user, liked_post, PostActionType.types[:like]) guardian = Guardian.new(user) @@ -17,8 +18,13 @@ describe UserSummarySerializer do 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 + expect(json[:most_liked_users][0][:count]).to eq(1) + expect(json[:most_liked_users][0][:name]).to eq("John Doe") + expect(json[:most_liked_users][0][:username]).to eq("john_doe") + expect(json[:most_liked_users][0][:avatar_template]).to eq(liked_user.avatar_template) + + # do not include full name if disabled + SiteSetting.enable_names = false + expect(serializer.as_json[:most_liked_users][0][:name]).to eq(nil) end end