tests: add daily & weekly maintenance tests.
This commit is contained in:
33
test/unit/daily_maintenance_test.rb
Normal file
33
test/unit/daily_maintenance_test.rb
Normal 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
|
||||||
13
test/unit/weekly_maintenance_test.rb
Normal file
13
test/unit/weekly_maintenance_test.rb
Normal 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
|
||||||
Reference in New Issue
Block a user