Skip to content

Commit

Permalink
Merge pull request smartinez87#27 from amishyn/master
Browse files Browse the repository at this point in the history
set verbose subject from options fix
  • Loading branch information
smartinez87 committed Oct 3, 2011
2 parents 7d0815e + 101fbf7 commit 986f427
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/exception_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/exception_notifier/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" <[email protected]>)
Expand All @@ -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

Expand All @@ -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|
Expand Down
19 changes: 19 additions & 0 deletions test/dummy/test/functional/posts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 986f427

Please sign in to comment.