exception_notification 3.0.1 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +7 -0
  2. data/Appraisals +7 -0
  3. data/CHANGELOG.rdoc +129 -1
  4. data/CODE_OF_CONDUCT.md +22 -0
  5. data/CONTRIBUTING.md +29 -1
  6. data/Gemfile +1 -1
  7. data/MIT-LICENSE +23 -0
  8. data/README.md +168 -222
  9. data/Rakefile +5 -11
  10. data/docs/notifiers/campfire.md +50 -0
  11. data/docs/notifiers/custom.md +42 -0
  12. data/docs/notifiers/datadog.md +51 -0
  13. data/docs/notifiers/email.md +195 -0
  14. data/docs/notifiers/google_chat.md +31 -0
  15. data/docs/notifiers/hipchat.md +66 -0
  16. data/docs/notifiers/irc.md +97 -0
  17. data/docs/notifiers/mattermost.md +115 -0
  18. data/docs/notifiers/slack.md +161 -0
  19. data/docs/notifiers/sns.md +37 -0
  20. data/docs/notifiers/teams.md +54 -0
  21. data/docs/notifiers/webhook.md +60 -0
  22. data/examples/sample_app.rb +54 -0
  23. data/examples/sinatra/Gemfile +8 -0
  24. data/examples/sinatra/Gemfile.lock +95 -0
  25. data/examples/sinatra/Procfile +2 -0
  26. data/examples/sinatra/README.md +11 -0
  27. data/examples/sinatra/config.ru +3 -0
  28. data/examples/sinatra/sinatra_app.rb +36 -0
  29. data/exception_notification.gemspec +32 -11
  30. data/gemfiles/rails4_0.gemfile +7 -0
  31. data/gemfiles/rails4_1.gemfile +7 -0
  32. data/gemfiles/rails4_2.gemfile +7 -0
  33. data/gemfiles/rails5_0.gemfile +7 -0
  34. data/gemfiles/rails5_1.gemfile +7 -0
  35. data/gemfiles/rails5_2.gemfile +7 -0
  36. data/gemfiles/rails6_0.gemfile +7 -0
  37. data/lib/exception_notification.rb +11 -0
  38. data/lib/exception_notification/rack.rb +55 -0
  39. data/lib/exception_notification/rails.rb +9 -0
  40. data/lib/exception_notification/resque.rb +22 -0
  41. data/lib/exception_notification/sidekiq.rb +27 -0
  42. data/lib/exception_notification/version.rb +3 -0
  43. data/lib/exception_notifier.rb +137 -61
  44. data/lib/exception_notifier/base_notifier.rb +24 -0
  45. data/lib/exception_notifier/campfire_notifier.rb +16 -11
  46. data/lib/exception_notifier/datadog_notifier.rb +153 -0
  47. data/lib/exception_notifier/email_notifier.rb +196 -0
  48. data/lib/exception_notifier/google_chat_notifier.rb +42 -0
  49. data/lib/exception_notifier/hipchat_notifier.rb +49 -0
  50. data/lib/exception_notifier/irc_notifier.rb +57 -0
  51. data/lib/exception_notifier/mattermost_notifier.rb +72 -0
  52. data/lib/exception_notifier/modules/backtrace_cleaner.rb +11 -0
  53. data/lib/exception_notifier/modules/error_grouping.rb +77 -0
  54. data/lib/exception_notifier/modules/formatter.rb +118 -0
  55. data/lib/exception_notifier/notifier.rb +9 -179
  56. data/lib/exception_notifier/slack_notifier.rb +111 -0
  57. data/lib/exception_notifier/sns_notifier.rb +85 -0
  58. data/lib/exception_notifier/teams_notifier.rb +193 -0
  59. data/lib/exception_notifier/views/exception_notifier/_backtrace.html.erb +3 -1
  60. data/lib/exception_notifier/views/exception_notifier/_data.html.erb +6 -1
  61. data/lib/exception_notifier/views/exception_notifier/_environment.html.erb +8 -6
  62. data/lib/exception_notifier/views/exception_notifier/_environment.text.erb +1 -4
  63. data/lib/exception_notifier/views/exception_notifier/_request.html.erb +36 -5
  64. data/lib/exception_notifier/views/exception_notifier/_request.text.erb +10 -5
  65. data/lib/exception_notifier/views/exception_notifier/_session.html.erb +10 -2
  66. data/lib/exception_notifier/views/exception_notifier/_session.text.erb +2 -2
  67. data/lib/exception_notifier/views/exception_notifier/_title.html.erb +3 -3
  68. data/lib/exception_notifier/views/exception_notifier/background_exception_notification.html.erb +38 -11
  69. data/lib/exception_notifier/views/exception_notifier/background_exception_notification.text.erb +10 -11
  70. data/lib/exception_notifier/views/exception_notifier/exception_notification.html.erb +38 -22
  71. data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +2 -3
  72. data/lib/exception_notifier/webhook_notifier.rb +51 -0
  73. data/lib/generators/exception_notification/install_generator.rb +15 -0
  74. data/lib/generators/exception_notification/templates/exception_notification.rb.erb +55 -0
  75. data/test/exception_notification/rack_test.rb +60 -0
  76. data/test/exception_notification/resque_test.rb +52 -0
  77. data/test/exception_notifier/campfire_notifier_test.rb +120 -0
  78. data/test/exception_notifier/datadog_notifier_test.rb +151 -0
  79. data/test/exception_notifier/email_notifier_test.rb +351 -0
  80. data/test/exception_notifier/google_chat_notifier_test.rb +181 -0
  81. data/test/exception_notifier/hipchat_notifier_test.rb +218 -0
  82. data/test/exception_notifier/irc_notifier_test.rb +137 -0
  83. data/test/exception_notifier/mattermost_notifier_test.rb +202 -0
  84. data/test/exception_notifier/modules/error_grouping_test.rb +165 -0
  85. data/test/exception_notifier/modules/formatter_test.rb +150 -0
  86. data/test/exception_notifier/sidekiq_test.rb +38 -0
  87. data/test/exception_notifier/slack_notifier_test.rb +227 -0
  88. data/test/exception_notifier/sns_notifier_test.rb +121 -0
  89. data/test/exception_notifier/teams_notifier_test.rb +90 -0
  90. data/test/exception_notifier/webhook_notifier_test.rb +96 -0
  91. data/test/exception_notifier_test.rb +182 -0
  92. data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.html.erb +0 -0
  93. data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.text.erb +0 -0
  94. data/test/{dummy/app → support}/views/exception_notifier/_new_section.html.erb +0 -0
  95. data/test/{dummy/app → support}/views/exception_notifier/_new_section.text.erb +0 -0
  96. data/test/test_helper.rb +12 -8
  97. metadata +333 -164
  98. data/.gemtest +0 -0
  99. data/Gemfile.lock +0 -122
  100. data/test/background_exception_notification_test.rb +0 -82
  101. data/test/campfire_test.rb +0 -53
  102. data/test/dummy/.gitignore +0 -4
  103. data/test/dummy/Gemfile +0 -33
  104. data/test/dummy/Gemfile.lock +0 -118
  105. data/test/dummy/Rakefile +0 -7
  106. data/test/dummy/app/controllers/application_controller.rb +0 -3
  107. data/test/dummy/app/controllers/posts_controller.rb +0 -30
  108. data/test/dummy/app/helpers/application_helper.rb +0 -2
  109. data/test/dummy/app/helpers/posts_helper.rb +0 -2
  110. data/test/dummy/app/models/post.rb +0 -2
  111. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  112. data/test/dummy/app/views/posts/_form.html.erb +0 -0
  113. data/test/dummy/app/views/posts/new.html.erb +0 -0
  114. data/test/dummy/app/views/posts/show.html.erb +0 -0
  115. data/test/dummy/config.ru +0 -4
  116. data/test/dummy/config/application.rb +0 -42
  117. data/test/dummy/config/boot.rb +0 -6
  118. data/test/dummy/config/database.yml +0 -22
  119. data/test/dummy/config/environment.rb +0 -13
  120. data/test/dummy/config/environments/development.rb +0 -24
  121. data/test/dummy/config/environments/production.rb +0 -49
  122. data/test/dummy/config/environments/test.rb +0 -35
  123. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  124. data/test/dummy/config/initializers/inflections.rb +0 -10
  125. data/test/dummy/config/initializers/mime_types.rb +0 -5
  126. data/test/dummy/config/initializers/secret_token.rb +0 -7
  127. data/test/dummy/config/initializers/session_store.rb +0 -8
  128. data/test/dummy/config/locales/en.yml +0 -5
  129. data/test/dummy/config/routes.rb +0 -3
  130. data/test/dummy/db/migrate/20110729022608_create_posts.rb +0 -15
  131. data/test/dummy/db/schema.rb +0 -24
  132. data/test/dummy/db/seeds.rb +0 -7
  133. data/test/dummy/lib/tasks/.gitkeep +0 -0
  134. data/test/dummy/public/404.html +0 -26
  135. data/test/dummy/public/422.html +0 -26
  136. data/test/dummy/public/500.html +0 -26
  137. data/test/dummy/public/favicon.ico +0 -0
  138. data/test/dummy/public/images/rails.png +0 -0
  139. data/test/dummy/public/index.html +0 -239
  140. data/test/dummy/public/javascripts/application.js +0 -2
  141. data/test/dummy/public/javascripts/controls.js +0 -965
  142. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  143. data/test/dummy/public/javascripts/effects.js +0 -1123
  144. data/test/dummy/public/javascripts/prototype.js +0 -6001
  145. data/test/dummy/public/javascripts/rails.js +0 -191
  146. data/test/dummy/public/robots.txt +0 -5
  147. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  148. data/test/dummy/public/stylesheets/scaffold.css +0 -56
  149. data/test/dummy/script/rails +0 -6
  150. data/test/dummy/test/fixtures/posts.yml +0 -11
  151. data/test/dummy/test/functional/posts_controller_test.rb +0 -239
  152. data/test/dummy/test/test_helper.rb +0 -13
  153. data/test/exception_notification_test.rb +0 -73
