tests: fix alias/implication tests.

This commit is contained in:
evazion
2019-08-17 02:41:07 -05:00
parent 868a2256d1
commit 145894fe8b
5 changed files with 33 additions and 23 deletions

View File

@@ -57,8 +57,9 @@ module TestHelpers
# XXX replace with `perform_enqueued_jobs` after rails 6 upgrade.
def workoff_active_jobs
queue_adapter.enqueued_jobs.each do |job_data|
klass = job_data[:job]
klass.perform_now(*job_data[:args])
args = ActiveJob::Arguments.deserialize(job_data[:args])
job = job_data[:job].new(*args)
job.perform_now
end
end
end

View File

@@ -108,8 +108,9 @@ class ArtistTest < ActiveSupport::TestCase
end
should "create a new tag implication" do
workoff_active_jobs
assert_equal(1, TagImplication.where(:antecedent_name => "aaa", :consequent_name => "banned_artist").count)
assert_equal("aaa banned_artist", @post.tag_string)
assert_equal("aaa banned_artist", @post.reload.tag_string)
end
should "set the approver of the banned_artist implication" do

View File

@@ -72,6 +72,9 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
@bur = FactoryBot.create(:bulk_update_request, :script => @script)
@bur.approve!(@admin)
assert_enqueued_jobs(2)
workoff_active_jobs
@ta = TagAlias.where(:antecedent_name => "foo", :consequent_name => "bar").first
@ti = TagImplication.where(:antecedent_name => "bar", :consequent_name => "baz").first
end

View File

@@ -127,7 +127,9 @@ class TagAliasTest < ActiveSupport::TestCase
tag2 = FactoryBot.create(:tag, :name => "bbb")
ss = FactoryBot.create(:saved_search, :query => "123 ... 456", :user => CurrentUser.user)
ta = FactoryBot.create(:tag_alias, :antecedent_name => "...", :consequent_name => "bbb")
ta.approve!(approver: @admin)
workoff_active_jobs
assert_equal(%w(123 456 bbb), ss.reload.query.split.sort)
end
@@ -139,6 +141,7 @@ class TagAliasTest < ActiveSupport::TestCase
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "ccc")
ta.approve!(approver: @admin)
workoff_active_jobs
assert_equal("bbb ccc", post1.reload.tag_string)
assert_equal("ccc ddd", post2.reload.tag_string)
@@ -157,8 +160,11 @@ class TagAliasTest < ActiveSupport::TestCase
should "move existing aliases" do
ta1 = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :status => "pending")
ta2 = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc", :status => "pending")
ta1.approve!(approver: @admin)
# 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
assert_equal("ccc", ta1.reload.consequent_name)
end
@@ -167,9 +173,9 @@ 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
ti.reload
assert_equal("ccc", ti.consequent_name)
assert_equal("ccc", ti.reload.consequent_name)
end
should "not push the antecedent's category to the consequent if the antecedent is general" do
@@ -184,7 +190,9 @@ class TagAliasTest < ActiveSupport::TestCase
tag1 = FactoryBot.create(:tag, :name => "aaa", :category => 1)
tag2 = FactoryBot.create(:tag, :name => "bbb", :category => 0)
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
ta.approve!(approver: @admin)
workoff_active_jobs
assert_equal(1, tag2.reload.category)
end
@@ -205,32 +213,32 @@ 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
end
@admin.reload # reload to get the forum post the approval created.
@topic.reload
end
should "update the forum topic when approved" do
assert_equal("[APPROVED] Tag alias: aaa -> bbb", @topic.title)
assert_match(/The tag alias .* been approved/m, @topic.posts[-2].body)
assert_equal("[APPROVED] Tag alias: aaa -> bbb", @topic.reload.title)
assert_match(/The tag alias .* been approved/m, @topic.posts.second.body)
end
should "warn about conflicting wiki pages when approved" do
assert_match(/has conflicting wiki pages/m, @topic.posts[-1].body)
assert_match(/has conflicting wiki pages/m, @topic.posts.third.body)
end
end
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@alias.approve!(approver: @admin)
workoff_active_jobs
end
end
should "update the parent post" do
previous = @post.body
@alias.approve!(approver: @admin)
@post.reload
assert_not_equal(previous, @post.body)
workoff_active_jobs
assert_not_equal(previous, @post.reload.body)
end
should "update the topic when rejected" do
@@ -242,10 +250,9 @@ class TagAliasTest < ActiveSupport::TestCase
should "update the topic when failed" do
@alias.stubs(:sleep).returns(true)
@alias.stubs(:update_posts).raises(Exception, "oh no")
@alias.approve!(approver: @admin)
@topic.reload
@alias.process!
assert_equal("[FAILED] Tag alias: aaa -> bbb", @topic.title)
assert_equal("[FAILED] Tag alias: aaa -> bbb", @topic.reload.title)
assert_match(/error: oh no/, @alias.status)
assert_match(/The tag alias .* failed during processing/, @topic.posts.last.body)
end

View File

@@ -246,10 +246,9 @@ class TagImplicationTest < ActiveSupport::TestCase
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
ti2 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "yyy")
perform_enqueued_jobs do
ti1.approve!
ti2.approve!
end
ti1.approve!
ti2.approve!
workoff_active_jobs
assert_equal("aaa bbb ccc xxx yyy", p1.reload.tag_string)
end
@@ -264,9 +263,8 @@ class TagImplicationTest < ActiveSupport::TestCase
should "update the topic when processed" do
assert_difference("ForumPost.count") do
perform_enqueued_jobs do
@implication.approve!
end
@implication.approve!
workoff_active_jobs
end
assert_match(/The tag implication .* has been approved/, @post.reload.body)