diff --git a/app/models/user_stat.rb b/app/models/user_stat.rb index 63bac29ec34..7d0093eeadc 100644 --- a/app/models/user_stat.rb +++ b/app/models/user_stat.rb @@ -211,7 +211,7 @@ class UserStat < ActiveRecord::Base UPDATE user_stats SET draft_count = (SELECT COUNT(*) FROM drafts WHERE user_id = :user_id) WHERE user_id = :user_id - RETURNING draft_count, (SELECT 1 FROM drafts WHERE draft_key = :new_topic) + RETURNING draft_count, (SELECT 1 FROM drafts WHERE user_id = :user_id AND draft_key = :new_topic) SQL MessageBus.publish( diff --git a/spec/models/draft_spec.rb b/spec/models/draft_spec.rb index 4dd9de5fe7d..538e9c96c58 100644 --- a/spec/models/draft_spec.rb +++ b/spec/models/draft_spec.rb @@ -179,6 +179,8 @@ describe Draft do end it 'updates draft count when a draft is created or destroyed' do + Draft.set(Fabricate(:user), Draft::NEW_TOPIC, 0, "data") + messages = MessageBus.track_publish("/user") do Draft.set(user, Draft::NEW_TOPIC, 0, "data") end