exception_notification 4.3.0 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +5 -5
  2. data/Appraisals +4 -2
  3. data/CHANGELOG.rdoc +47 -0
  4. data/CONTRIBUTING.md +18 -0
  5. data/Gemfile +3 -1
  6. data/README.md +97 -945
  7. data/Rakefile +4 -2
  8. data/docs/notifiers/campfire.md +50 -0
  9. data/docs/notifiers/custom.md +42 -0
  10. data/docs/notifiers/datadog.md +51 -0
  11. data/docs/notifiers/email.md +195 -0
  12. data/docs/notifiers/google_chat.md +31 -0
  13. data/docs/notifiers/hipchat.md +66 -0
  14. data/docs/notifiers/irc.md +97 -0
  15. data/docs/notifiers/mattermost.md +115 -0
  16. data/docs/notifiers/slack.md +161 -0
  17. data/docs/notifiers/sns.md +37 -0
  18. data/docs/notifiers/teams.md +54 -0
  19. data/docs/notifiers/webhook.md +60 -0
  20. data/examples/sample_app.rb +56 -0
  21. data/examples/sinatra/Gemfile +8 -6
  22. data/examples/sinatra/config.ru +3 -1
  23. data/examples/sinatra/sinatra_app.rb +19 -11
  24. data/exception_notification.gemspec +30 -24
  25. data/gemfiles/{rails4_0.gemfile → rails5_2.gemfile} +2 -2
  26. data/gemfiles/{rails4_1.gemfile → rails6_0.gemfile} +2 -2
  27. data/gemfiles/{rails4_2.gemfile → rails6_1.gemfile} +2 -2
  28. data/gemfiles/{rails5_0.gemfile → rails7_0.gemfile} +2 -2
  29. data/lib/exception_notification/rack.rb +28 -30
  30. data/lib/exception_notification/rails.rb +2 -0
  31. data/lib/exception_notification/resque.rb +10 -10
  32. data/lib/exception_notification/sidekiq.rb +10 -12
  33. data/lib/exception_notification/version.rb +5 -0
  34. data/lib/exception_notification.rb +3 -0
  35. data/lib/exception_notifier/base_notifier.rb +10 -5
  36. data/lib/exception_notifier/datadog_notifier.rb +156 -0
  37. data/lib/exception_notifier/email_notifier.rb +73 -88
  38. data/lib/exception_notifier/google_chat_notifier.rb +27 -119
  39. data/lib/exception_notifier/hipchat_notifier.rb +13 -12
  40. data/lib/exception_notifier/irc_notifier.rb +36 -33
  41. data/lib/exception_notifier/mattermost_notifier.rb +54 -137
  42. data/lib/exception_notifier/modules/backtrace_cleaner.rb +2 -2
  43. data/lib/exception_notifier/modules/error_grouping.rb +24 -13
  44. data/lib/exception_notifier/modules/formatter.rb +125 -0
  45. data/lib/exception_notifier/notifier.rb +9 -6
  46. data/lib/exception_notifier/slack_notifier.rb +65 -40
  47. data/lib/exception_notifier/sns_notifier.rb +23 -13
  48. data/lib/exception_notifier/teams_notifier.rb +67 -46
  49. data/lib/exception_notifier/views/exception_notifier/_backtrace.html.erb +1 -1
  50. data/lib/exception_notifier/views/exception_notifier/_environment.text.erb +1 -1
  51. data/lib/exception_notifier/views/exception_notifier/_request.text.erb +1 -1
  52. data/lib/exception_notifier/views/exception_notifier/exception_notification.html.erb +2 -2
  53. data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +2 -2
  54. data/lib/exception_notifier/webhook_notifier.rb +17 -14
  55. data/lib/exception_notifier.rb +65 -10
  56. data/lib/generators/exception_notification/install_generator.rb +11 -5
  57. data/lib/generators/exception_notification/templates/{exception_notification.rb → exception_notification.rb.erb} +13 -11
  58. data/test/exception_notification/rack_test.rb +75 -13
  59. data/test/exception_notification/resque_test.rb +54 -0
  60. data/test/exception_notifier/datadog_notifier_test.rb +153 -0
  61. data/test/exception_notifier/email_notifier_test.rb +275 -153
  62. data/test/exception_notifier/google_chat_notifier_test.rb +158 -101
  63. data/test/exception_notifier/hipchat_notifier_test.rb +84 -81
  64. data/test/exception_notifier/irc_notifier_test.rb +36 -34
  65. data/test/exception_notifier/mattermost_notifier_test.rb +213 -67
  66. data/test/exception_notifier/modules/error_grouping_test.rb +41 -40
  67. data/test/exception_notifier/modules/formatter_test.rb +152 -0
  68. data/test/exception_notifier/sidekiq_test.rb +9 -17
  69. data/test/exception_notifier/slack_notifier_test.rb +66 -63
  70. data/test/exception_notifier/sns_notifier_test.rb +84 -32
  71. data/test/exception_notifier/teams_notifier_test.rb +25 -26
  72. data/test/exception_notifier/webhook_notifier_test.rb +52 -48
  73. data/test/exception_notifier_test.rb +150 -41
  74. data/test/support/exception_notifier_helper.rb +14 -0
  75. data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.html.erb +0 -0
  76. data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.text.erb +0 -0
  77. data/test/{dummy/app → support}/views/exception_notifier/_new_section.html.erb +0 -0
  78. data/test/{dummy/app → support}/views/exception_notifier/_new_section.text.erb +0 -0
  79. data/test/test_helper.rb +14 -13
  80. metadata +134 -175
  81. data/gemfiles/rails5_1.gemfile +0 -7
  82. data/lib/exception_notifier/campfire_notifier.rb +0 -40
  83. data/test/dummy/.gitignore +0 -4
  84. data/test/dummy/Rakefile +0 -7
  85. data/test/dummy/app/controllers/application_controller.rb +0 -3
  86. data/test/dummy/app/controllers/posts_controller.rb +0 -30
  87. data/test/dummy/app/helpers/application_helper.rb +0 -2
  88. data/test/dummy/app/helpers/posts_helper.rb +0 -2
  89. data/test/dummy/app/models/post.rb +0 -2
  90. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  91. data/test/dummy/app/views/posts/_form.html.erb +0 -0
  92. data/test/dummy/app/views/posts/new.html.erb +0 -0
  93. data/test/dummy/app/views/posts/show.html.erb +0 -0
  94. data/test/dummy/config/application.rb +0 -42
  95. data/test/dummy/config/boot.rb +0 -6
  96. data/test/dummy/config/database.yml +0 -22
  97. data/test/dummy/config/environment.rb +0 -17
  98. data/test/dummy/config/environments/development.rb +0 -25
  99. data/test/dummy/config/environments/production.rb +0 -50
  100. data/test/dummy/config/environments/test.rb +0 -35
  101. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  102. data/test/dummy/config/initializers/inflections.rb +0 -10
  103. data/test/dummy/config/initializers/mime_types.rb +0 -5
  104. data/test/dummy/config/initializers/secret_token.rb +0 -8
  105. data/test/dummy/config/initializers/session_store.rb +0 -8
  106. data/test/dummy/config/locales/en.yml +0 -5
  107. data/test/dummy/config/routes.rb +0 -3
  108. data/test/dummy/config.ru +0 -4
  109. data/test/dummy/db/migrate/20110729022608_create_posts.rb +0 -15
  110. data/test/dummy/db/schema.rb +0 -24
  111. data/test/dummy/db/seeds.rb +0 -7
  112. data/test/dummy/lib/tasks/.gitkeep +0 -0
  113. data/test/dummy/public/404.html +0 -26
  114. data/test/dummy/public/422.html +0 -26
  115. data/test/dummy/public/500.html +0 -26
  116. data/test/dummy/public/favicon.ico +0 -0
  117. data/test/dummy/public/images/rails.png +0 -0
  118. data/test/dummy/public/index.html +0 -239
  119. data/test/dummy/public/javascripts/application.js +0 -2
  120. data/test/dummy/public/javascripts/controls.js +0 -965
  121. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  122. data/test/dummy/public/javascripts/effects.js +0 -1123
  123. data/test/dummy/public/javascripts/prototype.js +0 -6001
  124. data/test/dummy/public/javascripts/rails.js +0 -191
  125. data/test/dummy/public/robots.txt +0 -5
  126. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  127. data/test/dummy/public/stylesheets/scaffold.css +0 -56
  128. data/test/dummy/script/rails +0 -6
  129. data/test/dummy/test/functional/posts_controller_test.rb +0 -237
  130. data/test/dummy/test/test_helper.rb +0 -7
  131. data/test/exception_notifier/campfire_notifier_test.rb +0 -120
