exception_notification 2.6.1 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/CHANGELOG.rdoc +12 -0
  2. data/CONTRIBUTING.md +33 -0
  3. data/Gemfile.lock +61 -33
  4. data/README.md +59 -12
  5. data/exception_notification.gemspec +5 -3
  6. data/lib/exception_notifier.rb +7 -0
  7. data/lib/exception_notifier/campfire_notifier.rb +30 -0
  8. data/lib/exception_notifier/notifier.rb +55 -26
  9. data/lib/exception_notifier/views/exception_notifier/_backtrace.html.erb +1 -0
  10. data/lib/exception_notifier/views/exception_notifier/_data.html.erb +1 -0
  11. data/lib/exception_notifier/views/exception_notifier/_environment.html.erb +8 -0
  12. data/lib/exception_notifier/views/exception_notifier/_request.html.erb +5 -0
  13. data/lib/exception_notifier/views/exception_notifier/_session.html.erb +2 -0
  14. data/lib/exception_notifier/views/exception_notifier/_title.html.erb +3 -0
  15. data/lib/exception_notifier/views/exception_notifier/background_exception_notification.html.erb +26 -0
  16. data/lib/exception_notifier/views/exception_notifier/background_exception_notification.text.erb +5 -3
  17. data/lib/exception_notifier/views/exception_notifier/exception_notification.html.erb +36 -0
  18. data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +4 -3
  19. data/test/background_exception_notification_test.rb +21 -6
  20. data/test/campfire_test.rb +52 -0
  21. data/test/dummy/Gemfile +1 -1
  22. data/test/dummy/Gemfile.lock +93 -58
  23. data/test/dummy/app/controllers/posts_controller.rb +1 -0
  24. data/test/dummy/app/views/exception_notifier/_new_bkg_section.html.erb +1 -0
  25. data/test/dummy/app/views/exception_notifier/_new_section.html.erb +1 -0
  26. data/test/dummy/app/views/exception_notifier/_new_section.text.erb +1 -1
  27. data/test/dummy/test/functional/posts_controller_test.rb +62 -10
  28. data/test/exception_notification_test.rb +27 -2
  29. data/test/test_helper.rb +3 -0
  30. metadata +55 -7
@@ -0,0 +1 @@
1
+ <%= raw @backtrace.join("\n") %>
@@ -0,0 +1 @@
1
+ * data: <%= raw PP.pp(@data, "") %>
@@ -0,0 +1,8 @@
1
+ <% filtered_env = @request.filtered_env -%>
2
+ <% max = filtered_env.keys.map(&:to_s).max { |a, b| a.length <=> b.length } -%>
3
+ <% filtered_env.keys.map(&:to_s).sort.each do |key| -%>
4
+ * <%= raw("%-*s: %s" % [max.length, key, inspect_object(filtered_env[key])]) %>
5
+ <% end -%>
6
+
7
+ * Process: <%= raw $$ %>
8
+ * Server : <%= raw `hostname`.chomp %>
@@ -0,0 +1,5 @@
1
+ * URL : <%= raw @request.url %>
2
+ * IP address: <%= raw @request.remote_ip %>
3
+ * Parameters: <%= raw @request.filtered_parameters.inspect %>
4
+ * Rails root: <%= raw Rails.root %>
5
+ * Timestamp : <%= raw Time.current %>
@@ -0,0 +1,2 @@
1
+ * session id: <%= @request.ssl? ? "[FILTERED]" : (raw (@request.session['session_id'] || @request.env["rack.session.options"][:id]).inspect.html_safe) %>
2
+ * data: <%= raw PP.pp(@request.session, "") %>
@@ -0,0 +1,3 @@
1
+ -------------------------------
2
+ <%= raw title.to_s.humanize %>:
3
+ -------------------------------
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE HTML>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Exception</title>
6
+ </head>
7
+ <body>
8
+ <pre style="font-size: 12px">
9
+ <%= @exception.class.to_s =~ /^[aeiou]/i ? 'An' : 'A' %> <%= @exception.class %> occurred in background at <%= raw Time.current %> :
10
+
11
+ <%= @exception.message %>
12
+ <%= @backtrace.first %>
13
+ <%
14
+ sections = @sections.map do |section|
15
+ summary = render(section).strip
16
+ unless summary.blank?
17
+ title = render("title", :title => section).strip
18
+ "#{title}\n\n#{summary.gsub(/^/, " ")}\n\n"
19
+ end
20
+ end.join
21
+ sections = sections.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace).encode('UTF-8') if sections.respond_to?(:force_encoding)
22
+ %>
23
+ <%= raw sections %>
24
+ </pre>
25
+ </body>
26
+ </html>
@@ -1,4 +1,4 @@
1
- A <%= @exception.class %> occurred in background at <%= raw Time.current %> :
1
+ <%= @exception.class.to_s =~ /^[aeiou]/i ? 'An' : 'A' %> <%= @exception.class %> occurred in background at <%= raw Time.current %> :
2
2
 
