From 101fbf714839c3877783a8e1f770cd5e695f2b2e Mon Sep 17 00:00:00 2001 From: Alex Mishyn Date: Mon, 3 Oct 2011 16:34:13 +0300 Subject: [PATCH] fix setting verbose_subject from options --- lib/exception_notifier.rb | 1 + lib/exception_notifier/notifier.rb | 8 ++++++-- .../test/functional/posts_controller_test.rb | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/exception_notifier.rb b/lib/exception_notifier.rb index f50182d0..458b4358 100644 --- a/lib/exception_notifier.rb +++ b/lib/exception_notifier.rb @@ -17,6 +17,7 @@ def initialize(app, options = {}) Notifier.default_exception_recipients = @options[:exception_recipients] Notifier.default_email_prefix = @options[:email_prefix] Notifier.default_sections = @options[:sections] + Notifier.default_verbose_subject = @options[:verbose_subject] @options[:ignore_exceptions] ||= self.class.default_ignore_exceptions end diff --git a/lib/exception_notifier/notifier.rb b/lib/exception_notifier/notifier.rb index 651d9aff..8766a1bc 100644 --- a/lib/exception_notifier/notifier.rb +++ b/lib/exception_notifier/notifier.rb @@ -14,6 +14,7 @@ class << self attr_writer :default_exception_recipients attr_writer :default_email_prefix attr_writer :default_sections + attr_writer :default_verbose_subject def default_sender_address @default_sender_address || %("Exception Notifier" ) @@ -30,13 +31,17 @@ def default_email_prefix def default_sections @default_sections || %w(request session environment backtrace) end + + def default_verbose_subject + @default_verbose_subject.nil? || @default_verbose_subject + end def default_options { :sender_address => default_sender_address, :exception_recipients => default_exception_recipients, :email_prefix => default_email_prefix, :sections => default_sections, - :verbose_subject => true } + :verbose_subject => default_verbose_subject } end end @@ -58,7 +63,6 @@ def exception_notification(env, exception) data.each do |name, value| instance_variable_set("@#{name}", value) end - subject = compose_subject(exception, @kontroller) mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format| diff --git a/test/dummy/test/functional/posts_controller_test.rb b/test/dummy/test/functional/posts_controller_test.rb index d65f6dff..98f424b1 100644 --- a/test/dummy/test/functional/posts_controller_test.rb +++ b/test/dummy/test/functional/posts_controller_test.rb @@ -83,4 +83,23 @@ class PostsControllerTest < ActionController::TestCase end assert_equal "[Dummy ERROR] # (NoMethodError)", @mail.subject end + end + +class PostsControllerTestWithoutVerboseSubject < ActionController::TestCase + tests PostsController + setup do + ExceptionNotifier::Notifier.default_verbose_subject = false + begin + @post = posts(:one) + post :create, :post => @post.attributes + rescue => e + @exception = e + @mail = ExceptionNotifier::Notifier.exception_notification(request.env, @exception) + end + end + + test "should not include exception message in subject" do + assert_equal "[Dummy ERROR] # (NoMethodError)", @mail.subject + end +end \ No newline at end of file