diff --git a/Gemfile.lock b/Gemfile.lock index 033d6a9d..f4deaba3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - exception_notification (2.4.1) + exception_notification (2.5.2) actionmailer (>= 3.0.4) GEM diff --git a/lib/exception_notifier/notifier.rb b/lib/exception_notifier/notifier.rb index 90dffab9..c55778c3 100644 --- a/lib/exception_notifier/notifier.rb +++ b/lib/exception_notifier/notifier.rb @@ -70,12 +70,13 @@ def exception_notification(env, exception) end end - def background_exception_notification(exception) + def background_exception_notification(exception, additional = {}) if @notifier = Rails.application.config.middleware.detect{ |x| x.klass == ExceptionNotifier } @options = (@notifier.args.first || {}).reverse_merge(self.class.default_options) @exception = exception @backtrace = exception.backtrace || [] - @sections = %w{backtrace} + @additional_context = additional + @sections = %w(additional_context backtrace) subject = compose_subject(exception) mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format| diff --git a/lib/exception_notifier/views/exception_notifier/_additional_context.text.erb b/lib/exception_notifier/views/exception_notifier/_additional_context.text.erb new file mode 100644 index 00000000..b45b69ee --- /dev/null +++ b/lib/exception_notifier/views/exception_notifier/_additional_context.text.erb @@ -0,0 +1,4 @@ +<% max = @additional_context.keys.max { |a, b| a.length <=> b.length } -%> +<% @additional_context.keys.sort.each do |key| -%> +* <%= raw("%-*s: %s" % [max.length, key, inspect_object(@additional_context[key])]) %> +<% end -%> \ No newline at end of file diff --git a/test/background_exception_notification_test.rb b/test/background_exception_notification_test.rb index f701f22f..d72bd2d2 100644 --- a/test/background_exception_notification_test.rb +++ b/test/background_exception_notification_test.rb @@ -3,10 +3,11 @@ class BackgroundExceptionNotificationTest < ActiveSupport::TestCase setup do begin + @troublesome_object = "I like to cause problems." 1/0 rescue => e @exception = e - @mail = ExceptionNotifier::Notifier.background_exception_notification(@exception) + @mail = ExceptionNotifier::Notifier.background_exception_notification(@exception, :the_trouble_object => @troublesome_object) end end @@ -34,8 +35,12 @@ class BackgroundExceptionNotificationTest < ActiveSupport::TestCase assert @mail.body.include? "A ZeroDivisionError occurred in background" end + test "mail should contain additional context" do + assert @mail.body.include? "I like to cause problems." + end + test "mail should contain backtrace in body" do - assert @mail.body.include? "test/background_exception_notification_test.rb:6" + assert @mail.body.include? "test/background_exception_notification_test.rb:" end test "mail should not contain any attachments" do