refactor forum notifications for tag changes

This commit is contained in:
r888888888
2017-03-31 17:42:14 -07:00
parent 441022960a
commit 19b8d41d09
17 changed files with 422 additions and 317 deletions

View File

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

View File

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

View File

@@ -64,17 +64,21 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
context "with an associated forum topic" do
setup do
@topic = FactoryGirl.create(:forum_topic)
@req = FactoryGirl.create(:bulk_update_request, :script => "create alias AAA -> BBB", :forum_topic => @topic)
@topic = FactoryGirl.create(:forum_topic, :title => "[bulk] hoge")
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
@req = FactoryGirl.create(:bulk_update_request, :script => "create alias AAA -> BBB", :forum_topic_id => @topic.id, :forum_post_id => @post.id, :title => "[bulk] hoge")
end
should "handle errors gracefully" do
@req.stubs(:update_forum_topic_for_approve).raises(RuntimeError.new("blah"))
assert_difference("Dmail.count", 1) do
@req.stubs(:update).raises(RuntimeError.new("blah"))
assert_difference("ForumPost.count", 1) do
@req.approve!(@admin)
end
assert_match(/Exception: RuntimeError/, Dmail.last.body)
assert_match(/Message: blah/, Dmail.last.body)
@topic.reload
@post.reload
assert_match(/\[FAILED\]/, @topic.title)
assert_match(/UPDATE/, @post.body)
end
should "downcase the text" do
@@ -85,6 +89,11 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
assert_difference("ForumPost.count") do
@req.approve!(@admin)
end
@topic.reload
@post.reload
assert_match(/\[APPROVED\]/, @topic.title)
assert_match(/UPDATE/, @post.body)
end
should "update the topic when rejected" do
@@ -93,6 +102,11 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
assert_difference("ForumPost.count") do
@req.reject!
end
@topic.reload
@post.reload
assert_match(/\[REJECTED\]/, @topic.title)
assert_match(/UPDATE/, @post.body)
end
end
end

View File

@@ -74,7 +74,7 @@ class TagAliasTest < ActiveSupport::TestCase
assert_nil(Cache.get("ta:aaa"))
end
should "zzz move saved searches" do
should "move saved searches" do
tag1 = FactoryGirl.create(:tag, :name => "...")
tag2 = FactoryGirl.create(:tag, :name => "bbb")
ss = FactoryGirl.create(:saved_search, :query => "123 ... 456", :user => CurrentUser.user)
@@ -139,7 +139,8 @@ class TagAliasTest < ActiveSupport::TestCase
context "with an associated forum topic" do
setup do
@admin = FactoryGirl.create(:admin_user)
@topic = FactoryGirl.create(:forum_topic)
@topic = FactoryGirl.create(:forum_topic, :title => TagAliasRequest.topic_title("aaa", "bbb"))
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => TagAliasRequest.command_string("aaa", "bbb"))
@alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :status => "pending")
end
@@ -147,26 +148,34 @@ class TagAliasTest < ActiveSupport::TestCase
setup do
@wiki1 = FactoryGirl.create(:wiki_page, :title => "aaa")
@wiki2 = FactoryGirl.create(:wiki_page, :title => "bbb")
@alias.approve!(@admin)
@alias.approve!(approver: @admin)
@admin.reload # reload to get the forum post the approval created.
@topic.reload
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)
assert_equal("[APPROVED] Tag alias: aaa -> bbb", @topic.title)
assert_match(/The tag alias .* been approved/m, @admin.forum_posts[-2].body)
end
should "warn about conflicting wiki pages when approved" do
assert_match(/has conflicting wiki pages/, @admin.forum_posts.last.body)
assert_match(/has conflicting wiki pages/m, @admin.forum_posts[-1].body)
end
end
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@alias.approve!(@admin)
@alias.approve!(approver: @admin)
end
end
should "update the parent post" do
previous = @post.body
@alias.approve!(approver: @admin)
@post.reload
assert_not_equal(previous, @post.body)
end
should "update the topic when rejected" do
assert_difference("ForumPost.count") do
@alias.reject!
@@ -176,8 +185,10 @@ 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!(@admin)
@alias.approve!(approver: @admin)
@topic.reload
assert_equal("[FAILED] Tag alias: aaa -> bbb", @topic.title)
assert_match(/error: oh no/, @alias.status)
assert_match(/The tag alias .* failed during processing/, @admin.forum_posts.last.body)
end

View File

@@ -186,20 +186,29 @@ class TagImplicationTest < ActiveSupport::TestCase
context "with an associated forum topic" do
setup do
@admin = FactoryGirl.create(:admin_user)
@topic = FactoryGirl.create(:forum_topic)
@implication = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic)
@topic = FactoryGirl.create(:forum_topic, :title => TagImplicationRequest.topic_title("aaa", "bbb"))
@post = FactoryGirl.create(:forum_post, topic_id: @topic.id, :body => TagImplicationRequest.command_string("aaa", "bbb"))
@implication = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :status => "pending")
end
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@implication.process!
@implication.approve!
end
@post.reload
@topic.reload
assert_match(/The tag implication .* has been approved/, @post.body)
assert_equal("[APPROVED] Tag implication: aaa -> bbb", @topic.title)
end
should "update the topic when rejected" do
assert_difference("ForumPost.count") do
@implication.reject!
end
@post.reload
@topic.reload
assert_match(/The tag implication .* has been rejected/, @post.body)
assert_equal("[REJECTED] Tag implication: aaa -> bbb", @topic.title)
end
end
end