From 3c423faafda25b99da697b170f18f3d119000770 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 12 May 2020 11:13:18 +0800 Subject: [PATCH] DEV: Avoid repeating draft key logic in multiple places. --- lib/post_creator.rb | 2 +- spec/components/post_creator_spec.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 6f91e35b5d8..40856682ab8 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -303,7 +303,7 @@ class PostCreator def draft_key @draft_key ||= @opts[:draft_key] - @draft_key ||= @topic ? "topic_#{@topic.id}" : "new_topic" + @draft_key ||= @topic ? @topic.draft_key : Draft::NEW_TOPIC end def build_post_stats diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 0b3999a322a..7882e11c4b7 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -301,9 +301,8 @@ describe PostCreator do end it 'creates post stats' do - - Draft.set(user, 'new_topic', 0, "test") - Draft.set(user, 'new_topic', 0, "test1") + Draft.set(user, Draft::NEW_TOPIC, 0, "test") + Draft.set(user, Draft::NEW_TOPIC, 0, "test1") begin PostCreator.track_post_stats = true