FIX: leaving around useless drafts after posting
This commit is contained in:
parent
d459cb95dc
commit
0fd1974838
|
@ -11,6 +11,7 @@ module Jobs
|
|||
Post.calculate_avg_time
|
||||
Topic.calculate_avg_time
|
||||
ScoreCalculator.new.calculate
|
||||
Draft.cleanup!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,6 +34,15 @@ class Draft < ActiveRecord::Base
|
|||
find_by(user_id: user, draft_key: key)
|
||||
end
|
||||
end
|
||||
|
||||
def self.cleanup!
|
||||
exec_sql("DELETE FROM drafts where sequence < (
|
||||
SELECT max(s.sequence) from draft_sequences s
|
||||
WHERE s.draft_key = drafts.draft_key AND
|
||||
s.user_id = drafts.user_id
|
||||
)")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -34,6 +34,24 @@ describe Draft do
|
|||
expect(Draft.get(@user, "test", 1)).to eq "hello"
|
||||
end
|
||||
|
||||
it 'can cleanup old' do
|
||||
user = Fabricate(:user)
|
||||
key = Draft::NEW_TOPIC
|
||||
seq = DraftSequence.next!(user, key)
|
||||
|
||||
Draft.set(user,key,seq,'draft')
|
||||
DraftSequence.update_all('sequence = sequence + 1')
|
||||
|
||||
Draft.cleanup!
|
||||
|
||||
expect(Draft.count).to eq 0
|
||||
Draft.set(Fabricate(:user), Draft::NEW_TOPIC, seq+1, 'draft')
|
||||
|
||||
Draft.cleanup!
|
||||
|
||||
expect(Draft.count).to eq 1
|
||||
end
|
||||
|
||||
|
||||
context 'key expiry' do
|
||||
it 'nukes new topic draft after a topic is created' do
|
||||
|
|
Loading…
Reference in New Issue