aliases/implications: remove 'pending' state.

Remove the pending status from tag aliases and implications.

Previously aliases would be created first in the pending state then
changed to active when the alias was later processed in a delayed job.
This meant that BURs weren't processed completely sequentially; first
all the aliases in a BUR would be created in one go, then later they
would be processed and set to active sequentially.

This was problematic in complex BURs that tried to reverse or swap
around aliases, since new pending aliases could be created before old
conflicting aliases were removed.
This commit is contained in:
evazion
2020-12-01 15:30:42 -06:00
parent 45d050d918
commit 8717c319ab
19 changed files with 70 additions and 114 deletions

View File

@@ -107,10 +107,13 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
context "ban action" do
should "ban an artist" do
put_auth ban_artist_path(@artist.id), @admin
perform_enqueued_jobs do
put_auth ban_artist_path(@artist.id), @admin
end
assert_redirected_to(@artist)
assert_equal(true, @artist.reload.is_banned?)
assert_equal(true, TagImplication.exists?(antecedent_name: @artist.name, consequent_name: "banned_artist"))
assert_equal(true, TagImplication.exists?(antecedent_name: @artist.name, consequent_name: "banned_artist", status: "active"))
end
should "not allow non-admins to ban artists" do

View File

@@ -156,12 +156,14 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
create(:tag, name: "artist2a", category: Tag.categories.artist, post_count: 20)
@bulk_update_request = create(:bulk_update_request, script: "mass update artist1a -> artist1b\ncreate alias artist2a -> artist2b")
post_auth approve_bulk_update_request_path(@bulk_update_request), @builder
perform_enqueued_jobs do
post_auth approve_bulk_update_request_path(@bulk_update_request), @builder
end
assert_redirected_to(bulk_update_requests_path)
assert_equal("approved", @bulk_update_request.reload.status)
assert_equal(@builder, @bulk_update_request.approver)
assert_equal(true, TagAlias.where(antecedent_name: "artist2a", consequent_name: "artist2b").exists?)
assert_equal(true, TagAlias.exists?(antecedent_name: "artist2a", consequent_name: "artist2b", status: "active"))
end
end

View File

@@ -161,6 +161,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
end
should "show a notice for a single tag search with a pending BUR" do
create(:tag, name: "foo")
create(:bulk_update_request, script: "create alias foo -> bar")
get_auth posts_path(tags: "foo"), @user
assert_select ".tag-change-notice"

View File

@@ -18,7 +18,7 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest
@antecedent_wiki = create(:wiki_page, title: "touhou", body: "zun project")
@consequent_wiki = create(:wiki_page, title: "touhou_project")
@other_alias = create(:tag_alias, antecedent_name: "touhou", consequent_name: "touhou_project", creator: @user, status: "pending", forum_topic: @forum_topic, forum_post: @forum_post)
@other_alias = create(:tag_alias, antecedent_name: "touhou", consequent_name: "touhou_project", creator: @user, status: "deleted", forum_topic: @forum_topic, forum_post: @forum_post)
@unrelated_alias = create(:tag_alias)
end
@@ -30,7 +30,7 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest
should respond_to_search({}).with { [@unrelated_alias, @other_alias, @tag_alias] }
should respond_to_search(antecedent_name: "aaa").with { @tag_alias }
should respond_to_search(consequent_name: "bbb").with { @tag_alias }
should respond_to_search(status: "pending").with { @other_alias }
should respond_to_search(status: "deleted").with { @other_alias }
context "using includes" do
should respond_to_search(antecedent_tag: {post_count: 1000}).with { @other_alias }

View File

@@ -18,7 +18,7 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest
@antecedent_wiki = create(:wiki_page, title: "cannon", body: "made of fun")
@consequent_wiki = create(:wiki_page, title: "weapon")
@other_implication = create(:tag_implication, antecedent_name: "cannon", consequent_name: "weapon", creator: @user, status: "pending", forum_topic: @forum_topic, forum_post: @forum_post)
@other_implication = create(:tag_implication, antecedent_name: "cannon", consequent_name: "weapon", creator: @user, status: "deleted", forum_topic: @forum_topic, forum_post: @forum_post)
@unrelated_implication = create(:tag_implication)
end
@@ -30,7 +30,7 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest
should respond_to_search({}).with { [@unrelated_implication, @other_implication, @tag_implication] }
should respond_to_search(antecedent_name: "aaa").with { @tag_implication }
should respond_to_search(consequent_name: "bbb").with { @tag_implication }
should respond_to_search(status: "pending").with { @other_implication }
should respond_to_search(status: "deleted").with { @other_implication }
context "using includes" do
should respond_to_search(antecedent_tag: {post_count: 10}).with { @other_implication }