exception_notification 4.4.3 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae2c9d720954788440b1deedc356091324eb5c393801790d6f861c4fe157bdb4
4
- data.tar.gz: 31e91bdeeda86d168e887fa235e31b9810feb37c91317d564eee46c425376011
3
+ metadata.gz: f671fa31cec6dbf437c5e31ab10136a00f3ef5450fc13d9de2887296390451ba
4
+ data.tar.gz: 20f146f16e31e91c456cb08f5598b2714dec47ef1efc41741c7cfea761a8176f
5
5
  SHA512:
6
- metadata.gz: cbd31aedd92e7fc5064cad2efde830070aa41f2289f3e08f57c63d001046cad20187dd6948c4fd96e6489d3d513ee1d6b32069206cbc3562a82bb17f4b92e314
7
- data.tar.gz: fda70cf9f41a3a57bb83e47bfebbd1c181de0400faa72807474e76b6f2ec69f07ce37ea1ee1a5429e9dfb1b65006a6255765c0bd0677ff53cbf42cd274b5c254
6
+ metadata.gz: a3c4f84bef2faccc2a66306349b983843a1542895d13e8cb141e50e8c610dc525087f8f86fc4c40654140e128c5378b224851c888086b0b32a6cb4753011717e
7
+ data.tar.gz: 5aa30cabeb47f39f89d13c904bdd36da33bf7a598cdb24f14ff6882e90826e3985b1bfb19c55a250bdfc3edae343ec56a72887a5bdbd195bbe4251738a65d1b2
data/Appraisals CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- rails_versions = ['~> 4.0.5', '~> 4.1.1', '~> 4.2.0', '~> 5.0.0', '~> 5.1.0', '~> 5.2.0', '~> 6.0.0']
3
+ rails_versions = ['~> 5.2.0', '~> 6.0.0', '~> 6.1.0', '~> 7.0.0']
4
4
 
5
5
  rails_versions.each do |rails_version|
6
6
  appraise "rails#{rails_version.slice(/\d+\.\d+/).tr('.', '_')}" do
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,16 @@
1
+ == 4.5.0
2
+
3
+ * enhancements
4
+ * Added Rails 7 compatibility (by @fwininger)
5
+ * Added support for the optional `data` attribute to the SNS notifier (@TomK32)
6
+ * Addressed a deprecation warning for `module_parent_name` which was thrown for users
7
+ using Rails > 6.x (@quorak)
8
+ * Restored the hash separator for `controller#action` in the email notifier (@garethrees)
9
+
10
+ * removals
11
+ * Dropped support for Tinder (gem is no longer maintained) (by @fwininger)
12
+ * Dropped support for Ruby on Rails versions below 5.2
13
+
1
14
  == 4.4.3
2
15
 
