From af04318afff29959cb5bb7b564d39932b0ca0557 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 2 Apr 2019 09:36:25 -0400 Subject: [PATCH] FIX: Allow us to serialize reviewables with deleted topics --- app/serializers/reviewable_serializer.rb | 2 +- .../reviewable_flagged_post_serializer_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/serializers/reviewable_serializer.rb b/app/serializers/reviewable_serializer.rb index f6d3f233349..a47ec7978b4 100644 --- a/app/serializers/reviewable_serializer.rb +++ b/app/serializers/reviewable_serializer.rb @@ -93,7 +93,7 @@ class ReviewableSerializer < ApplicationSerializer end def include_topic_url? - object.topic_id.present? + object.topic.present? end def include_topic_id? diff --git a/spec/serializers/reviewable_flagged_post_serializer_spec.rb b/spec/serializers/reviewable_flagged_post_serializer_spec.rb index 2c43bccb3ec..4f8b68fb28c 100644 --- a/spec/serializers/reviewable_flagged_post_serializer_spec.rb +++ b/spec/serializers/reviewable_flagged_post_serializer_spec.rb @@ -13,4 +13,13 @@ describe ReviewableFlaggedPostSerializer do expect(json[:topic_url]).to eq(p0.url) end + it "works when the topic is deleted" do + reviewable = Fabricate(:reviewable_queued_post) + reviewable.topic.update(deleted_at: Time.now) + reviewable.reload + + json = ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json + expect(json[:id]).to be_present + end + end