From d459cb95dc817f706c5ad514bca4fa007f707976 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Tue, 2 Jun 2015 13:32:25 +1000 Subject: [PATCH] FIX: when advancing draft sequence remove old drafts --- app/models/draft_sequence.rb | 1 + spec/models/draft_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/models/draft_sequence.rb b/app/models/draft_sequence.rb index 3040b955b..7d15c6b9a 100644 --- a/app/models/draft_sequence.rb +++ b/app/models/draft_sequence.rb @@ -11,6 +11,7 @@ class DraftSequence < ActiveRecord::Base c.sequence ||= 0 c.sequence += 1 c.save + exec_sql("DELETE FROM drafts WHERE user_id = :user_id AND draft_key = :draft_key AND sequence < :sequence", draft_key: key, user_id: user_id, sequence: c.sequence) c.sequence end diff --git a/spec/models/draft_spec.rb b/spec/models/draft_spec.rb index 8b7f6b6ee..0f5f555c2 100644 --- a/spec/models/draft_spec.rb +++ b/spec/models/draft_spec.rb @@ -42,6 +42,7 @@ describe Draft do _t = Fabricate(:topic, user: u) s = DraftSequence.current(u, Draft::NEW_TOPIC) expect(Draft.get(u, Draft::NEW_TOPIC, s)).to eq nil + expect(Draft.count).to eq 0 end it 'nukes new pm draft after a pm is created' do