3
16
  * big fixes
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Exception Notification
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/exception_notification.svg)](https://badge.fury.io/rb/exception_notification)
4
- [![Build Status](https://travis-ci.org/smartinez87/exception_notification.svg?branch=master)](https://travis-ci.org/smartinez87/exception_notification)
4
+ [![Build Status](https://github.com/smartinez87/exception_notification/actions/workflows/main.yml/badge.svg)](https://github.com/smartinez87/exception_notification/actions/workflows/main.yml)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/smartinez87/exception_notification/badge.svg?branch=master)](https://coveralls.io/github/smartinez87/exception_notification?branch=master)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/78a9a12be00a6d305136/maintainability)](https://codeclimate.com/github/smartinez87/exception_notification/maintainability)
7
7
 
@@ -9,7 +9,7 @@
9
9
 
10
10
  ---
11
11
 
12
- The Exception Notification gem provides a set of [notifiers](#notifiers) for sending notifications when errors occur in a Rack/Rails application. The built-in notifiers can deliver notifications by [email](docs/notifiers/email.md), [Campfire](docs/notifiers/campfire.md), [HipChat](docs/notifiers/hipchat.md), [Slack](docs/notifiers/slack.md), [Mattermost](docs/notifiers/mattermost.md), [Teams](docs/notifiers/teams.md), [IRC](docs/notifiers/irc.md), [Amazon SNS](docs/notifiers/sns.md), [Google Chat](docs/notifiers/google_chat.md), [Datadog](docs/notifiers/datadog.md) or via custom [WebHooks](docs/notifiers/webhook.md).
12
+ The Exception Notification gem provides a set of [notifiers](#notifiers) for sending notifications when errors occur in a Rack/Rails application. The built-in notifiers can deliver notifications by [email](docs/notifiers/email.md), [HipChat](docs/notifiers/hipchat.md), [Slack](docs/notifiers/slack.md), [Mattermost](docs/notifiers/mattermost.md), [Teams](docs/notifiers/teams.md), [IRC](docs/notifiers/irc.md), [Amazon SNS](docs/notifiers/sns.md), [Google Chat](docs/notifiers/google_chat.md), [Datadog](docs/notifiers/datadog.md) or via custom [WebHooks](docs/notifiers/webhook.md).
13
13
 
14
14
  There's a great [Railscast about Exception Notification](http://railscasts.com/episodes/104-exception-notifications-revised) you can see that may help you getting started.
15
15
 
@@ -17,8 +17,8 @@ There's a great [Railscast about Exception Notification](http://railscasts.com/e
17
17
 
18
18
  ## Requirements
19
19
 
20
- * Ruby 2.3 or greater
21
- * Rails 4.0 or greater, Sinatra or another Rack-based application.
20
+ * Ruby 2.5 or greater
21
+ * Rails 5.2 or greater, Sinatra or another Rack-based application.
22
22
 
23
23
  ## Getting Started
24
24
 
@@ -35,7 +35,6 @@ ExceptionNotification is used as a rack middleware, or in the environment you wa
35
35
  ```ruby
36
36
  Rails.application.config.middleware.use ExceptionNotification::Rack,
37
37
  email: {
38
- deliver_with: :deliver, # Rails >= 4.2.1 do not need this option since it defaults to :deliver_now
39
38
  email_prefix: '[PREFIX] ',
40
39
  sender_address: %{"notifier" <notifier@example.com>},
41
40
  exception_recipients: %w{exceptions@example.com}
@@ -84,7 +83,6 @@ Options -> sections" below.
84
83
 
85
84
  ExceptionNotification relies on notifiers to deliver notifications when errors occur in your applications. By default, 8 notifiers are available:
86
85
 
87
- * [Campfire notifier](docs/notifiers/campfire.md)
88
86
  * [Datadog notifier](docs/notifiers/datadog.md)
89
87
  * [Email notifier](docs/notifiers/email.md)
90
88
  * [HipChat notifier](docs/notifiers/hipchat.md)
@@ -271,7 +269,6 @@ def server_error(exception)
271
269
  end
272
270
  ```
273
271
 
274
-
275
272
  ## Extras
276
273
 
277
274
  ### Rails
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = 'exception_notification'
7
7
  s.version = ExceptionNotification::VERSION
8
8
  s.authors = ['Jamis Buck', 'Josh Peek']
9
- s.date = '2020-06-29'
9
+ s.date = '2022-01-20'
10
10
  s.summary = 'Exception notification for Rails apps'
11
11
  s.homepage = 'https://smartinez87.github.io/exception_notification/'
12
12
  s.email = 'smartinez87@gmail.com'
@@ -20,8 +20,8 @@ Gem::Specification.new do |s|
20
20
  s.test_files = `git ls-files -- test`.split("\n")
21
21
  s.require_path = 'lib'
22
22
 
23
- s.add_dependency('actionmailer', '>= 4.0', '< 7')
24
- s.add_dependency('activesupport', '>= 4.0', '< 7')
23
+ s.add_dependency('actionmailer', '>= 5.2', '< 8')
24
+ s.add_dependency('activesupport', '>= 5.2', '< 8')
25
25
 
26
26
  s.add_development_dependency 'appraisal', '~> 2.2.0'
27
27
  s.add_development_dependency 'aws-sdk-sns', '~> 1'
@@ -32,11 +32,11 @@ Gem::Specification.new do |s|
32
32
  s.add_development_dependency 'httparty', '~> 0.10.2'
33
33
  s.add_development_dependency 'mocha', '>= 0.13.0'
34
34
  s.add_development_dependency 'mock_redis', '~> 0.19.0'
35
- s.add_development_dependency 'rails', '>= 4.0', '< 7'
35
+ s.add_development_dependency 'net-smtp'
36
+ s.add_development_dependency 'rails', '>= 5.2', '< 8'
36
37
  s.add_development_dependency 'resque', '~> 1.8.0'
37
38
  s.add_development_dependency 'rubocop', '0.78.0'
38
39
  s.add_development_dependency 'sidekiq', '>= 5.0.4'
39
40
  s.add_development_dependency 'slack-notifier', '>= 1.0.0'
40
41
  s.add_development_dependency 'timecop', '~> 0.9.0'
41
- s.add_development_dependency 'tinder', '~> 1.8'
42
42
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.0.5"
5
+ gem "rails", "~> 6.1.0"
6
6
 
7
7
  gemspec path: "../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.1.1"
5
+ gem "rails", "~> 7.0.0"
6
6
 
7
7
  gemspec path: "../"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ExceptionNotification
4
- VERSION = '4.4.3'
4
+ VERSION = '4.5.0'
5
5
  end
@@ -76,7 +76,7 @@ module ExceptionNotifier
76
76
  def compose_subject
77
77
  subject = @options[:email_prefix].to_s.dup
78
78
  subject << "(#{@options[:accumulated_errors_count]} times)" if @options[:accumulated_errors_count].to_i > 1
79
- subject << "#{@kontroller.controller_name} #{@kontroller.action_name}" if include_controller?
79
+ subject << "#{@kontroller.controller_name}##{@kontroller.action_name}" if include_controller?
80
80
  subject << " (#{@exception.class})"
81
81
  subject << " #{@exception.message.inspect}" if @options[:verbose_subject]
82
82
  subject = EmailNotifier.normalize_digits(subject) if @options[:normalize_subject]
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support'
3
4
  require 'active_support/core_ext/numeric/time'
4
5
  require 'active_support/concern'
5
6
 
@@ -111,7 +111,11 @@ module ExceptionNotifier
111
111
  def rails_app_name
112
112
  return unless defined?(::Rails) && ::Rails.respond_to?(:application)
113
113
 
114
- Rails.application.class.parent_name.underscore
114
+ if Rails::VERSION::MAJOR >= 6
115
+ Rails.application.class.module_parent_name.underscore
116
+ else
117
+ Rails.application.class.parent_name.underscore
118
+ end
115
119
  end
116
120
 
117
121
  def controller
@@ -45,10 +45,12 @@ module ExceptionNotifier
45
45
 
46
46
  if options[:env].nil?
47
47
  text = "#{exception_name} occured in background\n"
48
+ data = options[:data] || {}
48
49
  else
49
50
  env = options[:env]
50
51
 
51
52
  kontroller = env['action_controller.instance']
53
+ data = (env['exception_notifier.exception_data'] || {}).merge(options[:data] || {})
52
54
  request = "#{env['REQUEST_METHOD']} <#{env['REQUEST_URI']}>"
53
55
 
54
56
  text = "#{exception_name} occurred while #{request}"
@@ -57,6 +59,7 @@ module ExceptionNotifier
57
59
 
58
60
  text += "Exception: #{exception.message}\n"
59
61
  text += "Hostname: #{Socket.gethostname}\n"
62
+ text += "Data: #{data}\n"
60
63
 
61
64
  return unless exception.backtrace
62
65
 
@@ -14,7 +14,6 @@ module ExceptionNotifier
14
14
 
15
15
  autoload :Notifier, 'exception_notifier/notifier'
16
16
  autoload :EmailNotifier, 'exception_notifier/email_notifier'
17
- autoload :CampfireNotifier, 'exception_notifier/campfire_notifier'
18
17
  autoload :HipchatNotifier, 'exception_notifier/hipchat_notifier'
19
18
  autoload :WebhookNotifier, 'exception_notifier/webhook_notifier'
20
19
  autoload :IrcNotifier, 'exception_notifier/irc_notifier'
@@ -239,6 +239,7 @@ class EmailNotifierWithEnvTest < ActiveSupport::TestCase
239
239
  'action_dispatch.parameter_filter' => ['secret'],
240
240
  'HTTPS' => 'on',
241
241
  'action_controller.instance' => @controller,
242
+ 'rack.session.options' => {},
242
243
  params: { id: 'foo', secret: 'secret' }
243
244
  )
244
245
 
@@ -248,7 +249,7 @@ class EmailNotifierWithEnvTest < ActiveSupport::TestCase
248
249
  test 'sends mail with correct content' do
249
250
  assert_equal %("Dummy Notifier" <dummynotifier@example.com>), @mail[:from].value
250
251
  assert_equal %w[dummyexceptions@example.com], @mail.to
251
- assert_equal '[Dummy ERROR] home index (ZeroDivisionError) "divided by 0"', @mail.subject
252
+ assert_equal '[Dummy ERROR] home#index (ZeroDivisionError) "divided by 0"', @mail.subject
252
253
  assert_equal 'foobar', @mail['X-Custom-Header'].value
253
254
  assert_equal 'text/plain; charset=UTF-8', @mail.content_type
254
255
  assert_equal [], @mail.attachments
@@ -319,7 +320,8 @@ class EmailNotifierWithEnvTest < ActiveSupport::TestCase
319
320
  * rack.request.query_hash : {"id"=>"foo", "secret"=>"[FILTERED]"}
320
321
  * rack.request.query_string : id=foo&secret=secret
321
322
  * rack.run_once : false
322
- * rack.session : {}
323
+ * rack.session : #{@test_env['rack.session']}
324
+ * rack.session.options : #{@test_env['rack.session.options']}
323
325
  * rack.url_scheme : http
324
326
  * rack.version : #{Rack::VERSION}
325
327
 
@@ -66,6 +66,7 @@ class SnsNotifierTest < ActiveSupport::TestCase
66
66
  message: "3 MyException occured in background\n" \
67
67
  "Exception: undefined method 'method=' for Empty\n" \
68
68
  "Hostname: example.com\n" \
69
+ "Data: {}\n" \
69
70
  "Backtrace:\n#{fake_backtrace.join("\n")}\n",
70
71
  subject: '[App Exception] - 3 MyException occurred'
71
72
  )
@@ -85,6 +86,7 @@ class SnsNotifierTest < ActiveSupport::TestCase
85
86
  "was processed by examples#index\n" \
86
87
  "Exception: undefined method 'method=' for Empty\n" \
87
88
  "Hostname: example.com\n" \
89
+ "Data: {}\n" \
88
90
  "Backtrace:\n#{fake_backtrace.join("\n")}\n",
89
91
  subject: '[App Exception] - A MyException occurred'
90
92
  )
@@ -98,6 +100,59 @@ class SnsNotifierTest < ActiveSupport::TestCase
98
100
  })
99
101
  end
100
102
 
103
+ test 'should put data from env["exception_notifier.exception_data"] into text' do
104
+ controller = mock('controller')
105
+ controller.stubs(:action_name).returns('index')
106
+ controller.stubs(:controller_name).returns('examples')
107
+
108
+ Aws::SNS::Client.any_instance.expects(:publish).with(
109
+ topic_arn: 'topicARN',
110
+ message: 'A MyException occurred while GET </examples> ' \
111
+ "was processed by examples#index\n" \
112
+ "Exception: undefined method 'method=' for Empty\n" \
113
+ "Hostname: example.com\n" \
114
+ "Data: {:current_user=>12}\n" \
115
+ "Backtrace:\n#{fake_backtrace.join("\n")}\n",
116
+ subject: '[App Exception] - A MyException occurred'
117
+ )
118
+
119
+ sns_notifier = ExceptionNotifier::SnsNotifier.new(@options)
120
+ sns_notifier.call(@exception,
121
+ env: {
122
+ 'REQUEST_METHOD' => 'GET',
123
+ 'REQUEST_URI' => '/examples',
124
+ 'action_controller.instance' => controller,
125
+ 'exception_notifier.exception_data' => { current_user: 12 }
126
+ })
127
+ end
128
+ test 'should put optional data into text' do
129
+ controller = mock('controller')
130
+ controller.stubs(:action_name).returns('index')
131
+ controller.stubs(:controller_name).returns('examples')
132
+
133
+ Aws::SNS::Client.any_instance.expects(:publish).with(
134
+ topic_arn: 'topicARN',
135
+ message: 'A MyException occurred while GET </examples> ' \
136
+ "was processed by examples#index\n" \
137
+ "Exception: undefined method 'method=' for Empty\n" \
138
+ "Hostname: example.com\n" \
139
+ "Data: {:current_user=>12}\n" \
140
+ "Backtrace:\n#{fake_backtrace.join("\n")}\n",
141
+ subject: '[App Exception] - A MyException occurred'
142
+ )
143
+
144
+ sns_notifier = ExceptionNotifier::SnsNotifier.new(@options)
145
+ sns_notifier.call(@exception,
146
+ env: {
147
+ 'REQUEST_METHOD' => 'GET',
148
+ 'REQUEST_URI' => '/examples',
149
+ 'action_controller.instance' => controller
150
+ },
151
+ data: {
152
+ current_user: 12
153
+ })
154
+ end
155
+
101
156
  private
102
157
 
103
158
  def fake_exception
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.3
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamis Buck
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-29 00:00:00.000000000 Z
12
+ date: 2022-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionmailer
@@ -17,40 +17,40 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '4.0'
20
+ version: '5.2'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '7'
23
+ version: '8'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: '4.0'
30
+ version: '5.2'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '7'
33
+ version: '8'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: activesupport
36
36
  requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '4.0'
40
+ version: '5.2'
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: '7'
43
+ version: '8'
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: '4.0'
50
+ version: '5.2'
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: '7'
53
+ version: '8'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: appraisal
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -177,26 +177,40 @@ dependencies:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
179
  version: 0.19.0
180
+ - !ruby/object:Gem::Dependency
181
+ name: net-smtp
182
+ requirement: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ type: :development
188
+ prerelease: false
189
+ version_requirements: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
180
194
  - !ruby/object:Gem::Dependency
181
195
  name: rails
182
196
  requirement: !ruby/object:Gem::Requirement
183
197
  requirements:
184
198
  - - ">="
185
199
  - !ruby/object:Gem::Version
186
- version: '4.0'
200
+ version: '5.2'
187
201
  - - "<"
188
202
  - !ruby/object:Gem::Version
189
- version: '7'
203
+ version: '8'
190
204
  type: :development
191
205
  prerelease: false
192
206
  version_requirements: !ruby/object:Gem::Requirement
193
207
  requirements:
194
208
  - - ">="
195
209
  - !ruby/object:Gem::Version
196
- version: '4.0'
210
+ version: '5.2'
197
211
  - - "<"
198
212
  - !ruby/object:Gem::Version
199
- version: '7'
213
+ version: '8'
200
214
  - !ruby/object:Gem::Dependency
201
215
  name: resque
202
216
  requirement: !ruby/object:Gem::Requirement
@@ -267,20 +281,6 @@ dependencies:
267
281
  - - "~>"
268
282
  - !ruby/object:Gem::Version
269
283
  version: 0.9.0
270
- - !ruby/object:Gem::Dependency
271
- name: tinder
272
- requirement: !ruby/object:Gem::Requirement
273
- requirements:
274
- - - "~>"
275
- - !ruby/object:Gem::Version
276
- version: '1.8'
277
- type: :development
278
- prerelease: false
279
- version_requirements: !ruby/object:Gem::Requirement
280
- requirements:
281
- - - "~>"
282
- - !ruby/object:Gem::Version
283
- version: '1.8'
284
284
  description:
285
285
  email: smartinez87@gmail.com
286
286
  executables: []
@@ -315,13 +315,10 @@ files:
315
315
  - examples/sinatra/config.ru
316
316
  - examples/sinatra/sinatra_app.rb
317
317
  - exception_notification.gemspec
318
- - gemfiles/rails4_0.gemfile
319
- - gemfiles/rails4_1.gemfile
320
- - gemfiles/rails4_2.gemfile
321
- - gemfiles/rails5_0.gemfile
322
- - gemfiles/rails5_1.gemfile
323
318
  - gemfiles/rails5_2.gemfile
324
319
  - gemfiles/rails6_0.gemfile
320
+ - gemfiles/rails6_1.gemfile
321
+ - gemfiles/rails7_0.gemfile
325
322
  - lib/exception_notification.rb
326
323
  - lib/exception_notification/rack.rb
327
324
  - lib/exception_notification/rails.rb
@@ -330,7 +327,6 @@ files:
330
327
  - lib/exception_notification/version.rb
331
328
  - lib/exception_notifier.rb
332
329
  - lib/exception_notifier/base_notifier.rb
333
- - lib/exception_notifier/campfire_notifier.rb
334
330
  - lib/exception_notifier/datadog_notifier.rb
335
331
  - lib/exception_notifier/email_notifier.rb
336
332
  - lib/exception_notifier/google_chat_notifier.rb
@@ -365,7 +361,6 @@ files:
365
361
  - lib/generators/exception_notification/templates/exception_notification.rb.erb
366
362
  - test/exception_notification/rack_test.rb
367
363
  - test/exception_notification/resque_test.rb
368
- - test/exception_notifier/campfire_notifier_test.rb
369
364
  - test/exception_notifier/datadog_notifier_test.rb
370
365
  - test/exception_notifier/email_notifier_test.rb
371
366
  - test/exception_notifier/google_chat_notifier_test.rb
@@ -405,14 +400,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
405
400
  - !ruby/object:Gem::Version
406
401
  version: 1.8.11
407
402
  requirements: []
408
- rubygems_version: 3.1.2
403
+ rubygems_version: 3.2.32
409
404
  signing_key:
410
405
  specification_version: 4
411
406
  summary: Exception notification for Rails apps
412
407
  test_files:
413
408
  - test/exception_notification/rack_test.rb
414
409
  - test/exception_notification/resque_test.rb
415
- - test/exception_notifier/campfire_notifier_test.rb
416
410
  - test/exception_notifier/datadog_notifier_test.rb
417
411
  - test/exception_notifier/email_notifier_test.rb
418
412
  - test/exception_notifier/google_chat_notifier_test.rb
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 4.2.0"
6
-
7
- gemspec path: "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.0.0"
6
-
7
- gemspec path: "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.1.0"
6
-
7
- gemspec path: "../"
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ExceptionNotifier
4
- class CampfireNotifier < BaseNotifier
5
- attr_accessor :subdomain
6
- attr_accessor :token
7
- attr_accessor :room
8
-
9
- def initialize(options)
10
- super
11
- begin
12
- subdomain = options.delete(:subdomain)
13
- room_name = options.delete(:room_name)
14
- @campfire = Tinder::Campfire.new subdomain, options
15
- @room = @campfire.find_room_by_name room_name
16
- rescue StandardError
17
- @campfire = @room = nil
18
- end
19
- end
20
-
21
- def call(exception, options = {})
22
- return unless active?
23
-
24
- message = if options[:accumulated_errors_count].to_i > 1
25
- "The exception occurred #{options[:accumulated_errors_count]} times: '#{exception.message}'"
26
- else
27
- "A new exception occurred: '#{exception.message}'"
28
- end
29
- message += " on '#{exception.backtrace.first}'" if exception.backtrace
30
- send_notice(exception, options, message) do |msg, _|
31
- @room.paste msg
32
- end
33
- end
34
-
35
- private
36
-
37
- def active?
38
- !@room.nil?
39
- end
40
- end
41
- end
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- # silence_warnings trick around require can be removed once
6
- # https://github.com/collectiveidea/tinder/pull/77
7
- # gets merged and released
8
- silence_warnings do
9
- require 'tinder'
10
- end
11
-
12
- class CampfireNotifierTest < ActiveSupport::TestCase
13
- test 'should send campfire notification if properly configured' do
14
- ExceptionNotifier::CampfireNotifier.stubs(:new).returns(Object.new)
15
- campfire = ExceptionNotifier::CampfireNotifier.new(subdomain: 'test', token: 'test_token', room_name: 'test_room')
16
- campfire.stubs(:call).returns(fake_notification)
17
- notif = campfire.call(fake_exception)
18
-
19
- assert !notif[:message].empty?
20
- assert_equal notif[:message][:type], 'PasteMessage'
21
- assert_includes notif[:message][:body], 'A new exception occurred:'
22
- assert_includes notif[:message][:body], 'divided by 0'
23
- assert_includes notif[:message][:body], '/exception_notification/test/campfire_test.rb:45'
24
- end
25
-
26
- test 'should send campfire notification without backtrace info if properly configured' do
27
- ExceptionNotifier::CampfireNotifier.stubs(:new).returns(Object.new)
28
- campfire = ExceptionNotifier::CampfireNotifier.new(subdomain: 'test', token: 'test_token', room_name: 'test_room')
29
- campfire.stubs(:call).returns(fake_notification_without_backtrace)
30
- notif = campfire.call(fake_exception_without_backtrace)
31
-
32
- assert !notif[:message].empty?
33
- assert_equal notif[:message][:type], 'PasteMessage'
34
- assert_includes notif[:message][:body], 'A new exception occurred:'
35
- assert_includes notif[:message][:body], 'my custom error'
36
- end
37
-
38
- test 'should not send campfire notification if badly configured' do
39
- wrong_params = { subdomain: 'test', token: 'bad_token', room_name: 'test_room' }
40
- Tinder::Campfire.stubs(:new).with('test', token: 'bad_token').returns(nil)
41
- campfire = ExceptionNotifier::CampfireNotifier.new(wrong_params)
42
-
43
- assert_nil campfire.room
44
- assert_nil campfire.call(fake_exception)
45
- end
46
-
47
- test 'should not send campfire notification if config attr missing' do
48
- wrong_params = { subdomain: 'test', room_name: 'test_room' }
49
- Tinder::Campfire.stubs(:new).with('test', {}).returns(nil)
50
- campfire = ExceptionNotifier::CampfireNotifier.new(wrong_params)
51
-
52
- assert_nil campfire.room
53
- assert_nil campfire.call(fake_exception)
54
- end
55
-
56
- test 'should send the new exception message if no :accumulated_errors_count option' do
57
- campfire = ExceptionNotifier::CampfireNotifier.new({})
58
- campfire.stubs(:active?).returns(true)
59
- campfire.expects(:send_notice).with { |_, _, message| message.start_with?('A new exception occurred') }.once
60
- campfire.call(fake_exception)
61
- end
62
-
63
- test 'shoud send the exception message if :accumulated_errors_count option greater than 1' do
64
- campfire = ExceptionNotifier::CampfireNotifier.new({})
65
- campfire.stubs(:active?).returns(true)
66
- campfire.expects(:send_notice).with { |_, _, message| message.start_with?('The exception occurred 3 times:') }.once
67
- campfire.call(fake_exception, accumulated_errors_count: 3)
68
- end
69
-
70
- test 'should call pre/post_callback if specified' do
71
- pre_callback_called = 0
72
- post_callback_called = 0
73
- Tinder::Campfire.stubs(:new).returns(Object.new)
74
-
75
- campfire = ExceptionNotifier::CampfireNotifier.new(
76
- subdomain: 'test',
77
- token: 'test_token',
78
- room_name: 'test_room',
79
- pre_callback: proc { |_opts, _notifier, _backtrace, _message, _message_opts|
80
- pre_callback_called += 1
81
- },
82
- post_callback: proc { |_opts, _notifier, _backtrace, _message, _message_opts|
83
- post_callback_called += 1
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
- {
97
- message: {
98
- type: 'PasteMessage',
99
- body: fake_notification_body
100
- }
101
- }
102
- end
103
-
104
- def fake_notification_body
105
- "A new exception occurred: 'divided by 0' on " \
106
- "/Users/sebastian/exception_notification/test/campfire_test.rb:45:in `/'"
107
- end
108
-
109
- def fake_exception
110
- 5 / 0
111
- rescue StandardError => e
112
- e
113
- end
114
-
115
- def fake_notification_without_backtrace
116
- {
117
- message: {
118
- type: 'PasteMessage',
119
- body: "A new exception occurred: 'my custom error'"
120
- }
121
- }
122
- end
123
-
124
- def fake_exception_without_backtrace
125
- StandardError.new('my custom error')
126
- end
127
- end