dmail bulk update request errors to admin
This commit is contained in:
@@ -6,28 +6,28 @@ module BulkUpdateRequestsHelper
|
||||
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
||||
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
||||
|
||||
"create_alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})"
|
||||
"create alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})"
|
||||
|
||||
when :create_implication
|
||||
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
||||
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
||||
|
||||
"create_implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})"
|
||||
"create implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})"
|
||||
|
||||
when :remove_alias
|
||||
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
||||
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
||||
|
||||
"remove_alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})"
|
||||
"remove alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})"
|
||||
|
||||
when :remove_implication
|
||||
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
||||
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
||||
|
||||
"remove_implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})"
|
||||
"remove implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})"
|
||||
|
||||
when :mass_update
|
||||
"mass_update " + link_to(arg1, posts_path(:tags => arg1)) + " -> " + link_to(arg2, posts_path(:tags => arg2))
|
||||
"mass update " + link_to(arg1, posts_path(:tags => arg1)) + " -> " + link_to(arg2, posts_path(:tags => arg2))
|
||||
|
||||
end
|
||||
end.join("\n")
|
||||
|
||||
@@ -32,7 +32,7 @@ class AliasAndImplicationImporter
|
||||
[:remove_implication, $1, $2]
|
||||
elsif line =~ /^mass update (.+?) -> (.*)$/i
|
||||
[:mass_update, $1, $2]
|
||||
elsif line.empty?
|
||||
elsif line.strip.empty?
|
||||
# do nothing
|
||||
else
|
||||
raise "Unparseable line: #{line}"
|
||||
|
||||
@@ -35,6 +35,29 @@ class BulkUpdateRequest < ActiveRecord::Base
|
||||
AliasAndImplicationImporter.new(script, forum_topic_id, "1").process!
|
||||
update_forum_topic_for_approve
|
||||
update_attribute(:status, "approved")
|
||||
|
||||
rescue Exception => x
|
||||
admin = User.admins.first
|
||||
msg = <<-EOS
|
||||
Bulk Update Request ##{id} failed\n
|
||||
Exception: #{x.class}\n
|
||||
Message: #{x.to_s}\n
|
||||
Stack trace:\n
|
||||
EOS
|
||||
|
||||
x.backtrace.each do |line|
|
||||
msg += "#{line}\n"
|
||||
end
|
||||
|
||||
dmail = Dmail.new(
|
||||
:from_id => admin.id,
|
||||
:to_id => admin.id,
|
||||
:owner_id => admin.id,
|
||||
:title => "Bulk update request approval failed",
|
||||
:body => msg
|
||||
)
|
||||
dmail.owner_id = admin.id
|
||||
dmail.save
|
||||
end
|
||||
|
||||
def editable?(user)
|
||||
|
||||
@@ -23,6 +23,17 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
@req = FactoryGirl.create(:bulk_update_request, :script => "create alias AAA -> BBB", :forum_topic => @topic)
|
||||
end
|
||||
|
||||
should "handle errors gracefully" do
|
||||
@req.stubs(:update_forum_topic_for_approve).raises(RuntimeError.new("blah"))
|
||||
assert_difference("Dmail.count", 1) do
|
||||
CurrentUser.scoped(@admin, "127.0.0.1") do
|
||||
@req.approve!
|
||||
end
|
||||
end
|
||||
assert_match(/Exception: RuntimeError/, Dmail.last.body)
|
||||
assert_match(/Message: blah/, Dmail.last.body)
|
||||
end
|
||||
|
||||
should "downcase the text" do
|
||||
assert_equal("create alias aaa -> bbb", @req.script)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user