Merge pull request #2739 from evazion/fix-tag-alias

Fix "conflicting wikis" message; fix alias/implication approvers in BURs (#2715)
This commit is contained in:
Albert Yi
2016-10-27 10:44:51 -07:00
committed by GitHub
14 changed files with 119 additions and 84 deletions

View File

@@ -7,7 +7,8 @@ FactoryGirl.define do
after(:create) do |tag_alias|
unless tag_alias.status == "pending"
tag_alias.process!
approver = FactoryGirl.create(:admin_user) unless approver.present?
tag_alias.approve!(approver)
end
end
end

View File

@@ -7,7 +7,8 @@ FactoryGirl.define do
after(:create) do |tag_implication|
unless tag_implication.status == "pending"
tag_implication.process!
approver = FactoryGirl.create(:admin_user) unless approver.present?
tag_implication.approve!(approver)
end
end
end

View File

@@ -62,7 +62,8 @@ class ArtistTest < ActiveSupport::TestCase
setup do
@post = FactoryGirl.create(:post, :tag_string => "aaa")
@artist = FactoryGirl.create(:artist, :name => "aaa")
@artist.ban!
@admin = FactoryGirl.create(:admin_user)
CurrentUser.scoped(@admin) { @artist.ban! }
@post.reload
end
@@ -89,6 +90,11 @@ class ArtistTest < ActiveSupport::TestCase
assert_equal(1, TagImplication.where(:antecedent_name => "aaa", :consequent_name => "banned_artist").count)
assert_equal("aaa banned_artist", @post.tag_string)
end
should "set the approver of the banned_artist implication" do
ta = TagImplication.where(:antecedent_name => "aaa", :consequent_name => "banned_artist").first
assert_equal(@admin.id, ta.approver.id)
end
end
should "create a new wiki page to store any note information" do

View File

@@ -1,10 +1,12 @@
require 'test_helper'
class BulkUpdateRequestTest < ActiveSupport::TestCase
context "creation" do
context "a bulk update request" do
setup do
CurrentUser.user = FactoryGirl.create(:user)
@admin = FactoryGirl.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
Delayed::Worker.delay_jobs = false
end
teardown do
@@ -12,6 +14,35 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
CurrentUser.ip_addr = nil
end
context "on approval" do
setup do
@script = %q(
create alias foo -> bar
create implication bar -> baz
)
@bur = FactoryGirl.create(:bulk_update_request, :script => @script)
@bur.approve!(@admin)
@ta = TagAlias.where(:antecedent_name => "foo", :consequent_name => "bar").first
@ti = TagImplication.where(:antecedent_name => "bar", :consequent_name => "baz").first
end
should "set the BUR approver" do
assert_equal(@admin.id, @bur.approver.id)
end
should "create aliases/implications" do
assert_equal("active", @ta.status)
assert_equal("active", @ti.status)
end
should "set the alias/implication approvers" do
assert_equal(@admin.id, @ta.approver.id)
assert_equal(@admin.id, @ti.approver.id)
end
end
should "create a forum topic" do
assert_difference("ForumTopic.count", 1) do
BulkUpdateRequest.create(:title => "abc", :reason => "zzz", :script => "create alias aaa -> bbb", :skip_secondary_validations => true)
@@ -34,7 +65,6 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
context "with an associated forum topic" do
setup do
@admin = FactoryGirl.create(:admin_user)
@topic = FactoryGirl.create(:forum_topic)
@req = FactoryGirl.create(:bulk_update_request, :script => "create alias AAA -> BBB", :forum_topic => @topic)
end
@@ -42,7 +72,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
should "handle errors gracefully" do
@req.stubs(:update_forum_topic_for_approve).raises(RuntimeError.new("blah"))
assert_difference("Dmail.count", 1) do
@req.approve!(@admin.id)
@req.approve!(@admin)
end
assert_match(/Exception: RuntimeError/, Dmail.last.body)
assert_match(/Message: blah/, Dmail.last.body)
@@ -54,7 +84,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@req.approve!(@admin.id)
@req.approve!(@admin)
end
end

View File

@@ -137,25 +137,30 @@ class TagAliasTest < ActiveSupport::TestCase
setup do
@admin = FactoryGirl.create(:admin_user)
@topic = FactoryGirl.create(:forum_topic)
@alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic)
@alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :status => "pending")
end
context "and conflicting wiki pages" do
setup do
@wiki1 = FactoryGirl.create(:wiki_page, :title => "aaa")
@wiki2 = FactoryGirl.create(:wiki_page, :title => "bbb")
@alias.approve!(@admin)
@admin.reload # reload to get the forum post the approval created.
end
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@alias.rename_wiki_and_artist
end
should "update the forum topic when approved" do
assert(@topic.posts.last, @admin.forum_posts.last)
assert_match(/The tag alias .* been approved/, @admin.forum_posts.last.body)
end
should "warn about conflicting wiki pages when approved" do
assert_match(/has conflicting wiki pages/, @admin.forum_posts.last.body)
end
end
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@alias.process!
@alias.approve!(@admin)
end
end
@@ -164,6 +169,15 @@ class TagAliasTest < ActiveSupport::TestCase
@alias.reject!
end
end
should "update the topic when failed" do
@alias.stubs(:sleep).returns(true)
@alias.stubs(:update_posts).raises(Exception, "oh no")
@alias.approve!(@admin)
assert_match(/error: oh no/, @alias.status)
assert_match(/The tag alias .* failed during processing/, @admin.forum_posts.last.body)
end
end
end
end