mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 11:20:57 -06:00
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:
commit
11619247b4
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user