3
3
  <%= @exception.message %>
4
4
  <%= @backtrace.first %>
@@ -9,5 +9,7 @@ A <%= @exception.class %> occurred in background at <%= raw Time.current %> :
9
9
  title = render("title", :title => section).strip
10
10
  "#{title}\n\n#{summary.gsub(/^/, " ")}\n\n"
11
11
  end
12
- end %>
13
- <%= raw sections.join %>
12
+ end.join
13
+ sections = sections.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace).encode('UTF-8') if sections.respond_to?(:force_encoding)
14
+ %>
15
+ <%= raw sections %>
@@ -0,0 +1,36 @@
1
+ <!DOCTYPE HTML>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Exception</title>
6
+ </head>
7
+ <body>
8
+ <pre style="font-size: 12px">
9
+ <%= @exception.class.to_s =~ /^[aeiou]/i ? 'An' : 'A' %> <%= @exception.class %> occurred in <%= @kontroller.controller_name %>#<%= @kontroller.action_name %>:
10
+
11
+ <%= raw @exception.message %>
12
+ <%= raw @backtrace.first %>
13
+
14
+ <%
15
+ sections = @sections.map do |section|
16
+ begin
17
+ summary = render(section).strip
18
+ unless summary.blank?
19
+ title = render("title", :title => section).strip
20
+ "#{title}\n\n#{summary.gsub(/^/, " ")}\n\n"
21
+ end
22
+
23
+ rescue Exception => e
24
+ title = render("title", :title => section).strip
25
+ summary = ["ERROR: Failed to generate exception summary:", [e.class.to_s, e.message].join(": "), e.backtrace && e.backtrace.join("\n")].compact.join("\n\n")
26
+
27
+ [title, summary.gsub(/^/, " "), nil].join("\n\n")
28
+ end
29
+ end.join
30
+ sections = sections.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace).encode('UTF-8') if sections.respond_to?(:force_encoding)
31
+ %>
32
+
33
+ <%= raw sections %>
34
+ </pre>
35
+ </body>
36
+ </html>
@@ -1,4 +1,4 @@
1
- A <%= @exception.class %> occurred in <%= @kontroller.controller_name %>#<%= @kontroller.action_name %>:
1
+ <%= @exception.class.to_s =~ /^[aeiou]/i ? 'An' : 'A' %> <%= @exception.class %> occurred in <%= @kontroller.controller_name %>#<%= @kontroller.action_name %>:
2
2
 
3
3
  <%= raw @exception.message %>
4
4
  <%= raw @backtrace.first %>
@@ -18,7 +18,8 @@ A <%= @exception.class %> occurred in <%= @kontroller.controller_name %>#<%= @ko
18
18
 
19
19
  [title, summary.gsub(/^/, " "), nil].join("\n\n")
20
20
  end
21
- end
21
+ end.join
22
+ sections = sections.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace).encode('UTF-8') if sections.respond_to?(:force_encoding)
22
23
  %>
23
24
 
24
- <%= raw sections.join %>
25
+ <%= raw sections %>
@@ -12,6 +12,10 @@ class BackgroundExceptionNotificationTest < ActiveSupport::TestCase
12
12
  end
13
13
  end
14
14
 
15
+ test "mail should be plain text and UTF-8 enconded by default" do
16
+ assert @mail.content_type == "text/plain; charset=UTF-8"
17
+ end
18
+
15
19
  test "should have raised an exception" do
16
20
  assert_not_nil @exception
17
21
  end
@@ -33,18 +37,29 @@ class BackgroundExceptionNotificationTest < ActiveSupport::TestCase
33
37
  end
34
38
 
35
39
  test "mail should say exception was raised in background at show timestamp" do
