Merge pull request #3522 from techAPJ/patch-2

FIX: move old drafts cleanup to the dedicated method and add test
This commit is contained in:
Sam 2015-06-03 19:12:58 +10:00
commit 11619247b4
4 changed files with 13 additions and 14 deletions

View file

@ -1,12 +0,0 @@
module Jobs
class CleanUpDrafts < Jobs::Scheduled
every 1.week
def execute(args)
delete_drafts_older_than_n_days = SiteSetting.delete_drafts_older_than_n_days.days.ago
# remove old drafts
Draft.where("updated_at < ?", delete_drafts_older_than_n_days).destroy_all
end
end
end

View file

@ -41,6 +41,10 @@ class Draft < ActiveRecord::Base
WHERE s.draft_key = drafts.draft_key AND
s.user_id = drafts.user_id
)")
# remove old drafts
delete_drafts_older_than_n_days = SiteSetting.delete_drafts_older_than_n_days.days.ago
Draft.where("updated_at < ?", delete_drafts_older_than_n_days).destroy_all
end
end

View file

@ -893,7 +893,7 @@ uncategorized:
default: 0
hidden: true
delete_drafts_older_than_n_days: 90
delete_drafts_older_than_n_days: 180
tos_topic_id:
default: -1

View file

@ -34,7 +34,7 @@ describe Draft do
expect(Draft.get(@user, "test", 1)).to eq "hello"
end
it 'can cleanup old' do
it 'can cleanup old drafts' do
user = Fabricate(:user)
key = Draft::NEW_TOPIC
@ -55,6 +55,13 @@ describe Draft do
Draft.cleanup!
expect(Draft.count).to eq 1
# should cleanup drafts more than 180 days old
SiteSetting.stubs(:delete_drafts_older_than_n_days).returns(180)
Draft.last.update_columns(updated_at: 200.days.ago)
Draft.cleanup!
expect(Draft.count).to eq 0
end