hoptoad_notifier 2.4.2 → 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,19 @@
1
+ Version 2.4.4 - Fri Jan 28 13:50:10 -0500 2011
2
+ ===============================================================================
3
+
4
+ Matt Jankowski (1):
5
+ Change the javascript notifier from a config option to a helper method
6
+
7
+ Jonathan Yurek (1):
8
+ Show the javascript notifier prevents XSS attempts from request.url
9
+
10
+ Version 2.4.3 - Wed Jan 26 11:35:15 -0500 2011
11
+ ===============================================================================
12
+
13
+ Jon Yurek (1):
14
+ Allow the application to present the Hoptoad error number to the user
15
+
16
+
1
17
  Version 2.4.2 - Sun Jan 09 09:37:31 -0500 2011
2
18
  ===============================================================================
3
19
 
@@ -375,6 +391,8 @@ Nick Quaranto (3):
375
391
 
376
392
 
377
393
 
394
+
395
+
378
396
 
379
397
 
380
398
 
@@ -1,96 +1,100 @@
1
- = HoptoadNotifier
1
+ HoptoadNotifier
2
+ ===============
2
3
 
3
4
  This is the notifier gem for integrating apps with Hoptoad.
4
5
 
5
6
  When an uncaught exception occurs, HoptoadNotifier will POST the relevant data
6
7
  to the Hoptoad server specified in your environment.
7
8
 
8
- == Help
9
+ Help
10
+ ----
9
11
 