@@ -1,191 +0,0 @@
1
- (function() {
2
- // Technique from Juriy Zaytsev
3
- // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
- function isEventSupported(eventName) {
5
- var el = document.createElement('div');
6
- eventName = 'on' + eventName;
7
- var isSupported = (eventName in el);
8
- if (!isSupported) {
9
- el.setAttribute(eventName, 'return;');
10
- isSupported = typeof el[eventName] == 'function';
11
- }
12
- el = null;
13
- return isSupported;
14
- }
15
-
16
- function isForm(element) {
17
- return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
- }
19
-
20
- function isInput(element) {
21
- if (Object.isElement(element)) {
22
- var name = element.nodeName.toUpperCase()
23
- return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
- }
25
- else return false
26
- }
27
-
28
- var submitBubbles = isEventSupported('submit'),
29
- changeBubbles = isEventSupported('change')
30
-
31
- if (!submitBubbles || !changeBubbles) {
32
- // augment the Event.Handler class to observe custom events when needed
33
- Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
- function(init, element, eventName, selector, callback) {
35
- init(element, eventName, selector, callback)
36
- // is the handler being attached to an element that doesn't support this event?
37
- if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
- (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
- // "submit" => "emulated:submit"
40
- this.eventName = 'emulated:' + this.eventName
41
- }
42
- }
43
- )
44
- }
45
-
46
- if (!submitBubbles) {
47
- // discover forms on the page by observing focus events which always bubble
48
- document.on('focusin', 'form', function(focusEvent, form) {
49
- // special handler for the real "submit" event (one-time operation)
50
- if (!form.retrieve('emulated:submit')) {
51
- form.on('submit', function(submitEvent) {
52
- var emulated = form.fire('emulated:submit', submitEvent, true)
53
- // if custom event received preventDefault, cancel the real one too
54
- if (emulated.returnValue === false) submitEvent.preventDefault()
55
- })
56
- form.store('emulated:submit', true)
57
- }
58
- })
59
- }
60
-
61
- if (!changeBubbles) {
62
- // discover form inputs on the page
63
- document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
- // special handler for real "change" events
65
- if (!input.retrieve('emulated:change')) {
66
- input.on('change', function(changeEvent) {
67
- input.fire('emulated:change', changeEvent, true)
68
- })
69
- input.store('emulated:change', true)
70
- }
71
- })
72
- }
73
-
74
- function handleRemote(element) {
75
- var method, url, params;
76
-
77
- var event = element.fire("ajax:before");
78
- if (event.stopped) return false;
79
-
80
- if (element.tagName.toLowerCase() === 'form') {
81
- method = element.readAttribute('method') || 'post';
82
- url = element.readAttribute('action');
83
- params = element.serialize();
84
- } else {
85
- method = element.readAttribute('data-method') || 'get';
86
- url = element.readAttribute('href');
87
- params = {};
88
- }
89
-
90
- new Ajax.Request(url, {
91
- method: method,
92
- parameters: params,
93
- evalScripts: true,
94
-
95
- onComplete: function(request) { element.fire("ajax:complete", request); },
96
- onSuccess: function(request) { element.fire("ajax:success", request); },
97
- onFailure: function(request) { element.fire("ajax:failure", request); }
98
- });
99
-
100
- element.fire("ajax:after");
101
- }
102
-
103
- function handleMethod(element) {
104
- var method = element.readAttribute('data-method'),
105
- url = element.readAttribute('href'),
106
- csrf_param = $$('meta[name=csrf-param]')[0],
107
- csrf_token = $$('meta[name=csrf-token]')[0];
108
-
109
- var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
- element.parentNode.insert(form);
111
-
112
- if (method !== 'post') {
113
- var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
- form.insert(field);
115
- }
116
-
117
- if (csrf_param) {
118
- var param = csrf_param.readAttribute('content'),
119
- token = csrf_token.readAttribute('content'),
120
- field = new Element('input', { type: 'hidden', name: param, value: token });
121
- form.insert(field);
122
- }
123
-
124
- form.submit();
125
- }
126
-
127
-
128
- document.on("click", "*[data-confirm]", function(event, element) {
129
- var message = element.readAttribute('data-confirm');
130
- if (!confirm(message)) event.stop();
131
- });
132
-
133
- document.on("click", "a[data-remote]", function(event, element) {
134
- if (event.stopped) return;
135
- handleRemote(element);
136
- event.stop();
137
- });
138
-
139
- document.on("click", "a[data-method]", function(event, element) {
140
- if (event.stopped) return;
141
- handleMethod(element);
142
- event.stop();
143
- });
144
-
145
- document.on("submit", function(event) {
146
- var element = event.findElement(),
147
- message = element.readAttribute('data-confirm');
148
- if (message && !confirm(message)) {
149
- event.stop();
150
- return false;
151
- }
152
-
153
- var inputs = element.select("input[type=submit][data-disable-with]");
154
- inputs.each(function(input) {
155
- input.disabled = true;
156
- input.writeAttribute('data-original-value', input.value);
157
- input.value = input.readAttribute('data-disable-with');
158
- });
159
-
160
- var element = event.findElement("form[data-remote]");
161
- if (element) {
162
- handleRemote(element);
163
- event.stop();
164
- }
165
- });
166
-
167
- document.on("ajax:after", "form", function(event, element) {
168
- var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
- inputs.each(function(input) {
170
- input.value = input.readAttribute('data-original-value');
171
- input.removeAttribute('data-original-value');
172
- input.disabled = false;
173
- });
174
- });
175
-
176
- Ajax.Responders.register({
177
- onCreate: function(request) {
178
- var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
179
-
180
- if (csrf_meta_tag) {
181
- var header = 'X-CSRF-Token',
182
- token = csrf_meta_tag.readAttribute('content');
183
-
184
- if (!request.options.requestHeaders) {
185
- request.options.requestHeaders = {};
186
- }
187
- request.options.requestHeaders[header] = token;
188
- }
189
- }
190
- });
191
- })();
@@ -1,5 +0,0 @@
1
- # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
- #
3
- # To ban all spiders from the entire site uncomment the next two lines:
4
- # User-Agent: *
5
- # Disallow: /
File without changes
@@ -1,56 +0,0 @@
1
- body { background-color: #fff; color: #333; }
2
-
3
- body, p, ol, ul, td {
4
- font-family: verdana, arial, helvetica, sans-serif;
5
- font-size: 13px;
6
- line-height: 18px;
7
- }
8
-
9
- pre {
10
- background-color: #eee;
11
- padding: 10px;
12
- font-size: 11px;
13
- }
14
-
15
- a { color: #000; }
16
- a:visited { color: #666; }
17
- a:hover { color: #fff; background-color:#000; }
18
-
19
- div.field, div.actions {
20
- margin-bottom: 10px;
21
- }
22
-
23
- #notice {
24
- color: green;
25
- }
26
-
27
- .field_with_errors {
28
- padding: 2px;
29
- background-color: red;
30
- display: table;
31
- }
32
-
33
- #error_explanation {
34
- width: 450px;
35
- border: 2px solid red;
36
- padding: 7px;
37
- padding-bottom: 0;
38
- margin-bottom: 20px;
39
- background-color: #f0f0f0;
40
- }
41
-
42
- #error_explanation h2 {
43
- text-align: left;
44
- font-weight: bold;
45
- padding: 5px 5px 5px 15px;
46
- font-size: 12px;
47
- margin: -7px;
48
- margin-bottom: 0px;
49
- background-color: #c00;
50
- color: #fff;
51
- }
52
-
53
- #error_explanation ul li {
54
- font-size: 12px;
55
- list-style: square;
56
- }
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
6
- require 'rails/commands'
@@ -1,11 +0,0 @@
1
- # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
-
3
- one:
4
- title: MyString
5
- body: MyText
6
- secret: MySecret
7
-
8
- two:
9
- title: MyString
10
- body: MyText
11
- secret: MySecret
@@ -1,239 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PostsControllerTest < ActionController::TestCase
4
- setup do
5
- begin
6
- @post = posts(:one)
7
- post :create, :post => @post.attributes
8
- rescue => e
9
- @exception = e
10
- @mail = ExceptionNotifier::Notifier.exception_notification(request.env, @exception, {:data => {:message => 'My Custom Message'}})
11
- end
12
- end
13
-
14
- test "should have raised an exception" do
15
- assert_not_nil @exception
16
- end
17
-
18
- test "should have generated a notification email" do
19
- assert_not_nil @mail
20
- end
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
-
26
- test "mail should have a from address set" do
27
- assert @mail.from == ["dummynotifier@example.com"]
28
- end
29
-
30
- test "mail should have a to address set" do
31
- assert @mail.to == ["dummyexceptions@example.com"]
32
- end
33
-
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'"
40
- end
41
-
42
- test "mail should contain backtrace in body" do
43
- assert @mail.encoded.include? "`method_missing'\r\n app/controllers/posts_controller.rb:18:in `create'\r\n"
44
- end
45
-
46
- test "mail should contain timestamp of exception in body" do
47
- assert @mail.encoded.include? "Timestamp : #{Time.current}"
48
- end
49
-
50
- test "mail should contain the newly defined section" do
51
- assert @mail.encoded.include? "* New text section for testing"
52
- end
53
-
54
- test "mail should contain the custom message" do
55
- assert @mail.encoded.include? "My Custom Message"
56
- end
57
-
58
- test "should filter sensible data" do
59
- assert @mail.encoded.include? "secret\"=>\"[FILTERED]"
60
- end
61
-
62
- test "mail should contain the custom header" do
63
- assert @mail.encoded.include? 'X-Custom-Header: foobar'
64
- end
65
-
66
- test "mail should not contain any attachments" do
67
- assert @mail.attachments == []
68
- end
69
-
70
- test "should not send notification if one of ignored exceptions" do
71
- begin
72
- get :show, :id => @post.to_param + "10"
73
- rescue => e
74
- @ignored_exception = e
75
- unless ExceptionNotifier.default_ignore_exceptions.include?(@ignored_exception.class.name)
76
- @ignored_mail = ExceptionNotifier::Notifier.exception_notification(request.env, @ignored_exception)
77
- end
78
- end
79
-
80
- assert @ignored_exception.class.inspect == "ActiveRecord::RecordNotFound"
81
- assert_nil @ignored_mail
82
- end
83
-
84
- test "should filter session_id on secure requests" do
85
- request.env['HTTPS'] = 'on'
86
- begin
87
- @post = posts(:one)
88
- post :create, :post => @post.attributes
89
- rescue => e
90
- @secured_mail = ExceptionNotifier::Notifier.exception_notification(request.env, e)
91
- end
92
-
93
- assert request.ssl?
94
- assert @secured_mail.encoded.include? "* session id: [FILTERED]\r\n *"
95
- end
96
-
97
- test "should ignore exception if from unwanted cralwer" do
98
- request.env['HTTP_USER_AGENT'] = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
99
- begin
100
- @post = posts(:one)
101
- post :create, :post => @post.attributes
102
- rescue => e
103
- @exception = e
104
- custom_env = request.env
105
- custom_env['exception_notifier.options'] ||= {}
106
- custom_env['exception_notifier.options'].merge!(:ignore_crawlers => %w(Googlebot))
107
- ignore_array = custom_env['exception_notifier.options'][:ignore_crawlers]
108
- unless ExceptionNotifier.new(Dummy::Application, custom_env['exception_notifier.options']).send(:from_crawler, ignore_array, custom_env['HTTP_USER_AGENT'])
109
- @ignored_mail = ExceptionNotifier::Notifier.exception_notification(custom_env, @exception)
110
- end
111
- end
112
-
113
- assert_nil @ignored_mail
114
- end
115
-
116
- test "should ignore exception if satisfies conditional ignore" do
117
- request.env['IGNOREME'] = "IGNOREME"
118
- begin
119
- @post = posts(:one)
120
- post :create, :post => @post.attributes
121
- rescue => e
122
- @exception = e
123
- custom_env = request.env
124
- custom_env['exception_notifier.options'] ||= {}
125
- ignore_cond = {:ignore_if => lambda {|env, e| (env['IGNOREME'] == 'IGNOREME') && (e.message =~ /undefined method/)}}
126
- custom_env['exception_notifier.options'].merge!(ignore_cond)
127
- unless ExceptionNotifier.new(Dummy::Application, custom_env['exception_notifier.options']).send(:conditionally_ignored, ignore_cond[:ignore_if], custom_env, @exception)
128
- @ignored_mail = ExceptionNotifier::Notifier.exception_notification(custom_env, @exception)
129
- end
130
- end
131
-
132
- assert_nil @ignored_mail
133
- end
134
-
135
- test "should send html email when selected html format" do
136
- begin
137
- @post = posts(:one)
138
- post :create, :post => @post.attributes
139
- rescue => e
140
- @exception = e
141
- custom_env = request.env
142
- custom_env['exception_notifier.options'] ||= {}
143
- custom_env['exception_notifier.options'].merge!({:email_format => :html})
144
- @mail = ExceptionNotifier::Notifier.exception_notification(custom_env, @exception)
145
- end
146
-
147
- assert @mail.content_type.include? "multipart/alternative"
148
- end
149
- end
150
-
151
- class PostsControllerTestWithoutVerboseSubject < ActionController::TestCase
152
- tests PostsController
153
- setup do
154
- ExceptionNotifier::Notifier.default_verbose_subject = false
155
- begin
156
- @post = posts(:one)
157
- post :create, :post => @post.attributes
158
- rescue => e
159
- @exception = e
160
- @mail = ExceptionNotifier::Notifier.exception_notification(request.env, @exception)
161
- end
162
- end
163
-
164
- test "should not include exception message in subject" do
165
- assert_equal "[ERROR] # (NoMethodError)", @mail.subject
166
- end
167
- end
168
-
169
- class PostsControllerTestWithSmtpSettings < ActionController::TestCase
170
- tests PostsController
171
- setup do
172
- ExceptionNotifier::Notifier.default_smtp_settings = {
173
- :user_name => "Dummy user_name",
174
- :password => "Dummy password"
175
- }
176
-
177
- begin
178
- @post = posts(:one)
179
- post :create, :post => @post.attributes
180
- rescue => e
181
- @exception = e
182
- @mail = ExceptionNotifier::Notifier.exception_notification(request.env, @exception)
183
- end
184
- end
185
-
186
- test "should have overridden smtp settings" do
187
- assert_equal "Dummy user_name", @mail.delivery_method.settings[:user_name]
188
- assert_equal "Dummy password", @mail.delivery_method.settings[:password]
189
- end
190
-
191
- test "should have overridden smtp settings with background notification" do
192
- @mail = ExceptionNotifier::Notifier.background_exception_notification(@exception)
193
- assert_equal "Dummy user_name", @mail.delivery_method.settings[:user_name]
194
- assert_equal "Dummy password", @mail.delivery_method.settings[:password]
195
- end
196
- end
197
-
198
- class PostsControllerTestBadRequestData < ActionController::TestCase
199
- tests PostsController
200
- setup do
201
- begin
202
- # This might seem synthetic, but the point is that the data used by
203
- # ExceptionNotification could be rendered "invalid" by e.g. a badly
204
- # behaving middleware, and we want to test that ExceptionNotification
205
- # still manages to send off an email in those cases.
206
- #
207
- # The trick here is to trigger an exception in the template used by
208
- # ExceptionNotification. (The original test stuffed request.env with
209
- # badly encoded strings, but that only works in Ruby 1.9+.)
210
- request.send :instance_variable_set, :@env, {}
211
-
212
- @post = posts(:one)
213
- post :create, :post => @post.attributes
214
- rescue => e
215
- @exception = e
216
- @mail = ExceptionNotifier::Notifier.exception_notification(request.env, @exception)
217
- end
218
- end
219
-
220
- test "should include error message in body" do
221
- assert_match /ERROR: Failed to generate exception summary/, @mail.encoded.to_s
222
- end
223
- end
224
-
225
- class PostsControllerTestBackgroundNotification < ActionController::TestCase
226
- tests PostsController
227
- setup do
228
- begin
229
- @post = posts(:one)
230
- post :create, :post => @post.attributes
231
- rescue => exception
232
- @mail = ExceptionNotifier::Notifier.background_exception_notification(exception)
233
- end
234
- end
235
-
236
- test "mail should contain the specified section" do
237
- assert @mail.encoded.include? "* New background section for testing"
238
- end
239
- end