Merge pull request #3618 from evazion/fix-rails-5.1-bugs

Fix rails 5.1 bugs
This commit is contained in:
Albert Yi
2018-04-12 09:44:18 -07:00
committed by GitHub
4 changed files with 49 additions and 3 deletions

View File

@@ -3,8 +3,8 @@ class DailyMaintenance
ActiveRecord::Base.connection.execute("set statement_timeout = 0") ActiveRecord::Base.connection.execute("set statement_timeout = 0")
PostPruner.new.prune! PostPruner.new.prune!
TagPruner.new.prune! TagPruner.new.prune!
Upload.delete_all(['created_at < ?', 1.day.ago]) Upload.where('created_at < ?', 1.day.ago).delete_all
Delayed::Job.delete_all(['created_at < ?', 45.days.ago]) Delayed::Job.where('created_at < ?', 45.days.ago).delete_all
PostVote.prune! PostVote.prune!
CommentVote.prune! CommentVote.prune!
ApiCacheGenerator.new.generate_tag_cache ApiCacheGenerator.new.generate_tag_cache

View File

@@ -5,7 +5,7 @@ class UserPasswordResetNonce < ApplicationRecord
after_create :deliver_notice after_create :deliver_notice
def self.prune! def self.prune!
destroy_all(["created_at < ?", 1.week.ago]) where("created_at < ?", 1.week.ago).destroy_all
end end
def deliver_notice def deliver_notice

View File

@@ -0,0 +1,33 @@
require 'test_helper'
class DailyMaintenanceTest < ActiveSupport::TestCase
context "daily maintenance" do
setup do
# have ApiCacheGenerator save files to a temp dir.
@temp_shared_dir_path = "/tmp/#{SecureRandom.uuid}"
Danbooru.config.stubs(:shared_dir_path).returns(@temp_shared_dir_path)
FactoryBot.create(:tag, post_count: 1) # for ApiCacheGenerator
FactoryBot.create(:admin_user) # for SuperVoter.init!
end
teardown do
FileUtils.rm_rf(@temp_shared_dir_path)
Danbooru.config.unstub(:shared_dir_path)
end
should "work" do
assert_nothing_raised { DailyMaintenance.new.run }
end
should "prune expired posts" do
@pending = FactoryBot.create(:post, is_pending: true, created_at: 4.days.ago)
@flagged = FactoryBot.create(:post, is_flagged: true, created_at: 4.days.ago)
DailyMaintenance.new.run
assert(true, @pending.reload.is_deleted)
assert(true, @flagged.reload.is_deleted)
end
end
end

View File

@@ -0,0 +1,13 @@
require 'test_helper'
class WeeklyMaintenanceTest < ActiveSupport::TestCase
context "weekly maintenance" do
should "prune password resets" do
@user = FactoryBot.create(:user, email: "test@example.com")
@nonce = FactoryBot.create(:user_password_reset_nonce, email: "test@example.com", created_at: 1.month.ago)
WeeklyMaintenance.new.run
assert_equal(0, UserPasswordResetNonce.count)
end
end
end