@@ -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,237 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PostsControllerTest < ActionController::TestCase
4
- setup do
5
- Time.stubs(:current).returns('Sat, 20 Apr 2013 20:58:55 UTC +00:00')
6
- @email_notifier = ExceptionNotifier.registered_exception_notifier(:email)
7
- begin
8
- post :create, method: :post, params: { secret: "secret" }
9
- rescue => e
10
- @exception = e
11
- @mail = @email_notifier.create_email(@exception, {:env => request.env, :data => {:message => 'My Custom Message'}})
12
- end
13
- end
14
-
15
- test "should have raised an exception" do
16
- refute_nil @exception
17
- end
18
-
19
- test "should have generated a notification email" do
20
- refute_nil @mail
21
- end
22
-
23
- test "mail should be plain text and UTF-8 enconded by default" do
24
- assert_equal @mail.content_type, "text/plain; charset=UTF-8"
25
- end
26
-
27
- test "mail should have a from address set" do
28
- assert_equal @mail.from, ["dummynotifier@example.com"]
29
- end
30
-
31
- test "mail should have a to address set" do
32
- assert_equal @mail.to, ["dummyexceptions@example.com"]
33
- end
34
-
35
- test "mail subject should have the proper prefix" do
36
- assert_includes @mail.subject, "[Dummy ERROR]"
37
- end
38
-
39
- test "mail subject should include descriptive error message" do
40
- assert_includes @mail.subject, "(NoMethodError) \"undefined method `nw'"
41
- end
42
-
43
- test "mail should contain backtrace in body" do
44
- assert_includes @mail.encoded, "`method_missing'\r\n app/controllers/posts_controller.rb:18:in `create'\r\n"
45
- end
46
-
47
- test "mail should contain timestamp of exception in body" do
48
- assert_includes @mail.encoded, "Timestamp : #{Time.current}"
49
- end
50
-
51
- test "mail should contain the newly defined section" do
52
- assert_includes @mail.encoded, "* New text section for testing"
53
- end
54
-
55
- test "mail should contain the custom message" do
56
- assert_includes @mail.encoded, "My Custom Message"
57
- end
58
-
59
- test "should filter sensible data" do
60
- assert_includes @mail.encoded, "secret\"=>\"[FILTERED]"
61
- end
62
-
63
- test "mail should contain the custom header" do
64
- assert_includes @mail.encoded, 'X-Custom-Header: foobar'
65
- end
66
-
67
- test "mail should not contain any attachments" do
68
- assert_equal @mail.attachments, []
69
- end
70
-
71
- test "should not send notification if one of ignored exceptions" do
72
- begin
73
- get :invalid
74
- rescue => e
75
- @ignored_exception = e
76
- unless ExceptionNotifier.ignored_exceptions.include?(@ignored_exception.class.name)
77
- ignored_mail = @email_notifier.create_email(@ignored_exception, {:env => request.env})
78
- end
79
- end
80
-
81
- assert_equal @ignored_exception.class.inspect, "ActionController::UrlGenerationError"
82
- assert_nil ignored_mail
83
- end
84
-
85
- test "should filter session_id on secure requests" do
86
- request.env['HTTPS'] = 'on'
87
- begin
88
- post :create, method: :post
89
- rescue => e
90
- @secured_mail = @email_notifier.create_email(e, {:env => request.env})
91
- end
92
-
93
- assert request.ssl?
94
- assert_includes @secured_mail.encoded, "* session id: [FILTERED]\r\n *"
95
- end
96
-
97
- test "should ignore exception if from unwanted crawler" do
98
- request.env['HTTP_USER_AGENT'] = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
99
- begin
100
- post :create, method: :post
101
- rescue => e
102
- @exception = e
103
- custom_env = request.env
104
- custom_env['exception_notifier.options'] ||= {}
105
- custom_env['exception_notifier.options'].merge!(:ignore_crawlers => %w(Googlebot))
106
- ignore_array = custom_env['exception_notifier.options'][:ignore_crawlers]
107
- unless ExceptionNotification::Rack.new(Dummy::Application, custom_env['exception_notifier.options']).send(:from_crawler, custom_env, ignore_array)
108
- ignored_mail = @email_notifier.create_email(@exception, {:env => custom_env})
109
- end
110
- end
111
-
112
- assert_nil ignored_mail
113
- end
114
-
115
- test "should send html email when selected html format" do
116
- begin
117
- post :create, method: :post
118
- rescue => e
119
- @exception = e
120
- custom_env = request.env
121
- custom_env['exception_notifier.options'] ||= {}
122
- custom_env['exception_notifier.options'].merge!({:email_format => :html})
123
- @mail = @email_notifier.create_email(@exception, {:env => custom_env})
124
- end
125
-
126
- assert_includes @mail.content_type, "multipart/alternative"
127
- end
128
- end
129
-
130
- class PostsControllerTestWithoutVerboseSubject < ActionController::TestCase
131
- tests PostsController
132
- setup do
133
- @email_notifier = ExceptionNotifier::EmailNotifier.new(:verbose_subject => false)
134
- begin
135
- post :create, method: :post
136
- rescue => e
137
- @exception = e
138
- @mail = @email_notifier.create_email(@exception, {:env => request.env})
139
- end
140
- end
141
-
142
- test "should not include exception message in subject" do
143
- assert_includes @mail.subject, '[ERROR]'
144
- assert_includes @mail.subject, '(NoMethodError)'
145
- refute_includes @mail.subject, 'undefined method'
146
- end
147
- end
148
-
149
- class PostsControllerTestWithoutControllerAndActionNames < ActionController::TestCase
150
- tests PostsController
151
- setup do
152
- @email_notifier = ExceptionNotifier::EmailNotifier.new(:include_controller_and_action_names_in_subject => false)
153
- begin
154
- post :create, method: :post
155
- rescue => e
156
- @exception = e
157
- @mail = @email_notifier.create_email(@exception, {:env => request.env})
158
- end
159
- end
160
-
161
- test "should include controller and action names in subject" do
162
- assert_includes @mail.subject, '[ERROR]'
163
- assert_includes @mail.subject, '(NoMethodError)'
164
- refute_includes @mail.subject, 'posts#create'
165
- end
166
- end
167
-
168
- class PostsControllerTestWithSmtpSettings < ActionController::TestCase
169
- tests PostsController
170
- setup do
171
- @email_notifier = ExceptionNotifier::EmailNotifier.new(:smtp_settings => {
172
- :user_name => "Dummy user_name",
173
- :password => "Dummy password"
174
- })
175
-
176
- begin
177
- post :create, method: :post
178
- rescue => e
179
- @exception = e
180
- @mail = @email_notifier.create_email(@exception, {:env => request.env})
181
- end
182
- end
183
-
184
- test "should have overridden smtp settings" do
185
- assert_equal "Dummy user_name", @mail.delivery_method.settings[:user_name]
186
- assert_equal "Dummy password", @mail.delivery_method.settings[:password]
187
- end
188
-
189
- test "should have overridden smtp settings with background notification" do
190
- @mail = @email_notifier.create_email(@exception)
191
- assert_equal "Dummy user_name", @mail.delivery_method.settings[:user_name]
192
- assert_equal "Dummy password", @mail.delivery_method.settings[:password]
193
- end
194
- end
195
-
196
- class PostsControllerTestBackgroundNotification < ActionController::TestCase
197
- tests PostsController
198
- setup do
199
- @email_notifier = ExceptionNotifier.registered_exception_notifier(:email)
200
- begin
201
- post :create, method: :post
202
- rescue => exception
203
- @mail = @email_notifier.create_email(exception)
204
- end
205
- end
206
-
207
- test "mail should contain the specified section" do
208
- assert_includes @mail.encoded, "* New background section for testing"
209
- end
210
- end
211
-
212
- class PostsControllerTestWithExceptionRecipientsAsProc < ActionController::TestCase
213
- tests PostsController
214
- setup do
215
- exception_recipients = %w{first@example.com second@example.com}
216
-
217
- @email_notifier = ExceptionNotifier::EmailNotifier.new(
218
- exception_recipients: -> { [ exception_recipients.shift ] }
219
- )
220
-
221
- @action = proc do
222
- begin
223
- post :create, method: :post
224
- rescue => e
225
- @exception = e
226
- @mail = @email_notifier.create_email(@exception, {:env => request.env})
227
- end
228
- end
229
- end
230
-
231
- test "should lazily evaluate exception_recipients" do
232
- @action.call
233
- assert_equal [ "first@example.com" ], @mail.to
234
- @action.call
235
- assert_equal [ "second@example.com" ], @mail.to
236
- end
237
- end
@@ -1,7 +0,0 @@
1
- ENV["RAILS_ENV"] = "test"
2
- require File.expand_path('../../config/environment', __FILE__)
3
- require 'rails/test_help'
4
-
5
- class ActiveSupport::TestCase
6
- # Add more helper methods to be used by all tests here...
7
- end
@@ -1,120 +0,0 @@
1
- require 'test_helper'
2
-
3
- # silence_warnings trick around require can be removed once
4
- # https://github.com/collectiveidea/tinder/pull/77
5
- # gets merged and released
6
- silence_warnings do
7
- require 'tinder'
8
- end
9
-
10
- class CampfireNotifierTest < ActiveSupport::TestCase
11
-
12
- test "should send campfire notification if properly configured" do
13
- ExceptionNotifier::CampfireNotifier.stubs(:new).returns(Object.new)
14
- campfire = ExceptionNotifier::CampfireNotifier.new({:subdomain => 'test', :token => 'test_token', :room_name => 'test_room'})
15
- campfire.stubs(:call).returns(fake_notification)
16
- notif = campfire.call(fake_exception)
17
-
18
- assert !notif[:message].empty?
19
- assert_equal notif[:message][:type], 'PasteMessage'
20
- assert_includes notif[:message][:body], "A new exception occurred:"
21
- assert_includes notif[:message][:body], "divided by 0"
22
- assert_includes notif[:message][:body], "/exception_notification/test/campfire_test.rb:45"
23
- end
24
-
25
- test "should send campfire notification without backtrace info if properly configured" do
26
- ExceptionNotifier::CampfireNotifier.stubs(:new).returns(Object.new)
27
- campfire = ExceptionNotifier::CampfireNotifier.new({:subdomain => 'test', :token => 'test_token', :room_name => 'test_room'})
28
- campfire.stubs(:call).returns(fake_notification_without_backtrace)
29
- notif = campfire.call(fake_exception_without_backtrace)
30
-
31
- assert !notif[:message].empty?
32
- assert_equal notif[:message][:type], 'PasteMessage'
33
- assert_includes notif[:message][:body], "A new exception occurred:"
34
- assert_includes notif[:message][:body], "my custom error"
35
- end
36
-
37
- test "should not send campfire notification if badly configured" do
38
- wrong_params = {:subdomain => 'test', :token => 'bad_token', :room_name => 'test_room'}
39
- Tinder::Campfire.stubs(:new).with('test', {:token => 'bad_token'}).returns(nil)
40
- campfire = ExceptionNotifier::CampfireNotifier.new(wrong_params)
41
-
42
- assert_nil campfire.room
43
- assert_nil campfire.call(fake_exception)
44
- end
45
-
46
- test "should not send campfire notification if config attr missing" do
47
- wrong_params = {:subdomain => 'test', :room_name => 'test_room'}
48
- Tinder::Campfire.stubs(:new).with('test', {}).returns(nil)
49
- campfire = ExceptionNotifier::CampfireNotifier.new(wrong_params)
50
-
51
- assert_nil campfire.room
52
- assert_nil campfire.call(fake_exception)
53
- end
54
-
55
- test "should send the new exception message if no :accumulated_errors_count option" do
56
- campfire = ExceptionNotifier::CampfireNotifier.new({})
57
- campfire.stubs(:active?).returns(true)
58
- campfire.expects(:send_notice).with{ |_, _, message| message.start_with?("A new exception occurred") }.once
59
- campfire.call(fake_exception)
60
- end
61
-
62
- test "shoud send the exception message if :accumulated_errors_count option greater than 1" do
63
- campfire = ExceptionNotifier::CampfireNotifier.new({})
64
- campfire.stubs(:active?).returns(true)
65
- campfire.expects(:send_notice).with{ |_, _, message| message.start_with?("The exception occurred 3 times:") }.once
66
- campfire.call(fake_exception, accumulated_errors_count: 3)
67
- end
68
-
69
- test "should call pre/post_callback if specified" do
70
- pre_callback_called, post_callback_called = 0,0
71
- Tinder::Campfire.stubs(:new).returns(Object.new)
72
-
73
- campfire = ExceptionNotifier::CampfireNotifier.new(
74
- {
75
- :subdomain => 'test',
76
- :token => 'test_token',
77
- :room_name => 'test_room',
78
- :pre_callback => proc { |opts, notifier, backtrace, message, message_opts|
79
- pre_callback_called += 1
80
- },
81
- :post_callback => proc { |opts, notifier, backtrace, message, message_opts|
82
- post_callback_called += 1
83
- }
84
- }
85
- )
86
- campfire.room = Object.new
87
- campfire.room.stubs(:paste).returns(fake_notification)
88
- campfire.call(fake_exception)
89
- assert_equal(1, pre_callback_called)
90
- assert_equal(1, post_callback_called)
91
- end
92
-
93
- private
94
-
95
- def fake_notification
96
- {:message => {:type => 'PasteMessage',
97
- :body => "A new exception occurred: 'divided by 0' on '/Users/sebastian/exception_notification/test/campfire_test.rb:45:in `/'"
98
- }
99
- }
100
- end
101
-
102
- def fake_exception
103
- begin
104
- 5/0
105
- rescue Exception => e
106
- e
107
- end
108
- end
109
-
110
- def fake_notification_without_backtrace
111
- {:message => {:type => 'PasteMessage',
112
- :body => "A new exception occurred: 'my custom error'"
113
- }
114
- }
115
- end
116
-
117
- def fake_exception_without_backtrace
118
- StandardError.new('my custom error')
119
- end
120
- end