tests: replace workoff_active_jobs with perform_enqueued_jobs.

This commit is contained in:
evazion
2019-09-07 22:18:33 -05:00
parent 6b8515811f
commit 258fa06422
6 changed files with 16 additions and 25 deletions

View File

@@ -841,7 +841,7 @@ class UploadServiceTest < ActiveSupport::TestCase
as_user { @post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350") }
travel_to((PostReplacement::DELETION_GRACE_PERIOD + 1).days.from_now) do
workoff_active_jobs
perform_enqueued_jobs
end
rescue Net::OpenTimeout
skip "Remote connection to Pixiv failed"
@@ -892,7 +892,7 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_nothing_raised { @post.file(:preview) }
travel_to((PostReplacement::DELETION_GRACE_PERIOD + 1).days.from_now) do
workoff_active_jobs
perform_enqueued_jobs
end
assert_nothing_raised { @post.file(:original) }
@@ -937,7 +937,7 @@ class UploadServiceTest < ActiveSupport::TestCase
travel_to (PostReplacement::DELETION_GRACE_PERIOD + 1).days.from_now do
assert_raise(Post::DeletionError) do
workoff_active_jobs
perform_enqueued_jobs
end
end
@@ -1287,7 +1287,7 @@ class UploadServiceTest < ActiveSupport::TestCase
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
travel (PostReplacement::DELETION_GRACE_PERIOD + 1).days
workoff_active_jobs
perform_enqueued_jobs
refute(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
end

View File

@@ -51,15 +51,6 @@ module TestHelpers
Thread.current[:pixiv_comic_session_cache_key] = Cache.get(PixivWebAgent::COMIC_SESSION_CACHE_KEY)
end
end
# XXX replace with `perform_enqueued_jobs` after rails 6 upgrade.
def workoff_active_jobs
queue_adapter.enqueued_jobs.each do |job_data|
args = ActiveJob::Arguments.deserialize(job_data[:args])
job = job_data[:job].new(*args)
job.perform_now
end
end
end
class ActiveSupport::TestCase

View File

@@ -93,7 +93,7 @@ class ArtistTest < ActiveSupport::TestCase
end
should "create a new tag implication" do
workoff_active_jobs
perform_enqueued_jobs
assert_equal(1, TagImplication.where(:antecedent_name => "aaa", :consequent_name => "banned_artist").count)
assert_equal("aaa banned_artist", @post.reload.tag_string)
end

View File

@@ -74,7 +74,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
@bur.approve!(@admin)
assert_enqueued_jobs(3)
workoff_active_jobs
perform_enqueued_jobs
@ta = TagAlias.where(:antecedent_name => "foo", :consequent_name => "bar").first
@ti = TagImplication.where(:antecedent_name => "bar", :consequent_name => "baz").first

View File

@@ -127,7 +127,7 @@ class TagAliasTest < ActiveSupport::TestCase
ta = FactoryBot.create(:tag_alias, :antecedent_name => "...", :consequent_name => "bbb")
ta.approve!(approver: @admin)
workoff_active_jobs
perform_enqueued_jobs
assert_equal(%w(123 456 bbb), ss.reload.query.split.sort)
end
@@ -139,7 +139,7 @@ class TagAliasTest < ActiveSupport::TestCase
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "ccc")
ta.approve!(approver: @admin)
workoff_active_jobs
perform_enqueued_jobs
assert_equal("bbb ccc", post1.reload.tag_string)
assert_equal("ccc ddd", post2.reload.tag_string)
@@ -162,7 +162,7 @@ class TagAliasTest < ActiveSupport::TestCase
# XXX this is broken, it depends on the order the jobs are executed in.
ta2.approve!(approver: @admin)
ta1.approve!(approver: @admin)
workoff_active_jobs
perform_enqueued_jobs
assert_equal("ccc", ta1.reload.consequent_name)
end
@@ -171,7 +171,7 @@ class TagAliasTest < ActiveSupport::TestCase
ti = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ta = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
ta.approve!(approver: @admin)
workoff_active_jobs
perform_enqueued_jobs
assert_equal("ccc", ti.reload.consequent_name)
end
@@ -190,7 +190,7 @@ class TagAliasTest < ActiveSupport::TestCase
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
ta.approve!(approver: @admin)
workoff_active_jobs
perform_enqueued_jobs
assert_equal(1, tag2.reload.category)
end
@@ -211,7 +211,7 @@ class TagAliasTest < ActiveSupport::TestCase
@wiki1 = FactoryBot.create(:wiki_page, :title => "aaa")
@wiki2 = FactoryBot.create(:wiki_page, :title => "bbb")
@alias.approve!(approver: @admin)
workoff_active_jobs
perform_enqueued_jobs
end
end
@@ -228,14 +228,14 @@ class TagAliasTest < ActiveSupport::TestCase
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@alias.approve!(approver: @admin)
workoff_active_jobs
perform_enqueued_jobs
end
end
should "update the parent post" do
previous = @post.body
@alias.approve!(approver: @admin)
workoff_active_jobs
perform_enqueued_jobs
assert_not_equal(previous, @post.reload.body)
end

View File

@@ -246,7 +246,7 @@ class TagImplicationTest < ActiveSupport::TestCase
ti1.approve!
ti2.approve!
workoff_active_jobs
perform_enqueued_jobs
assert_equal("aaa bbb ccc xxx yyy", p1.reload.tag_string)
end
@@ -262,7 +262,7 @@ class TagImplicationTest < ActiveSupport::TestCase
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@implication.approve!
workoff_active_jobs
perform_enqueued_jobs
end
assert_match(/The tag implication .* has been approved/, @post.reload.body)