36
- assert @mail.body.include? "A ZeroDivisionError occurred in background at #{@time}"
40
+ assert @mail.encoded.include? "A ZeroDivisionError occurred in background at #{@time}"
41
+ end
42
+
43
+ test "mail should prefix exception class with 'an' instead of 'a' when it starts with a vowel" do
44
+ begin
45
+ raise ActiveRecord::RecordNotFound
46
+ rescue => e
47
+ @vowel_exception = e
48
+ @vowel_mail = ExceptionNotifier::Notifier.background_exception_notification(@vowel_exception)
49
+ end
50
+
51
+ assert @vowel_mail.encoded.include? "An ActiveRecord::RecordNotFound occurred in background at #{@time}"
37
52
  end
38
53
 
39
54
  test "mail should contain backtrace in body" do
40
- assert @mail.body.include? "test/background_exception_notification_test.rb:6"
55
+ assert @mail.encoded.include?("test/background_exception_notification_test.rb:6"), "\n#{@mail.inspect}"
41
56
  end
42
57
 
43
58
  test "mail should contain data in body" do
44
- assert @mail.body.include? '* data:'
45
- assert @mail.body.include? ':payload=>"1/0"'
46
- assert @mail.body.include? ':job=>"DivideWorkerJob"'
47
- assert @mail.body.include? "My Custom Message"
59
+ assert @mail.encoded.include? '* data:'
60
+ assert @mail.encoded.include? ':payload=>"1/0"'
61
+ assert @mail.encoded.include? ':job=>"DivideWorkerJob"'
62
+ assert @mail.encoded.include? "My Custom Message"
48
63
  end
49
64
 
50
65
  test "mail should not contain any attachments" do
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ class CampfireNotifierTest < ActiveSupport::TestCase
4
+
5
+ test "should send campfire notification if properly configured" do
6
+ ExceptionNotifier::CampfireNotifier.stubs(:new).returns(Object.new)
7
+ campfire = ExceptionNotifier::CampfireNotifier.new({:subdomain => 'test', :token => 'test_token', :room_name => 'test_room'})
8
+ campfire.stubs(:exception_notification).returns(fake_notification)
9
+ notif = campfire.exception_notification(fake_exception)
10
+
11
+ assert !notif[:message].empty?
12
+ assert_equal notif[:message][:type], 'PasteMessage'
13
+ assert notif[:message][:body].include? "A new exception occurred:"
14
+ assert notif[:message][:body].include? "divided by 0"
15
+ assert notif[:message][:body].include? "/exception_notification/test/campfire_test.rb:45"
16
+ end
17
+
18
+ test "should not send campfire notification if badly configured" do
19
+ wrong_params = {:subdomain => 'test', :token => 'bad_token', :room_name => 'test_room'}
20
+ Tinder::Campfire.stubs(:new).with('test', {:token => 'bad_token'}).returns(nil)
21
+ campfire = ExceptionNotifier::CampfireNotifier.new(wrong_params)
22
+
23
+ assert_nil campfire.room
24
+ assert_nil campfire.exception_notification(fake_exception)
25
+ end
26
+
27
+ test "should not send campfire notification if config attr missing" do
28
+ wrong_params = {:subdomain => 'test', :room_name => 'test_room'}
29
+ Tinder::Campfire.stubs(:new).with('test', {}).returns(nil)
30
+ campfire = ExceptionNotifier::CampfireNotifier.new(wrong_params)
31
+
32
+ assert_nil campfire.room
33
+ assert_nil campfire.exception_notification(fake_exception)
34
+ end
35
+
36
+ private
37
+
38
+ def fake_notification
39
+ {:message => {:type => 'PasteMessage',
40
+ :body => "A new exception occurred: 'divided by 0' on '/Users/sebastian/exception_notification/test/campfire_test.rb:45:in `/'"
41
+ }
42
+ }
43
+ end
44
+
45
+ def fake_exception
46
+ exception = begin
47
+ 5/0
48
+ rescue Exception => e
49
+ e
50
+ end
51
+ end
52
+ end
@@ -1,6 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'rails', '3.0.9'
3
+ gem 'rails', '3.2.8'
4
4
 
5
5
  # Bundle edge Rails instead:
6
6
  # gem 'rails', :git => 'git://github.com/rails/rails.git'
@@ -1,83 +1,118 @@
1
1
  PATH
2
2
  remote: ../../..
3
3
  specs:
4
- exception_notification (2.5.2)
4
+ exception_notification (2.6.1)
5
5
  actionmailer (>= 3.0.4)