10
- * {IRC}[irc://irc.freenode.net/thoughtbot]
11
- * {mailing list}[http://groups.google.com/group/hoptoad-notifier-dev]
12
+ For help with using Hoptoad and the Hoptoad notifier visit [our support site](http://help.hoptoadapp.com)
12
13
 
13
- == Rails Installation
14
+ For discussion of Hoptoad notifier development check out the [mailing list](http://groups.google.com/group/hoptoad-notifier-dev)
14
15
 
15
- === Remove exception_notifier
16
+ Rails Installation
17
+ ------------------
18
+
19
+ ### Remove exception_notifier
16
20
 
17
21
  in your ApplicationController, REMOVE this line:
18
22
 
19
- include ExceptionNotifiable
23
+ include ExceptionNotifiable
20
24
 
21
25
  In your config/environment* files, remove all references to ExceptionNotifier
22
26
 
23
27
  Remove the vendor/plugins/exception_notifier directory.
24
28
 
25
- === Remove hoptoad_notifier plugin
29
+ ### Remove hoptoad_notifier plugin
26
30
 
27
31
  Remove the vendor/plugins/hoptoad_notifier directory before installing the gem, or run:
28
32
 
29
- script/plugin remove hoptoad_notifier
33
+ script/plugin remove hoptoad_notifier
30
34
 
31
- === Rails 3.x
35
+ ### Rails 3.x
32
36
 
33
37
  Add the hoptoad_notifier gem to your Gemfile. In Gemfile:
34
38
 
35
- gem "hoptoad_notifier", "~> 2.3"
39
+ gem "hoptoad_notifier", "~> 2.3"
36
40
 
37
41
  Then from your project's RAILS_ROOT, run:
38
42
 
39
- bundle install
40
- script/rails generate hoptoad --api-key your_key_here
43
+ bundle install
44
+ script/rails generate hoptoad --api-key your_key_here
41
45
 
42
46
  That's it!
43
47
 
44
- === Rails 2.x
48
+ ### Rails 2.x
45
49
 
46
50
  Add the hoptoad_notifier gem to your app. In config/environment.rb:
47
51
 
48
- config.gem 'hoptoad_notifier'
52
+ config.gem 'hoptoad_notifier'
49
53
 
50
54
  Then from your project's RAILS_ROOT, run:
51
55
 
52
- rake gems:install
53
- rake gems:unpack GEM=hoptoad_notifier
54
- script/generate hoptoad --api-key your_key_here
56
+ rake gems:install
57
+ rake gems:unpack GEM=hoptoad_notifier
58
+ script/generate hoptoad --api-key your_key_here
55
59
 
56
60
  As always, if you choose not to vendor the hoptoad_notifier gem, make sure
57
61
  every server you deploy to has the gem installed or your application won't start.
58
62
 
59
- === Rails 1.2.6
63
+ ### Rails 1.2.6
60
64
 
61
65
  Install the hoptoad_notifier gem:
62
66
 
63
- gem install hoptoad_notifier
67
+ gem install hoptoad_notifier
64
68
 
65
69
  Once installed, you should vendor the hoptoad_notifier gem:
66
70
 
67
- mkdir vendor/gems
68
- cd vendor/gems
69
- gem unpack hoptoad_notifier
71
+ mkdir vendor/gems
72
+ cd vendor/gems
73
+ gem unpack hoptoad_notifier
70
74
 
71
75
  And then add the following to the Rails::Initializer.run do |config|
72
76
  block in environment.rb so that the vendored gem is loaded.
73
77
 
74
- # Add the vendor/gems/*/lib directories to the LOAD_PATH
75
- config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib'))
78
+ # Add the vendor/gems/*/lib directories to the LOAD_PATH
79
+ config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib'))
76
80
 
77
81
  Next add something like this at the bottom of your config/environment.rb:
78
82
 
79
- require 'hoptoad_notifier'
80
- require 'hoptoad_notifier/rails'
81
- HoptoadNotifier.configure do |config|
82
- config.api_key = 'your_key_here'
83
- end
83
+ require 'hoptoad_notifier'
84
+ require 'hoptoad_notifier/rails'
85
+ HoptoadNotifier.configure do |config|
86
+ config.api_key = 'your_key_here'
87
+ end
84
88
 
85
89
  You will also need to copy the hoptoad_notifier_tasks.rake file into your
86
90
  RAILS_ROOT/lib/tasks directory in order for the rake hoptoad:test task to work:
87
91
 
88
- cp vendor/gems/hoptoad_notifier-*/generators/hoptoad/templates/hoptoad_notifier_tasks.rake lib/tasks
92
+ cp vendor/gems/hoptoad_notifier-*/generators/hoptoad/templates/hoptoad_notifier_tasks.rake lib/tasks
89
93
 
90
94
  As always, if you choose not to vendor the hoptoad_notifier gem, make sure
91
95
  every server you deploy to has the gem installed or your application won't start.
92
96
 
93
- === Upgrading From Earlier Versions of Hoptoad
97
+ ### Upgrading From Earlier Versions of Hoptoad
94
98
 
95
99
  If you're currently using the plugin version (if you have a
96
100
  vendor/plugins/hoptoad_notifier directory, you are), you'll need to perform a
@@ -131,7 +135,7 @@ As always, if you choose not to vendor the hoptoad_notifier gem, make sure
131
135
  every server you deploy to has the gem installed or your application won't
132
136
  start.
133
137
 
134
- == Upgrading from Earlier Versions of the Hoptoad Gem (with config.gem)
138
+ ### Upgrading from Earlier Versions of the Hoptoad Gem (with config.gem)
135
139
 
136
140
  If you're currently using the gem version of the hoptoad_notifier and have
137
141
  a version of Rails that uses config.gem (in the 2.x series), there is
@@ -148,56 +152,59 @@ You can them continue to install normally. If you don't remove the rake file,
148
152
  you will be unable to unpack this gem (Rails will think it's part of the
149
153
  framework).
150
154
 
151
- === Testing it out
155
+ ### Testing it out
152
156
 
153
157
  You can test that Hoptoad is working in your production environment by using
154
158
  this rake task (from RAILS_ROOT):
155
159
 
156
- rake hoptoad:test
160
+ rake hoptoad:test
157
161
 
158
162
  If everything is configured properly, that task will send a notice to Hoptoad
159
163
  which will be visible immediately.
160
164
 
161
- == Rack
165
+ Rack
166
+ ----
162
167
 
163
168
  In order to use hoptoad_notifier in a non-Rails rack app, just load the
164
169
  hoptoad_notifier, configure your API key, and use the HoptoadNotifier::Rack
165
170
  middleware:
166
171
 
167
- require 'rack'
168
- require 'hoptoad_notifier'
172
+ require 'rack'
173
+ require 'hoptoad_notifier'
169
174
 
170
- HoptoadNotifier.configure do |config|
171
- config.api_key = 'my_api_key'
172
- end
175
+ HoptoadNotifier.configure do |config|
176
+ config.api_key = 'my_api_key'
177
+ end
173
178
 
174
- app = Rack::Builder.app do
175
- use HoptoadNotifier::Rack
176
- run lambda { |env| raise "Rack down" }
177
- end
179
+ app = Rack::Builder.app do
180
+ use HoptoadNotifier::Rack
181
+ run lambda { |env| raise "Rack down" }
182
+ end
178
183
 
179
- == Sinatra
184
+ Sinatra
185
+ -------
180
186
 
181
187
  Using hoptoad_notifier in a Sinatra app is just like a Rack app, but you have
182
188
  to disable Sinatra's error rescuing functionality:
183
189
 
184
- require 'sinatra/base'
185
- require 'hoptoad_notifier'
186
-
187
- HoptoadNotifier.configure do |config|
188
- config.api_key = 'my_api_key'
189
- end
190
-
191
- class MyApp < Sinatra::Default
192
- use HoptoadNotifier::Rack
193
- enable :raise_errors
194
-
195
- get "/" do
196
- raise "Sinatra has left the building"
190
+ require 'sinatra/base'
191
+ require 'hoptoad_notifier'
192
+
193
+ HoptoadNotifier.configure do |config|
194
+ config.api_key = 'my_api_key'
195
+ end
196
+
197
+ class MyApp < Sinatra::Default
198
+ use HoptoadNotifier::Rack
199
+ enable :raise_errors
200
+
201
+ get "/" do
202
+ raise "Sinatra has left the building"
203
+ end
197
204
  end
198
- end
199
205
 
200
- == Usage
206
+ Usage
207
+ -----
201
208
 
202
209
  For the most part, Hoptoad works for itself. Once you've included the notifier
203
210
  in your ApplicationController (which is now done automatically by the gem),
@@ -206,12 +213,12 @@ all errors will be rescued by the #rescue_action_in_public provided by the gem.
206
213
  If you want to log arbitrary things which you've rescued yourself from a
207
214
  controller, you can do something like this:
208
215
 
209
- ...
210
- rescue => ex
211
- notify_hoptoad(ex)
212
- flash[:failure] = 'Encryptions could not be rerouted, try again.'
213
- end
214
- ...
216
+ ...
217
+ rescue => ex
218
+ notify_hoptoad(ex)
219
+ flash[:failure] = 'Encryptions could not be rerouted, try again.'
220
+ end
221
+ ...
215
222
 
216
223
  The #notify_hoptoad call will send the notice over to Hoptoad for later
217
224
  analysis. While in your controllers you use the notify_hoptoad method, anywhere
@@ -221,7 +228,8 @@ To perform custom error processing after Hoptoad has been notified, define the
221
228
  instance method #rescue_action_in_public_without_hoptoad(exception) in your
222
229
  controller.
223
230
 
224
- == Tracking deployments in Hoptoad
231
+ Tracking deployments in Hoptoad
232
+ -------------------------------
225
233
 
226
234
  Paying Hoptoad plans support the ability to track deployments of your application in Hoptoad.
227
235
  By notifying Hoptoad of your application deployments, all errors are resolved when a deploy occurs,
@@ -231,7 +239,7 @@ Additionally, it's possible to review the errors in Hoptoad that occurred before
231
239
 
232
240
  When Hoptoad is installed as a gem, you need to add
233
241
 
234
- require 'hoptoad_notifier/capistrano'
242
+ require 'hoptoad_notifier/capistrano'
235
243
 
236
244
  to your deploy.rb
237
245
 
@@ -240,24 +248,25 @@ deployment process to notify Hoptoad:
240
248
 
241
249
  rake hoptoad:deploy TO=#{rails_env} REVISION=#{current_revision} REPO=#{repository} USER=#{local_user}
242
250
 
243
- == Going beyond exceptions
251
+ Going beyond exceptions
252
+ -----------------------
244
253
 
245
254
  You can also pass a hash to notify_hoptoad method and store whatever you want,
246
255
  not just an exception. And you can also use it anywhere, not just in
247
256
  controllers:
248
257
 
249
- begin
250
- params = {
251
- # params that you pass to a method that can throw an exception
252
- }
253
- my_unpredicable_method(params)
254
- rescue => e
255
- HoptoadNotifier.notify(
256
- :error_class => "Special Error",
257
- :error_message => "Special Error: #{e.message}",
258
- :parameters => params
259
- )
260
- end
258
+ begin
259
+ params = {
260
+ # params that you pass to a method that can throw an exception
261
+ }
262
+ my_unpredicable_method(params)
263
+ rescue => e
264
+ HoptoadNotifier.notify(
265
+ :error_class => "Special Error",
266
+ :error_message => "Special Error: #{e.message}",
267
+ :parameters => params
268
+ )
269
+ end
261
270
 
262
271
  While in your controllers you use the notify_hoptoad method, anywhere else in
263
272
  your code, use HoptoadNotifier.notify. Hoptoad will get all the information
@@ -269,17 +278,17 @@ about the error itself. As for a hash, these are the keys you should pass:
269
278
 
270
279
  Hoptoad merges the hash you pass with these default options:
271
280
 
272
- {
273
- :api_key => HoptoadNotifier.api_key,
274
- :error_message => 'Notification',
275
- :backtrace => caller,
276
- :parameters => {},
277
- :session => {}
278
- }
281
+ {
282
+ :api_key => HoptoadNotifier.api_key,
283
+ :error_message => 'Notification',
284
+ :backtrace => caller,
285
+ :parameters => {},
286
+ :session => {}
287
+ }
279
288
 
280
289
  You can override any of those parameters.
281
290
 
282
- === Sending shell environment variables when "Going beyond exceptions"
291
+ ### Sending shell environment variables when "Going beyond exceptions"
283
292
 
284
293
  One common request we see is to send shell environment variables along with
285
294
  manual exception notification. We recommend sending them along with CGI data
@@ -288,7 +297,8 @@ or Rack environment (:cgi_data or :rack_env keys, respectively.)
288
297
  See HoptoadNotifier::Notice#initialize in lib/hoptoad_notifier/notice.rb for
289
298
  more details.
290
299
 
291
- == Filtering
300
+ Filtering
301
+ ---------
292
302
 
293
303
  You can specify a whitelist of errors, that Hoptoad will not report on. Use
294
304
  this feature when you are so apathetic to certain errors that you don't want
@@ -299,81 +309,84 @@ notifications (when #notify is called directly).
299
309
 
300
310
  Hoptoad ignores the following exceptions by default:
301
311
 
302
- AbstractController::ActionNotFound
303
- ActiveRecord::RecordNotFound
304
- ActionController::RoutingError
305
- ActionController::InvalidAuthenticityToken
306
- ActionController::UnknownAction
307
- CGI::Session::CookieStore::TamperedWithCookie
312
+ AbstractController::ActionNotFound
313
+ ActiveRecord::RecordNotFound
314
+ ActionController::RoutingError
315
+ ActionController::InvalidAuthenticityToken
316
+ ActionController::UnknownAction
317
+ CGI::Session::CookieStore::TamperedWithCookie
308
318
 
309
319
  To ignore errors in addition to those, specify their names in your Hoptoad
310
320
  configuration block.
311
321
 
312
- HoptoadNotifier.configure do |config|
313
- config.api_key = '1234567890abcdef'
314
- config.ignore << "ActiveRecord::IgnoreThisError"
315
- end
322
+ HoptoadNotifier.configure do |config|
323
+ config.api_key = '1234567890abcdef'
324
+ config.ignore << "ActiveRecord::IgnoreThisError"
325
+ end
316
326
 
317
327
  To ignore *only* certain errors (and override the defaults), use the
318
328
  #ignore_only attribute.
319
329
 
320
- HoptoadNotifier.configure do |config|
321
- config.api_key = '1234567890abcdef'
322
- config.ignore_only = ["ActiveRecord::IgnoreThisError"]
323
- end
330
+ HoptoadNotifier.configure do |config|
331
+ config.api_key = '1234567890abcdef'
332
+ config.ignore_only = ["ActiveRecord::IgnoreThisError"]
333
+ end
324
334
 
325
335
  To ignore certain user agents, add in the #ignore_user_agent attribute as a
326
336
  string or regexp:
327
337
 
328
- HoptoadNotifier.configure do |config|
329
- config.api_key = '1234567890abcdef'
330
- config.ignore_user_agent << /Ignored/
331
- config.ignore_user_agent << 'IgnoredUserAgent'
332
- end
338
+ HoptoadNotifier.configure do |config|
339
+ config.api_key = '1234567890abcdef'
340
+ config.ignore_user_agent << /Ignored/
341
+ config.ignore_user_agent << 'IgnoredUserAgent'
342
+ end
333
343
 
334
344
  To ignore exceptions based on other conditions, use #ignore_by_filter:
335
345
 
336
- HoptoadNotifier.configure do |config|
337
- config.api_key = '1234567890abcdef'
338
- config.ignore_by_filter do |exception_data|
339
- true if exception_data[:error_class] == "RuntimeError"
346
+ HoptoadNotifier.configure do |config|
347
+ config.api_key = '1234567890abcdef'
348
+ config.ignore_by_filter do |exception_data|
349
+ true if exception_data[:error_class] == "RuntimeError"
350
+ end
340
351
  end
341
- end
342
352
 
343
353
  To replace sensitive information sent to the Hoptoad service with [FILTERED] use #params_filters:
344
354
 
345
- HoptoadNotifier.configure do |config|
346
- config.api_key = '1234567890abcdef'
347
- config.params_filters << "credit_card_number"
348
- end
355
+ HoptoadNotifier.configure do |config|
356
+ config.api_key = '1234567890abcdef'
357
+ config.params_filters << "credit_card_number"
358
+ end
349
359
 
350
360
  Note that, when rescuing exceptions within an ActionController method,
351
361
  hoptoad_notifier will reuse filters specified by #filter_parameter_logging.
352
362
 
353
- == Testing
363
+ Testing
364
+ -------
354
365
 
355
366
  When you run your tests, you might notice that the Hoptoad service is recording
356
367
  notices generated using #notify when you don't expect it to. You can
357
368
  use code like this in your test_helper.rb to redefine that method so those
358
369
  errors are not reported while running tests.
359
370
 
360
- module HoptoadNotifier
361
- def self.notify(thing)
362
- # do nothing.
371
+ module HoptoadNotifier
372
+ def self.notify(thing)
373
+ # do nothing.
374
+ end
363
375
  end
364
- end
365
376
 
366
- == Proxy Support
377
+ Proxy Support
378
+ -------------
367
379
 
368
380
  The notifier supports using a proxy, if your server is not able to directly reach the Hoptoad servers. To configure the proxy settings, added the following information to your Hoptoad configuration block.
369
381
 
370
- HoptoadNotifier.configure do |config|
371
- config.proxy_host = ...
372
- config.proxy_port = ...
373
- config.proxy_user = ...
374
- config.proxy_pass = ...
382
+ HoptoadNotifier.configure do |config|
383
+ config.proxy_host = ...
384
+ config.proxy_port = ...
385
+ config.proxy_user = ...
386
+ config.proxy_pass = ...
375
387
 
376
- == Supported Rails versions
388
+ Supported Rails versions
389
+ ------------------------
377
390
 
378
391
  See SUPPORTED_RAILS_VERSIONS for a list of official supported versions of
379
392
  Rails.
@@ -382,19 +395,41 @@ Please open up a support ticket on Tender ( http://help.hoptoadapp.com ) if
382
395
  you're using a version of Rails that is not listed above and the notifier is
383
396
  not working properly.
384
397
 
385
- == Javascript Notifer
398
+ Javascript Notifer
399
+ ------------------
400
+
401
+ To automatically include the Javascript node on every page, use this helper method from your layouts:
402
+
403
+ <%= hoptoad_javascript_notifier %>
404
+
405
+ It's important to insert this very high in the markup, above all other javascript. Example:
406
+
407
+ <!DOCTYPE html>
408
+ <html>
409
+ <head>
410
+ <meta charset="utf8">
411
+ <%= hoptoad_javascript_notifier %>
412
+ <!-- more javascript -->
413
+ </head>
414
+ <body>
415
+ ...
416
+ </body>
417
+ </html>
418
+
419
+ This helper will automatically use the API key, host, and port specified in the configuration.
420
+
421
+ Credits
422
+ -------
423
+
424
+ ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
386
425
 
387
- To automatically include the Javascript node on every page, set the
388
- :js_notifier to true:
426
+ HoptoadNotifier is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
389
427
 
390
- HoptoadNotifier.configure do |config|
391
- config.js_notifier = true
392
- end
428
+ Thank you to all [the contributors](https://github.com/thoughtbot/hoptoad_notifier/contributors)!
393
429
 
394
- It automatically uses the API key, host, and port specified in the
395
- configuration.
430
+ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
396
431
 
397
- == Thanks
432
+ License
433
+ -------
398
434
 
399
- Thanks to Eugene Bolshakov for the excellent write-up on GOING BEYOND
400
- EXCEPTIONS, which we have included above.
435
+ HoptoadNotifier is Copyright © 2008-2011 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
data/Rakefile CHANGED
@@ -123,10 +123,6 @@ gemspec = Gem::Specification.new do |s|
123
123
  s.require_path = 'lib'
124
124
  s.test_files = Dir[*['test/**/*_test.rb']]
125
125
 
126
- s.has_rdoc = true
127
- s.extra_rdoc_files = ["README.rdoc"]
128
- s.rdoc_options = ['--line-numbers', "--main", "README.rdoc"]
129
-
130
126
  s.add_runtime_dependency("builder")
131
127
  s.add_runtime_dependency("activesupport")
132
128
  s.add_development_dependency("activerecord")
@@ -7,7 +7,8 @@ module HoptoadNotifier
7
7
  :http_open_timeout, :http_read_timeout, :ignore, :ignore_by_filters,
8
8
  :ignore_user_agent, :notifier_name, :notifier_url, :notifier_version,
9
9
  :params_filters, :project_root, :port, :protocol, :proxy_host,
10
- :proxy_pass, :proxy_port, :proxy_user, :secure, :framework, :js_notifier].freeze
10
+ :proxy_pass, :proxy_port, :proxy_user, :secure, :framework,
11
+ :user_information].freeze
11
12
 
12
13
  # The API key for your project, found on the project edit form.
13
14
  attr_accessor :api_key
@@ -62,9 +63,6 @@ module HoptoadNotifier
62
63
  # +true+ if you want to check for production errors matching development errors, +false+ otherwise.
63
64
  attr_accessor :development_lookup
64
65
 
65
- # +true+ if you want to enable the JavaScript notifier in production environments
66
- attr_accessor :js_notifier
67
-
68
66
  # The name of the environment the application is running in
69
67
  attr_accessor :environment_name
70
68
 
@@ -83,6 +81,9 @@ module HoptoadNotifier
83
81
  # The logger used by HoptoadNotifier
84
82
  attr_accessor :logger
85
83
 
84
+ # The text that the placeholder is replaced with. {{error_id}} is the actual error number.
85
+ attr_accessor :user_information
86
+
86
87
  # The framework HoptoadNotifier is configured to use
87
88
  attr_accessor :framework
88
89
 
@@ -128,11 +129,11 @@ module HoptoadNotifier
128
129
  @ignore_user_agent = []
129
130
  @development_environments = %w(development test cucumber)
130
131
  @development_lookup = true
131
- @js_notifier = false
132
132
  @notifier_name = 'Hoptoad Notifier'
133
133
  @notifier_version = VERSION
134
134
  @notifier_url = 'http://hoptoadapp.com'
135
135
  @framework = 'Standalone'
136
+ @user_information = 'Hoptoad Error {{error_id}}'
136
137
  end
137
138
 
138
139
  # Takes a block and adds it to the list of backtrace filters. When the filters
@@ -217,6 +218,10 @@ module HoptoadNotifier
217
218
  end
218
219
  end
219
220
 
221
+ def js_notifier=(*args)
222
+ warn '[HOPTOAD] config.js_notifier has been deprecated and has no effect. You should use <%= hoptoad_javascript_notifier %> directly at the top of your layouts. Be sure to place it before all other javascript.'
223
+ end
224
+
220
225
  def environment_filters
221
226
  warn 'config.environment_filters has been deprecated and has no effect.'
222
227
  []
@@ -26,12 +26,14 @@ module HoptoadNotifier
26
26
  begin
27
27
  response = @app.call(env)
28
28
  rescue Exception => raised
29
- HoptoadNotifier.notify_or_ignore(raised, :rack_env => env)
29
+ error_id = HoptoadNotifier.notify_or_ignore(raised, :rack_env => env)
30
+ env['hoptoad.error_id'] = error_id
30
31
  raise
31
32
  end
32
33
 
33
34
  if env['rack.exception']
34
- HoptoadNotifier.notify_or_ignore(env['rack.exception'], :rack_env => env)
35
+ error_id = HoptoadNotifier.notify_or_ignore(env['rack.exception'], :rack_env => env)
36
+ env['hoptoad.error_id'] = error_id
35
37
  end
36
38
 
37
39
  response
@@ -14,7 +14,8 @@ module HoptoadNotifier
14
14
  # any custom processing that is defined with Rails 2's exception helpers.
15
15
  def rescue_action_in_public_with_hoptoad(exception)
16
16
  unless hoptoad_ignore_user_agent?
17
- HoptoadNotifier.notify_or_ignore(exception, hoptoad_request_data)
17
+ error_id = HoptoadNotifier.notify_or_ignore(exception, hoptoad_request_data)
18
+ request.env['hoptoad.error_id'] = error_id
18
19
  end
19
20
  rescue_action_in_public_without_hoptoad(exception)
20
21
  end
@@ -2,44 +2,39 @@ module HoptoadNotifier
2
2
  module Rails
3
3
  module JavascriptNotifier
4
4
  def self.included(base) #:nodoc:
5
- base.send(:after_filter, :insert_hoptoad_javascript_notifier)
5
+ base.send :helper_method, :hoptoad_javascript_notifier
6
6
  end
7
7
 
8
8
  private
9
9
 
10
- def insert_hoptoad_javascript_notifier
10
+ def hoptoad_javascript_notifier
11
11
  return unless HoptoadNotifier.configuration.public?
12
- return unless HoptoadNotifier.configuration.js_notifier
13
12
 
14
- path = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'javascript_notifier.erb')
13
+ path = File.join File.dirname(__FILE__), '..', '..', 'templates', 'javascript_notifier.erb'
15
14
  host = HoptoadNotifier.configuration.host.dup
16
15
  port = HoptoadNotifier.configuration.port
17
16
  host << ":#{port}" unless [80, 443].include?(port)
18
17
 
19
- options = {
20
- :file => path,
21
- :layout => false,
22
- :use_full_path => false,
23
- :locals => {
24
- :host => host,
25
- :api_key => HoptoadNotifier.configuration.api_key,
26
- :environment => HoptoadNotifier.configuration.environment_name
18
+ options = {
19
+ :file => path,
20
+ :layout => false,
21
+ :use_full_path => false,
22
+ :locals => {
23
+ :host => host,
24
+ :api_key => HoptoadNotifier.configuration.api_key,
25
+ :environment => HoptoadNotifier.configuration.environment_name,
26
+ :action_name => action_name,
27
+ :controller_name => controller_name,
28
+ :url => request.url
27
29
  }
28
30
  }
29
31
 
30
32
  if @template
31
- javascript = @template.render(options)
33
+ @template.render(options)
32
34
  else
33
- javascript = render_to_string(options)
35
+ render_to_string(options)
34
36
  end
35
37
 
36
- if response.body.respond_to?(:gsub)
37
- response.body = insert_javascript_after_head response.body, javascript
38
- end
39
- end
40
-
41
- def insert_javascript_after_head(body, javascript)
42
- body.gsub /<(head.*?)>/i, "<\\1>\n#{javascript}\n"
43
38
  end
44
39
 
45
40
  end
@@ -23,6 +23,8 @@ module HoptoadNotifier
23
23
  if defined?(::Rails.configuration) && ::Rails.configuration.respond_to?(:middleware)
24
24
  ::Rails.configuration.middleware.insert_after 'ActionController::Failsafe',
25
25
  HoptoadNotifier::Rack
26
+ ::Rails.configuration.middleware.insert_after 'Rack::Lock',
27
+ HoptoadNotifier::UserInformer
26
28
  end
27
29
 
28
30
  HoptoadNotifier.configure(true) do |config|
@@ -9,6 +9,7 @@ module HoptoadNotifier
9
9
 
10
10
  initializer "hoptoad.use_rack_middleware" do |app|
11
11
  app.config.middleware.use "HoptoadNotifier::Rack"
12
+ app.config.middleware.insert_after "Rack::Lock", "HoptoadNotifier::UserInformer"
12
13
  end
13
14
 
14
15
  config.after_initialize do
@@ -46,6 +46,11 @@ module HoptoadNotifier
46
46
  else
47
47
  log :error, "Failure: #{response.class}", response
48
48
  end
49
+
50
+ if response && response.respond_to?(:body)
51
+ error_id = response.body.match(%r{<error-id[^>]*>(.*?)</error-id>})
52
+ error_id[1] if error_id
53
+ end
49
54
  end
50
55
 
51
56
  private
@@ -0,0 +1,29 @@
1
+ module HoptoadNotifier
2
+ class UserInformer
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def replacement(with)
8
+ @replacement ||= HoptoadNotifier.configuration.user_information.gsub(/\{\{\s*error_id\s*\}\}/, with.to_s)
9
+ end
10
+
11
+ def call(env)
12
+ response = @app.call(env)
13
+ if env['hoptoad.error_id']
14
+ new_response = []
15
+ original_content_length = 0
16
+ modified_content_length = 0
17
+ response[2].each do |chunk|
18
+ original_content_length += chunk.length
19
+ new_response << chunk.to_s.gsub("<!-- HOPTOAD ERROR -->", replacement(env['hoptoad.error_id']))
20
+ modified_content_length += new_response.last.length
21
+ end
22
+ response[1]['Content-Length'] = modified_content_length.to_s
23
+ response[2] = new_response
24
+ end
25
+ response
26
+ end
27
+ end
28
+ end
29
+
@@ -1,3 +1,3 @@
1
1
  module HoptoadNotifier
2
- VERSION = "2.4.2".freeze
2
+ VERSION = "2.4.4".freeze
3
3
  end
@@ -12,6 +12,7 @@ require 'hoptoad_notifier/notice'
12
12
  require 'hoptoad_notifier/sender'
13
13
  require 'hoptoad_notifier/backtrace'
14
14
  require 'hoptoad_notifier/rack'
15
+ require 'hoptoad_notifier/user_informer'
15
16
 
16
17
  require 'hoptoad_notifier/railtie' if defined?(Rails::Railtie)
17
18
 
@@ -1,17 +1,13 @@
1
- <script type="text/javascript">
2
- //<![CDATA[
3
- var notifierJsScheme = (("https:" == document.location.protocol) ? "https://" : "http://");
4
- document.write(unescape("%3Cscript src='" + notifierJsScheme + "<%= host %>/javascripts/notifier.js' type='text/javascript'%3E%3C/script%3E"));
5
- //]]>
6
- </script>
1
+ <%= javascript_tag %Q{
2
+ var notifierJsScheme = (("https:" == document.location.protocol) ? "https://" : "http://");
3
+ document.write(unescape("%3Cscript src='" + notifierJsScheme + "#{host}/javascripts/notifier.js' type='text/javascript'%3E%3C/script%3E"));
4
+ }
5
+ %>
7
6
 
8
- <script type="text/javascript">
9
- Hoptoad.setKey('<%= api_key %>');
10
- Hoptoad.setHost('<%= host %>');
11
- Hoptoad.setEnvironment('<%= environment %>');
12
- Hoptoad.setErrorDefaults({
13
- url: "<%= a = "#{controller.request.protocol}#{controller.request.host_with_port}#{controller.request.request_uri}"; p a; a %>",
14
- component: "<%= controller.controller_name %>",
15
- action: "<%= controller.action_name %>"
16
- });
17
- </script>
7
+ <%= javascript_tag %Q{
8
+ Hoptoad.setKey('#{api_key}');
9
+ Hoptoad.setHost('#{host}');
10
+ Hoptoad.setEnvironment('#{environment}');
11
+ Hoptoad.setErrorDefaults({ url: "#{escape_javascript url}", component: "#{controller_name}", action: "#{action_name}" });
12
+ }
13
+ %>
data/test/catcher_test.rb CHANGED
@@ -25,6 +25,8 @@ class ActionControllerCatcherTest < Test::Unit::TestCase
25
25
 
26
26
  def assert_sent_hash(hash, xpath)
27
27
  hash.each do |key, value|
28
+ next if key.match(/^hoptoad\./) # We added this key.
29
+
28
30
  element_xpath = "#{xpath}/var[@key = '#{key}']"
29
31
  if value.respond_to?(:to_hash)
30
32
  assert_sent_hash value.to_hash, element_xpath
@@ -29,7 +29,6 @@ class ConfigurationTest < Test::Unit::TestCase
29
29
  HoptoadNotifier::Configuration::IGNORE_DEFAULT
30
30
  assert_config_default :development_lookup, true
31
31
  assert_config_default :framework, 'Standalone'
32
- assert_config_default :js_notifier, false
33
32
  end
34
33
 
35
34
  should "provide default values for secure connections" do
@@ -85,7 +84,7 @@ class ConfigurationTest < Test::Unit::TestCase
85
84
  :http_read_timeout, :ignore, :ignore_by_filters, :ignore_user_agent,
86
85
  :notifier_name, :notifier_url, :notifier_version, :params_filters,
87
86
  :project_root, :port, :protocol, :proxy_host, :proxy_pass, :proxy_port,
88
- :proxy_user, :secure, :development_lookup, :js_notifier].each do |option|
87
+ :proxy_user, :secure, :development_lookup].each do |option|
89
88
  assert_equal config[option], hash[option], "Wrong value for #{option}"
90
89
  end
91
90
  end
@@ -108,6 +107,14 @@ class ConfigurationTest < Test::Unit::TestCase
108
107
  assert_equal [], config.environment_filters
109
108
  end
110
109
 
110
+ should "warn when attempting to write js_notifier" do
111
+ config = HoptoadNotifier::Configuration.new
112
+ config.
113
+ expects(:warn).
114
+ with(regexp_matches(/deprecated/i))
115
+ config.js_notifier = true
116
+ end
117
+
111
118
  should "allow ignored user agents to be appended" do
112
119
  assert_appends_value :ignore_user_agent
113
120
  end
data/test/helper.rb CHANGED
@@ -7,6 +7,7 @@ gem "actionpack", "= 2.3.8"
7
7
  gem "nokogiri", "= 1.4.3.1"
8
8
  gem "shoulda", "= 2.11.3"
9
9
  gem 'bourne', '>= 1.0'
10
+ gem "sham_rack", "~> 1.3.0"
10
11
 
11
12
  $LOAD_PATH << File.join(File.dirname(__FILE__), *%w[.. vendor ginger lib])
12
13
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
@@ -25,6 +26,7 @@ require 'active_support'
25
26
  require 'nokogiri'
26
27
  require 'rack'
27
28
  require 'bourne'
29
+ require 'sham_rack'
28
30
 
29
31
  require "hoptoad_notifier"
30
32
 
@@ -1,38 +1,52 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
-
3
2
  require 'hoptoad_notifier/rails/javascript_notifier'
3
+ require 'ostruct'
4
4
 
5
5
  class JavascriptNotifierTest < Test::Unit::TestCase
6
-
7
- def self.after_filter(arg); end
8
- include ::HoptoadNotifier::Rails::JavascriptNotifier
9
-
10
- should "insert javascript after head" do
11
- input_body =<<-EOS
12
- <html><head><title></title></head><body></body></html>
13
- EOS
14
- javascript = "js-code"
15
- expected =<<-EOS
16
- <html><head>
17
- js-code
18
- <title></title></head><body></body></html>
19
- EOS
20
- output = send :insert_javascript_after_head, input_body, javascript
21
- assert_equal expected, output
6
+ module FakeRenderer
7
+ def javascript_tag(text)
8
+ "<script>#{text}</script>"
9
+ end
10
+ def escape_javascript(text)
11
+ "ESC#{text}ESC"
12
+ end
22
13
  end
23
14
 
24
- should "insert javascript after head when head has attributes" do
25
- input_body =<<-EOS
26
- <html><head lang="en"><title></title></head><body></body></html>
27
- EOS
28
- javascript = "js-code"
29
- expected =<<-EOS
30
- <html><head lang="en">
31
- js-code
32
- <title></title></head><body></body></html>
33
- EOS
34
- output = send :insert_javascript_after_head, input_body, javascript
35
- assert_equal expected, output
15
+ class FakeController
16
+ def self.helper_method(*args)
17
+ end
18
+
19
+ include HoptoadNotifier::Rails::JavascriptNotifier
20
+
21
+ def action_name
22
+ "action"
23
+ end
24
+
25
+ def controller_name
26
+ "controller"
27
+ end
28
+
29
+ def request
30
+ @request ||= OpenStruct.new
31
+ end
32
+
33
+ def render_to_string(options)
34
+ context = OpenStruct.new(options[:locals])
35
+ context.extend(FakeRenderer)
36
+ context.instance_eval do
37
+ erb = ERB.new(IO.read(options[:file]))
38
+ erb.result(binding)
39
+ end
40
+ end
36
41
  end
37
42
 
43
+ should "make sure escape_javacript is called on the request.url" do
44
+ HoptoadNotifier.configure do
45
+ end
46
+ controller = FakeController.new
47
+ controller.request.url = "bad_javascript"
48
+ assert controller.send(:hoptoad_javascript_notifier)['"ESCbad_javascriptESC"']
49
+ assert ! controller.send(:hoptoad_javascript_notifier)['"bad_javascript"']
50
+ end
38
51
  end
52
+
data/test/sender_test.rb CHANGED
@@ -16,11 +16,10 @@ class SenderTest < Test::Unit::TestCase
16
16
  notice = args.delete(:notice) || build_notice_data
17
17
  sender = args.delete(:sender) || build_sender(args)
18
18
  sender.send_to_hoptoad(notice)
19
- sender
20
19
  end
21
20
 
22
- def stub_http
23
- response = stub(:body => 'body')
21
+ def stub_http(options = {})
22
+ response = stub(:body => options[:body] || 'body')
24
23
  http = stub(:post => response,
25
24
  :read_timeout= => nil,
26
25
  :open_timeout= => nil,
@@ -58,6 +57,17 @@ class SenderTest < Test::Unit::TestCase
58
57
  end
59
58
  end
60
59
 
60
+ should "return the created group's id on successful posting" do
61
+ http = stub_http(:body => '<error-id type="integer">3799307</error-id>')
62
+ assert_equal "3799307", send_exception(:secure => false)
63
+ end
64
+
65
+ should "return nil on failed posting" do
66
+ http = stub_http
67
+ http.stubs(:post).raises(Errno::ECONNREFUSED)
68
+ assert_equal nil, send_exception(:secure => false)
69
+ end
70
+
61
71
  should "not fail when posting and a timeout exception occurs" do
62
72
  http = stub_http
63
73
  http.stubs(:post).raises(TimeoutError)
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class UserInformerTest < Test::Unit::TestCase
4
+ should "modify output if there is a hoptoad id" do
5
+ main_app = lambda do |env|
6
+ env['hoptoad.error_id'] = 1
7
+ [200, {}, "<!-- HOPTOAD ERROR -->"]
8
+ end
9
+ informer_app = HoptoadNotifier::UserInformer.new(main_app)
10
+
11
+ ShamRack.mount(informer_app, "example.com")
12
+
13
+ response = Net::HTTP.get_response(URI.parse("http://example.com/"))
14
+ assert_equal "Hoptoad Error 1", response.body
15
+ assert_equal 15, response["Content-Length"].to_i
16
+ end
17
+
18
+ should "not modify output if there is no hoptoad id" do
19
+ main_app = lambda do |env|
20
+ [200, {}, "<!-- HOPTOAD ERROR -->"]
21
+ end
22
+ informer_app = HoptoadNotifier::UserInformer.new(main_app)
23
+
24
+ ShamRack.mount(informer_app, "example.com")
25
+
26
+ response = Net::HTTP.get_response(URI.parse("http://example.com/"))
27
+ assert_equal "<!-- HOPTOAD ERROR -->", response.body
28
+ end
29
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoptoad_notifier
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 4
9
- - 2
10
- version: 2.4.2
9
+ - 4
10
+ version: 2.4.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - thoughtbot, inc
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-09 00:00:00 -05:00
18
+ date: 2011-01-28 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -122,14 +122,14 @@ executables: []
122
122
 
123
123
  extensions: []
124
124
 
125
- extra_rdoc_files:
126
- - README.rdoc
125
+ extra_rdoc_files: []
126
+
127
127
  files:
128
128
  - CHANGELOG
129
129
  - INSTALL
130
130
  - MIT-LICENSE
131
131
  - Rakefile
132
- - README.rdoc
132
+ - README.md
133
133
  - README_FOR_HEROKU_ADDON.md
134
134
  - SUPPORTED_RAILS_VERSIONS
135
135
  - TESTING.rdoc
@@ -154,6 +154,7 @@ files:
154
154
  - lib/hoptoad_notifier/sender.rb
155
155
  - lib/hoptoad_notifier/shared_tasks.rb
156
156
  - lib/hoptoad_notifier/tasks.rb
157
+ - lib/hoptoad_notifier/user_informer.rb
157
158
  - lib/hoptoad_notifier/version.rb
158
159
  - lib/hoptoad_notifier.rb
159
160
  - lib/hoptoad_tasks.rb
@@ -170,6 +171,7 @@ files:
170
171
  - test/rack_test.rb
171
172
  - test/rails_initializer_test.rb
172
173
  - test/sender_test.rb
174
+ - test/user_informer_test.rb
173
175
  - rails/init.rb
174
176
  - script/integration_test.rb
175
177
  - lib/templates/javascript_notifier.erb
@@ -179,10 +181,8 @@ homepage: http://www.hoptoadapp.com
179
181
  licenses: []
180
182
 
181
183
  post_install_message:
182
- rdoc_options:
183
- - --line-numbers
184
- - --main
185
- - README.rdoc
184
+ rdoc_options: []
185
+
186
186
  require_paths:
187
187
  - lib
188
188
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -222,3 +222,4 @@ test_files:
222
222
  - test/rack_test.rb
223
223
  - test/rails_initializer_test.rb
224
224
  - test/sender_test.rb
225
+ - test/user_informer_test.rb