From b6a1d59c285054913834ed3db656e6de9f22cc33 Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Mon, 2 Aug 2021 15:03:11 -0500 Subject: [PATCH] ProfilePreviewCard serializes the user's created at, not the profile (#14392) This matches what happens for the html preview ("Joined" is the user's created_at timestamp), and what the json builder does: json.created_at utc_iso_timestamp(@user.created_at) Update the test cases to assert the profile preview is showing the user's created_at, not the profile's created at. Since these are almost always the same thing, we didn't notice this. However, if a user is created just before the second boundary, and their profile created immediately after the second boundary (so that the iso8601 values have distinct seconds) this could fail when looking at the wrong objects timestamp. To test this locally I modified the user let block to update the timestamp to be a day earlier (this would not have happened in practice but was sufficient to cover the use case). let(:user) { create(:profile).user.tap {|u| u.update(created_at: 1.day.ago) } } --- spec/requests/profile_preview_cards_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/requests/profile_preview_cards_spec.rb b/spec/requests/profile_preview_cards_spec.rb index 95362c837..3958781fc 100644 --- a/spec/requests/profile_preview_cards_spec.rb +++ b/spec/requests/profile_preview_cards_spec.rb @@ -65,7 +65,7 @@ RSpec.describe "ProfilePreviewCards", type: :request do expect(preview_card["work"]).to eq(profile.work) expect(preview_card["location"]).to eq(profile.location) expect(preview_card["education"]).to eq(profile.education) - expect(preview_card["created_at"]).to eq(profile.created_at.utc.iso8601) + expect(preview_card["created_at"]).to eq(user.created_at.utc.iso8601) end it "has the correct card color" do @@ -117,7 +117,7 @@ RSpec.describe "ProfilePreviewCards", type: :request do expect(preview_card["work"]).to eq(profile.work) expect(preview_card["location"]).to eq(profile.location) expect(preview_card["education"]).to eq(profile.education) - expect(preview_card["created_at"]).to eq(profile.created_at.utc.iso8601) + expect(preview_card["created_at"]).to eq(user.created_at.utc.iso8601) end it "has the correct card color" do