6
+ tinder (~> 1.8)
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
9
10
  specs:
10
- abstract (1.0.0)
11
- actionmailer (3.0.9)
12
- actionpack (= 3.0.9)
13
- mail (~> 2.2.19)
14
- actionpack (3.0.9)
15
- activemodel (= 3.0.9)
16
- activesupport (= 3.0.9)
17
- builder (~> 2.1.2)
18
- erubis (~> 2.6.6)
19
- i18n (~> 0.5.0)
20
- rack (~> 1.2.1)
21
- rack-mount (~> 0.6.14)
22
- rack-test (~> 0.5.7)
23
- tzinfo (~> 0.3.23)
24
- activemodel (3.0.9)
25
- activesupport (= 3.0.9)
26
- builder (~> 2.1.2)
27
- i18n (~> 0.5.0)
28
- activerecord (3.0.9)
29
- activemodel (= 3.0.9)
30
- activesupport (= 3.0.9)
31
- arel (~> 2.0.10)
32
- tzinfo (~> 0.3.23)
33
- activeresource (3.0.9)
34
- activemodel (= 3.0.9)
35
- activesupport (= 3.0.9)
36
- activesupport (3.0.9)
37
- arel (2.0.10)
38
- builder (2.1.2)
39
- erubis (2.6.6)
40
- abstract (>= 1.0.0)
41
- i18n (0.5.0)
42
- mail (2.2.19)
43
- activesupport (>= 2.3.6)
11
+ actionmailer (3.2.8)
12
+ actionpack (= 3.2.8)
13
+ mail (~> 2.4.4)
14
+ actionpack (3.2.8)
15
+ activemodel (= 3.2.8)
16
+ activesupport (= 3.2.8)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ journey (~> 1.0.4)
20
+ rack (~> 1.4.0)
21
+ rack-cache (~> 1.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.1.3)
24
+ activemodel (3.2.8)
25
+ activesupport (= 3.2.8)
26
+ builder (~> 3.0.0)
27
+ activerecord (3.2.8)
28
+ activemodel (= 3.2.8)
29
+ activesupport (= 3.2.8)
30
+ arel (~> 3.0.2)
31
+ tzinfo (~> 0.3.29)
32
+ activeresource (3.2.8)
33
+ activemodel (= 3.2.8)
34
+ activesupport (= 3.2.8)
35
+ activesupport (3.2.8)
36
+ i18n (~> 0.6)
37
+ multi_json (~> 1.0)
38
+ arel (3.0.2)
39
+ builder (3.0.2)
40
+ erubis (2.7.0)
41
+ eventmachine (1.0.0)
42
+ faraday (0.8.4)
43
+ multipart-post (~> 1.1)
44
+ faraday_middleware (0.8.8)
45
+ faraday (>= 0.7.4, < 0.9)
46
+ hashie (1.2.0)
47
+ hike (1.2.1)
48
+ http_parser.rb (0.5.3)
49
+ i18n (0.6.1)
50
+ journey (1.0.4)
51
+ json (1.7.5)
52
+ mail (2.4.4)
44
53
  i18n (>= 0.4.0)
45
54
  mime-types (~> 1.16)
46
55
  treetop (~> 1.4.8)
47
- mime-types (1.16)
48
- polyglot (0.3.2)
49
- rack (1.2.3)
50
- rack-mount (0.6.14)
51
- rack (>= 1.0.0)
52
- rack-test (0.5.7)
56
+ mime-types (1.19)
57
+ multi_json (1.3.6)
58
+ multipart-post (1.1.5)
59
+ polyglot (0.3.3)
60
+ rack (1.4.1)
61
+ rack-cache (1.2)
62
+ rack (>= 0.4)
63
+ rack-ssl (1.3.2)
64
+ rack
65
+ rack-test (0.6.1)
53
66
  rack (>= 1.0)
54
- rails (3.0.9)
55
- actionmailer (= 3.0.9)
56
- actionpack (= 3.0.9)
57
- activerecord (= 3.0.9)
58
- activeresource (= 3.0.9)
59
- activesupport (= 3.0.9)
67
+ rails (3.2.8)
68
+ actionmailer (= 3.2.8)
69
+ actionpack (= 3.2.8)
70
+ activerecord (= 3.2.8)
71
+ activeresource (= 3.2.8)
72
+ activesupport (= 3.2.8)
60
73
  bundler (~> 1.0)
61
- railties (= 3.0.9)
62
- railties (3.0.9)
63
- actionpack (= 3.0.9)
64
- activesupport (= 3.0.9)
74
+ railties (= 3.2.8)
75
+ railties (3.2.8)
76
+ actionpack (= 3.2.8)
77
+ activesupport (= 3.2.8)
78
+ rack-ssl (~> 1.3.2)
65
79
  rake (>= 0.8.7)
66
80
  rdoc (~> 3.4)
67
- thor (~> 0.14.4)
68
- rake (0.9.2)
69
- rdoc (3.8)
70
- sqlite3 (1.3.4)
71
- thor (0.14.6)
81
+ thor (>= 0.14.6, < 2.0)
82
+ rake (0.9.2.2)
83
+ rdoc (3.12)
84
+ json (~> 1.4)
85
+ simple_oauth (0.1.9)
86
+ sprockets (2.1.3)
87
+ hike (~> 1.2)
88
+ rack (~> 1.0)
89
+ tilt (~> 1.1, != 1.3.0)
90
+ sqlite3 (1.3.6)
91
+ thor (0.16.0)
92
+ tilt (1.3.3)
93
+ tinder (1.9.1)
94
+ eventmachine (>= 0.12.0, < 2)
95
+ faraday (~> 0.8)
96
+ faraday_middleware (~> 0.8)
97
+ hashie (~> 1.0)
98
+ json (~> 1.6)
99
+ mime-types (~> 1.16)
100
+ multi_json (~> 1.0)
101
+ multipart-post (~> 1.1)
102
+ twitter-stream (~> 0.1)
72
103
  treetop (1.4.10)
73
104
  polyglot
74
105
  polyglot (>= 0.3.1)
75
- tzinfo (0.3.29)
106
+ twitter-stream (0.1.16)
107
+ eventmachine (>= 0.12.8)
108
+ http_parser.rb (~> 0.5.1)
109
+ simple_oauth (~> 0.1.4)
110
+ tzinfo (0.3.33)
76
111
 
77
112
  PLATFORMS
78
113
  ruby
79
114
 
80
115
  DEPENDENCIES
81
116
  exception_notification!
82
- rails (= 3.0.9)
117
+ rails (= 3.2.8)
83
118
  sqlite3
@@ -13,6 +13,7 @@ class PostsController < ApplicationController
13
13
  # POST /posts
14
14
  # POST /posts.xml
15
15
  def create
16
+ @sections = Object.new
16
17
  # Have this line raise an exception
17
18
  @post = Post.nw(params[:post])
18
19
 
@@ -0,0 +1 @@
1
+ * New background section for testing
@@ -0,0 +1 @@
1
+ * New html section for testing
@@ -1 +1 @@
1
- * New section for testing
1
+ * New text section for testing
@@ -19,6 +19,10 @@ class PostsControllerTest < ActionController::TestCase
19
19
  assert_not_nil @mail
20
20
  end
21
21
 
22
+ test "mail should be plain text and UTF-8 enconded by default" do
23
+ assert @mail.content_type == "text/plain; charset=UTF-8"
24
+ end
25
+
22
26
  test "mail should have a from address set" do
23
27
  assert @mail.from == ["dummynotifier@example.com"]
24
28
  end
@@ -27,28 +31,32 @@ class PostsControllerTest < ActionController::TestCase
27
31
  assert @mail.to == ["dummyexceptions@example.com"]
28
32
  end
29
33
 
30
- test "mail should have a descriptive subject" do
31
- assert @mail.subject.include? "[Dummy ERROR] # (NoMethodError) \"undefined method `nw'"
34
+ test "mail subject should have the proper prefix" do
35
+ assert @mail.subject.include? "[Dummy ERROR]"
36
+ end
37
+
38
+ test "mail subject should include descriptive error message" do
39
+ assert @mail.subject.include? "(NoMethodError) \"undefined method `nw'"
32
40
  end
33
41
 
34
42
  test "mail should contain backtrace in body" do
35
- assert @mail.body.include? "`method_missing'\n app/controllers/posts_controller.rb:17:in `create'\n"
43
+ assert @mail.encoded.include? "`method_missing'\r\n app/controllers/posts_controller.rb:18:in `create'\r\n"
36
44
  end
37
45
 
38
46
  test "mail should contain timestamp of exception in body" do
39
- assert @mail.body.include? "Timestamp : #{Time.current}"
47
+ assert @mail.encoded.include? "Timestamp : #{Time.current}"
40
48
  end
41
49
 
42
50
  test "mail should contain the newly defined section" do
43
- assert @mail.body.include? "* New section for testing"
51
+ assert @mail.encoded.include? "* New text section for testing"
44
52
  end
45
53
 
46
54
  test "mail should contain the custom message" do
47
- assert @mail.body.include? "My Custom Message"
55
+ assert @mail.encoded.include? "My Custom Message"
48
56
  end
49
57
 
50
58
  test "should filter sensible data" do
51
- assert @mail.body.include? "secret\"=>\"[FILTERED]"
59
+ assert @mail.encoded.include? "secret\"=>\"[FILTERED]"
52
60
  end
53
61
 
54
62
  test "mail should not contain any attachments" do
@@ -79,7 +87,7 @@ class PostsControllerTest < ActionController::TestCase
79
87
  end
80
88
 
81
89
  assert request.ssl?
82
- assert @secured_mail.body.include? "* session id: [FILTERED]\n *"
90
+ assert @secured_mail.encoded.include? "* session id: [FILTERED]\r\n *"
83
91
  end
84
92
 
85
93
  test "should ignore exception if from unwanted cralwer" do
@@ -119,6 +127,21 @@ class PostsControllerTest < ActionController::TestCase
119
127
 
120
128
  assert_nil @ignored_mail
121
129
  end
130
+
131
+ test "should send html email when selected html format" do
132
+ begin
133
+ @post = posts(:one)
134
+ post :create, :post => @post.attributes
135
+ rescue => e
136
+ @exception = e
137
+ custom_env = request.env
138
+ custom_env['exception_notifier.options'] ||= {}
139
+ custom_env['exception_notifier.options'].merge!({:email_format => :html})
140
+ @mail = ExceptionNotifier::Notifier.exception_notification(custom_env, @exception)
141
+ end
142
+
143
+ assert @mail.content_type.include? "multipart/alternative"
144
+ end
122
145
  end
123
146
 
124
147
  class PostsControllerTestWithoutVerboseSubject < ActionController::TestCase
@@ -139,6 +162,35 @@ class PostsControllerTestWithoutVerboseSubject < ActionController::TestCase
139
162
  end
140
163
  end
141
164
 
165
+ class PostsControllerTestWithSmtpSettings < ActionController::TestCase
166
+ tests PostsController
167
+ setup do
168
+ ExceptionNotifier::Notifier.default_smtp_settings = {
169
+ :user_name => "Dummy user_name",
170
+ :password => "Dummy password"
171
+ }
172
+
173
+ begin
174
+ @post = posts(:one)
175
+ post :create, :post => @post.attributes
176
+ rescue => e
177
+ @exception = e
178
+ @mail = ExceptionNotifier::Notifier.exception_notification(request.env, @exception)
179
+ end
180
+ end
181
+
182
+ test "should have overridden smtp settings" do
183
+ assert_equal "Dummy user_name", @mail.delivery_method.settings[:user_name]
184
+ assert_equal "Dummy password", @mail.delivery_method.settings[:password]
185
+ end
186
+
187
+ test "should have overridden smtp settings with background notification" do
188
+ @mail = ExceptionNotifier::Notifier.background_exception_notification(@exception)
189
+ assert_equal "Dummy user_name", @mail.delivery_method.settings[:user_name]
190
+ assert_equal "Dummy password", @mail.delivery_method.settings[:password]
191
+ end
192
+ end
193
+
142
194
  class PostsControllerTestBadRequestData < ActionController::TestCase
143
195
  tests PostsController
144
196
  setup do
@@ -162,7 +214,7 @@ class PostsControllerTestBadRequestData < ActionController::TestCase
162
214
  end
163
215
 
164
216
  test "should include error message in body" do
165
- assert_match /ERROR: Failed to generate exception summary/, @mail.body.to_s
217
+ assert_match /ERROR: Failed to generate exception summary/, @mail.encoded.to_s
166
218
  end
167
219
  end
168
220
 
@@ -178,6 +230,6 @@ class PostsControllerTestBackgroundNotification < ActionController::TestCase
178
230
  end
179
231
 
180
232
  test "mail should contain the specified section" do
181
- assert @mail.body.include? "* New background section for testing"
233
+ assert @mail.encoded.include? "* New background section for testing"
182
234
  end
183
235
  end