Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' of github.com:thoughtbot/hoptoad_notifier

Conflicts:
	README.md
	Rakefile
  • Loading branch information...
commit 5dfa7fc3ebfcb7691805f351163510f62212e4b7 2 parents 5846faf + 51240c1
Chad Pytel authored

Showing 26 changed files with 531 additions and 78 deletions. Show diff stats Hide diff stats

  1. +143 0 CHANGELOG
  2. +9 3 README.md
  3. +93 0 README_FOR_HEROKU_ADDON.md
  4. +21 10 Rakefile
  5. +5 5 SUPPORTED_RAILS_VERSIONS
  6. +2 2 features/metal.feature
  7. +23 1 features/rails.feature
  8. +12 1 features/rails_with_js_notifier.feature
  9. +13 0 features/step_definitions/metal_steps.rb
  10. +38 0 features/step_definitions/rails_application_steps.rb
  11. +6 1 features/support/terminal.rb
  12. +25 0 generators/hoptoad/hoptoad_generator.rb
  13. +5 1 lib/hoptoad_notifier.rb
  14. +2 1  lib/hoptoad_notifier/configuration.rb
  15. +9 1 lib/hoptoad_notifier/rails/controller_methods.rb
  16. +6 1 lib/hoptoad_notifier/rails/javascript_notifier.rb
  17. +1 10 lib/hoptoad_notifier/rails3_tasks.rb
  18. +3 1 lib/hoptoad_notifier/railtie.rb
  19. +29 0 lib/hoptoad_notifier/shared_tasks.rb
  20. +1 15 lib/hoptoad_notifier/tasks.rb
  21. +1 1  lib/hoptoad_notifier/version.rb
  22. +25 0 lib/rails/generators/hoptoad/hoptoad_generator.rb
  23. +5 0 lib/templates/javascript_notifier.erb
  24. +2 1  test/helper.rb
  25. +38 0 test/javascript_notifier_test.rb
  26. +14 23 test/notice_test.rb
143 CHANGELOG
... ... @@ -1,3 +1,138 @@
  1 +Version 2.4.2 - Sun Jan 09 09:37:31 -0500 2011
  2 +===============================================================================
  3 +
  4 +Matt Jankowski (1):
  5 + fix issue where the gsub to replace the html head with javascript was removing the head element entirely
  6 +
  7 +
  8 +Version 2.4.1 - Sat Jan 08 12:17:15 -0500 2011
  9 +===============================================================================
  10 +
  11 +Matt Jankowski (1):
  12 + restore method which may have been accidentally removed?
  13 +
  14 +
  15 +Version 2.4.0 - Thu Jan 06 15:03:58 -0500 2011
  16 +===============================================================================
  17 +
  18 +Jason Morrison (1):
  19 + Remove official support for very old Rails version going forward
  20 +
  21 +Version 2.3.14 - Wed Jan 05 14:06:12 -0500 2011
  22 +===============================================================================
  23 +
  24 +Jason Morrison (1):
  25 + Fix 'require' path
  26 +
  27 +Version 2.3.13 - Mon Jan 03 15:56:20 -0500 2011
  28 +===============================================================================
  29 +
  30 +Dan Croak (1):
  31 + including twiddle wakka in install instructions
  32 +
  33 +Emma Lindsay (5):
  34 + Sends more javascript information back to hoptaod
  35 + Merge branch 'js_notifier_default_fields'
  36 + Bumping to version 2.3.10
  37 + Updated jferris-mocha to bourne
  38 + Update readme to show quotes around error names in ignores
  39 +
  40 +Jason Morrison (8):
  41 + wip: Supply default url, component, action for JS notifier
  42 + gracefully fall back to require 'activesupport' if require 'active_support' fails
  43 + Add non-capistrano deploy instructions
  44 + Add instructions for heroku gem to Heroku addon README
  45 + Add AbstractController::ActionNotFound to default ignore list
  46 + Bumping to version 2.3.12
  47 + Bugfix: JS Notifier will now insert itself even when <head> tag has attributes
  48 + Add Heroku deploy notification
  49 +
  50 +Jon Yurek (11):
  51 + Require bourne, run right cucumber task
  52 + Get the API key from Heroku
  53 + Bumped version: 2.3.11
  54 + Getting green cucumber stories
  55 + Fakes out the heroku command for cucumber.
  56 + Mount the metal endpoint in Rails 3 tests.
  57 + Metal test mounts at /metal
  58 + Supported versions: 2.3.9, 2.3.10, and 3.0.1
  59 + Return non-zero on cucumber failure.
  60 + Controller info for older Rails-es is different.
  61 + Remove Rails 2.0.2 from official support. Added 3.0.2+3
  62 +
  63 +Trevor Turk (1):
  64 + Fix default ignores in the README
  65 +
  66 +
  67 +Version 2.3.12 - Wed Nov 03 13:53:18 -0400 2010
  68 +===============================================================================
  69 +
  70 +In general: Update gems, improve testing, improve documentation, improve
  71 +javascript notifier.
  72 +
  73 +Emma Lindsay (4):
  74 + Sends more javascript information back to hoptaod
  75 + Merge branch 'js_notifier_default_fields'
  76 + Bumping to version 2.3.10
  77 + Updated jferris-mocha to bourne
  78 +
  79 +Jason Morrison (5):
  80 + wip: Supply default url, component, action for JS notifier
  81 + gracefully fall back to require 'activesupport' if require 'active_support' fails
  82 + Add non-capistrano deploy instructions
  83 + Add instructions for heroku gem to Heroku addon README
  84 + Add AbstractController::ActionNotFound to default ignore list
  85 +
  86 +Jon Yurek (9):
  87 + Require bourne, run right cucumber task
  88 + Get the API key from Heroku
  89 + Bumped version: 2.3.11
  90 + Getting green cucumber stories
  91 + Fakes out the heroku command for cucumber.
  92 + Mount the metal endpoint in Rails 3 tests.
  93 + Metal test mounts at /metal
  94 + Supported versions: 2.3.9, 2.3.10, and 3.0.1
  95 + Return non-zero on cucumber failure.
  96 +
  97 +
  98 +Version 2.3.10 - Mon Oct 18 17:07:56 -0400 2010
  99 +===============================================================================
  100 +
  101 +Emma Lindsay (2):
  102 + Sends more javascript information back to hoptaod
  103 + Merge branch 'js_notifier_default_fields'
  104 +
  105 +Jason Morrison (2):
  106 + wip: Supply default url, component, action for JS notifier
  107 + gracefully fall back to require 'activesupport' if require 'active_support' fails
  108 +
  109 +
  110 +Version 2.3.9 - 2010-10-18
  111 +===============================================================================
  112 +
  113 +This patch release contains a handful of bugfixes, and ensures:
  114 + If hoptoadapp.com is completely unreachable by HTTP, your app is not affected.
  115 + Controller method #notify_hoptoad is available in Rails 3. Thanks contributor Kyle Crum!
  116 +
  117 +Chad Pytel (1):
  118 + also handle Errno::ECONNREFUSED and other http errors
  119 +
  120 +Jason Morrison (4):
  121 + Add gem versions to test suite
  122 + Revert "Revert "attempt to debug mail sending on staging""
  123 + Adding Heroku notifier readme
  124 + gracefully fall back to require 'activesupport' if require 'active_support' fails
  125 +
  126 +Jon Yurek (2):
  127 + Bumping version to 2.3.8
  128 + Adds builder to the gemspec
  129 +
  130 +Kyle Crum (3):
  131 + notify_hoptoad now works in rails 3 controllers
  132 + more sane way of testing for rails 3 controller methods
  133 + added a scenario for using the notify_hoptoad method within a controller
  134 +
  135 +
1 136 Version 2.3.7 - 2010-09-15
2 137 ===============================================================================
3 138
@@ -235,3 +370,11 @@ Nick Quaranto (3):
235 370
236 371
237 372
  373 +
  374 +
  375 +
  376 +
  377 +
  378 +
  379 +
  380 +
12 README.md
Source Rendered
@@ -36,7 +36,7 @@ Remove the vendor/plugins/hoptoad_notifier directory before installing the gem,
36 36
37 37 Add the hoptoad_notifier gem to your Gemfile. In Gemfile:
38 38
39   - gem 'hoptoad_notifier'
  39 + gem "hoptoad_notifier", "~> 2.3"
40 40
41 41 Then from your project's RAILS_ROOT, run:
42 42
@@ -243,6 +243,11 @@ When Hoptoad is installed as a gem, you need to add
243 243
244 244 to your deploy.rb
245 245
  246 +If you don't use Capistrano, then you can use the following rake task from your
  247 +deployment process to notify Hoptoad:
  248 +
  249 + rake hoptoad:deploy TO=#{rails_env} REVISION=#{current_revision} REPO=#{repository} USER=#{local_user}
  250 +
246 251 Going beyond exceptions
247 252 -----------------------
248 253
@@ -304,6 +309,7 @@ notifications (when #notify is called directly).
304 309
305 310 Hoptoad ignores the following exceptions by default:
306 311
  312 + AbstractController::ActionNotFound
307 313 ActiveRecord::RecordNotFound
308 314 ActionController::RoutingError
309 315 ActionController::InvalidAuthenticityToken
@@ -315,7 +321,7 @@ configuration block.
315 321
316 322 HoptoadNotifier.configure do |config|
317 323 config.api_key = '1234567890abcdef'
318   - config.ignore << ActiveRecord::IgnoreThisError
  324 + config.ignore << "ActiveRecord::IgnoreThisError"
319 325 end
320 326
321 327 To ignore *only* certain errors (and override the defaults), use the
@@ -323,7 +329,7 @@ To ignore *only* certain errors (and override the defaults), use the
323 329
324 330 HoptoadNotifier.configure do |config|
325 331 config.api_key = '1234567890abcdef'
326   - config.ignore_only = [ActiveRecord::IgnoreThisError]
  332 + config.ignore_only = ["ActiveRecord::IgnoreThisError"]
327 333 end
328 334
329 335 To ignore certain user agents, add in the #ignore_user_agent attribute as a
93 README_FOR_HEROKU_ADDON.md
Source Rendered
... ... @@ -0,0 +1,93 @@
  1 +Hoptoad
  2 +===========
  3 +Send your application errors to our hosted service and reclaim your inbox.
  4 +
  5 +1. Installing the Heroku add-on
  6 +----------------------------
  7 +To use Hoptoad on Heroku, install the Hoptoad add-on:
  8 +
  9 + $ heroku addons:add hoptoad:basic # This adds the the basic plan.
  10 + # If you'd like another plan, specify that instead.
  11 +
  12 +2. Including the Hoptoad notifier in your application
  13 +--------------------------------------------------
  14 +After adding the Hoptoad add-on, you will need to install and configure the Hoptoad notifier.
  15 +
  16 +Your application connects to Hoptoad with an API key. On Heroku, this is automatically provided to your
  17 +application in `ENV['HOPTOAD_API_KEY']`, so installation should be a snap!
  18 +
  19 +### Rails 3.x
  20 +
  21 +Add the hoptoad_notifier and heroku gems to your Gemfile. In Gemfile:
  22 +
  23 + gem 'hoptoad_notifier'
  24 + gem 'heroku'
  25 +
  26 +Then from your project's RAILS_ROOT, run:
  27 +
  28 + $ bundle install
  29 + $ script/rails generate hoptoad --heroku
  30 +
  31 +### Rails 2.x
  32 +
  33 +Install the heroku gem if you haven't already:
  34 +
  35 + gem install heroku
  36 +
  37 +Add the hoptoad_notifier gem to your app. In config/environment.rb:
  38 +
  39 + config.gem 'hoptoad_notifier'
  40 +
  41 +Then from your project's RAILS_ROOT, run:
  42 +
  43 + $ rake gems:install
  44 + $ rake gems:unpack GEM=hoptoad_notifier
  45 + $ script/generate hoptoad --heroku
  46 +
  47 +As always, if you choose not to vendor the hoptoad_notifier gem, make sure
  48 +every server you deploy to has the gem installed or your application won't start.
  49 +
  50 +### Rack applications
  51 +
  52 +In order to use hoptoad_notifier in a non-Rails rack app, just load the hoptoad_notifier, configure your API key, and use the HoptoadNotifier::Rack middleware:
  53 +
  54 + require 'rubygems'
  55 + require 'rack'
  56 + require 'hoptoad_notifier'
  57 +
  58 + HoptoadNotifier.configure do |config|
  59 + config.api_key = `ENV['HOPTOAD_API_KEY']`
  60 + end
  61 +
  62 + app = Rack::Builder.app do
  63 + use HoptoadNotifier::Rack
  64 + run lambda { |env| raise "Rack down" }
  65 + end
  66 +
  67 +### Rails 1.x
  68 +
  69 +For Rails 1.x, visit the [Hoptoad notifier's README on GitHub](http://github.com/thoughtbot/hoptoad_notifier),
  70 +and be sure to use `ENV['HOPTOAD_API_KEY']` where your API key is required in configuration code.
  71 +
  72 +3. Configure your notification settings (important!)
  73 +---------------------------------------------------
  74 +
  75 +Once you have included and configured the notifier in your application,
  76 +you will want to configure your notification settings.
  77 +
  78 +This is important - without setting your email address, you won't receive notification emails.
  79 +
  80 +Hoptoad can deliver exception notifications to your email inbox. To configure these delivery settings:
  81 +
  82 +1. Visit your application's Hoptoad Add-on page, like [ http://api.heroku.com/myapps/my-great-app/addons/hoptoad:basic ](http://api.heroku.com/myapps/my-great-app/addons/hoptoad:basic)
  83 +2. Click "Go to Hoptoad admin" to configure the Hoptoad Add-on on the Hoptoadapp.com website
  84 +3. Click the "Profile" button in the header to edit your email address and notification settings.
  85 +
  86 +4. Optionally: Set up deploy notification
  87 +-----------------------------------------
  88 +
  89 +If your Hoptoad plan supports deploy notification, set it up for your Heroku application like this:
  90 +
  91 + rake hoptoad:heroku:add_deploy_notification
  92 +
  93 +This will install a Heroku [HTTP Deploy Hook](http://docs.heroku.com/deploy-hooks) to notify Hoptoad of the deploy.
31 Rakefile
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
5 5 require 'cucumber/rake/task'
6 6
7 7 desc 'Default: run unit tests.'
8   -task :default => [:test, :cucumber]
  8 +task :default => [:test, "cucumber:rails:all"]
9 9
10 10 desc 'Test the hoptoad_notifier gem.'
11 11 Rake::TestTask.new(:test) do |t|
@@ -66,7 +66,7 @@ EOF
66 66
67 67 File.open(file, "w") do |f|
68 68 f.write <<EOF
69   -Version #{version} - #{Date.today}
  69 +Version #{version} - #{Time.now}
70 70 ===============================================================================
71 71
72 72 #{`git log $(git tag | tail -1)..HEAD | git shortlog`}
@@ -123,10 +123,11 @@ 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.add_runtime_dependency("builder")
126 127 s.add_runtime_dependency("activesupport")
127 128 s.add_development_dependency("activerecord")
128 129 s.add_development_dependency("actionpack")
129   - s.add_development_dependency("jferris-mocha")
  130 + s.add_development_dependency("bourne")
130 131 s.add_development_dependency("nokogiri")
131 132 s.add_development_dependency("shoulda")
132 133
@@ -187,22 +188,32 @@ end
187 188
188 189 task :cucumber => [:gemspec, :vendor_test_gems]
189 190
  191 +def run_rails_cucumbr_task(version, additional_cucumber_args)
  192 + puts "Testing Rails #{version}"
  193 + if version.empty?
  194 + raise "No Rails version specified - make sure ENV['RAILS_VERSION'] is set, e.g. with `rake cucumber:rails:all`"
  195 + end
  196 + ENV['RAILS_VERSION'] = version
  197 + system("cucumber --format #{ENV['CUCUMBER_FORMAT'] || 'progress'} #{additional_cucumber_args} features/rails.feature features/rails_with_js_notifier.feature")
  198 +end
  199 +
190 200 def define_rails_cucumber_tasks(additional_cucumber_args = '')
191 201 namespace :rails do
192 202 RAILS_VERSIONS.each do |version|
193 203 desc "Test integration of the gem with Rails #{version}"
194 204 task version => [:gemspec, :vendor_test_gems] do
195   - puts "Testing Rails #{version}"
196   - if version.empty?
197   - raise "No Rails version specified - make sure ENV['RAILS_VERSION'] is set, e.g. with `rake cucumber:rails:all`"
198   - end
199   - ENV['RAILS_VERSION'] = version
200   - system("cucumber --format #{ENV['CUCUMBER_FORMAT'] || 'progress'} #{additional_cucumber_args} features/rails.feature features/rails_with_js_notifier.feature")
  205 + exit 1 unless run_rails_cucumbr_task(version, additional_cucumber_args)
201 206 end
202 207 end
203 208
204 209 desc "Test integration of the gem with all Rails versions"
205   - task :all => RAILS_VERSIONS
  210 + task :all do
  211 + results = RAILS_VERSIONS.map do |version|
  212 + run_rails_cucumbr_task(version, additional_cucumber_args)
  213 + end
  214 +
  215 + exit 1 unless results.all?
  216 + end
206 217 end
207 218 end
208 219
10 SUPPORTED_RAILS_VERSIONS
... ... @@ -1,10 +1,10 @@
1   -1.2.6
2   -2.0.2
3   -2.1.0
4   -2.1.2
5   -2.2.2
6 1 2.3.2
7 2 2.3.4
8 3 2.3.5
9 4 2.3.8
  5 +2.3.9
  6 +2.3.10
10 7 3.0.0
  8 +3.0.1
  9 +3.0.2
  10 +3.0.3
4 features/metal.feature
@@ -14,10 +14,10 @@ Feature: Rescue errors in Rails middleware
14 14 raise "Explode"
15 15 end
16 16 """
17   - When I perform a request to "http://example.com:123/test/index?param=value"
  17 + When I perform a request to "http://example.com:123/metal/index?param=value"
18 18 Then I should receive the following Hoptoad notification:
19 19 | error message | RuntimeError: Explode |
20 20 | error class | RuntimeError |
21 21 | parameters | param: value |
22   - | url | http://example.com:123/test/index?param=value |
  22 + | url | http://example.com:123/metal/index?param=value |
23 23
24 features/rails.feature
@@ -132,8 +132,8 @@ Feature: Install the Gem in a Rails application
132 132 When I generate a new Rails application
133 133 And I configure the Hoptoad shim
134 134 And I configure the Heroku rake shim
  135 + And I configure the Heroku gem shim with "myapikey"
135 136 And I configure my application to require the "hoptoad_notifier" gem
136   - And I set the environment variable "HOPTOAD_API_KEY" to "myapikey"
137 137 And I run the hoptoad generator with "--heroku"
138 138 Then the command should have run successfully
139 139 And I should receive a Hoptoad notification
@@ -215,3 +215,25 @@ Feature: Install the Gem in a Rails application
215 215 | params | secret: [FILTERED] |
216 216 | session | secret: [FILTERED] |
217 217 | url | http://example.com:123/test/index?param=value |
  218 +
  219 + Scenario: Notify hoptoad within the controller
  220 + When I generate a new Rails application
  221 + And I configure the Hoptoad shim
  222 + And I configure my application to require the "hoptoad_notifier" gem
  223 + And I run the hoptoad generator with "-k myapikey"
  224 + And I define a response for "TestController#index":
  225 + """
  226 + session[:value] = "test"
  227 + notify_hoptoad(RuntimeError.new("some message"))
  228 + render :nothing => true
  229 + """
  230 + And I route "/test/index" to "test#index"
  231 + And I perform a request to "http://example.com:123/test/index?param=value"
  232 + Then I should receive the following Hoptoad notification:
  233 + | component | test |
  234 + | action | index |
  235 + | error message | RuntimeError: some message |
  236 + | error class | RuntimeError |
  237 + | session | value: test |
  238 + | parameters | param: value |
  239 + | url | http://example.com:123/test/index?param=value |
13 features/rails_with_js_notifier.feature
@@ -14,13 +14,20 @@ Feature: Install the Gem in a Rails application and enable the JavaScript notifi
14 14 """
15 15 And I define a response for "TestController#index":
16 16 """
17   - render :text => "<html><head></head><body></body></html>"
  17 + render :text => '<html><head profile="http://example.com"></head><body></body></html>'
18 18 """
19 19 And I route "/test/index" to "test#index"
20 20 And I perform a request to "http://example.com:123/test/index"
21 21 Then I should see the notifier JavaScript for the following:
22 22 | api_key | environment | host |
23 23 | myapikey | production | hoptoadapp.com |
  24 + And the notifier JavaScript should provide the following errorDefaults:
  25 + | url | component | action |
  26 + | http://example.com:123/test/index | test | index |
  27 + And I should see the following value as the html head:
  28 + """
  29 + <head profile="http://example.com">
  30 + """
24 31
25 32 Scenario: Include the Javascript notifier when enabled using custom configuration settings
26 33 When I generate a new Rails application
@@ -42,6 +49,10 @@ Feature: Install the Gem in a Rails application and enable the JavaScript notifi
42 49 Then I should see the notifier JavaScript for the following:
43 50 | api_key | environment | host |
44 51 | myapikey! | production | myhoptoad.com:3001 |
  52 + And I should see the following value as the html head:
  53 + """
  54 + <head>
  55 + """
45 56
46 57 Scenario: Don't include the Javascript notifier by default
47 58 When I generate a new Rails application
13 features/step_definitions/metal_steps.rb
@@ -6,5 +6,18 @@
6 6 file.puts definition
7 7 file.puts "end"
8 8 end
  9 + When %{the metal endpoint "#{class_name}" is mounted in the Rails 3 routes.rb} if rails3?
9 10 end
10 11
  12 +When /^the metal endpoint "([^\"]*)" is mounted in the Rails 3 routes.rb$/ do |class_name|
  13 + routesrb = File.join(RAILS_ROOT, "config", "routes.rb")
  14 + routes = IO.readlines(routesrb)
  15 + rack_route = "match '/metal(/*other)' => #{class_name}"
  16 + routes = routes[0..-2] + [rack_route, routes[-1]]
  17 + File.open(routesrb, "w") do |f|
  18 + f.puts "require 'app/metal/#{class_name.underscore}'"
  19 + routes.each do |route_line|
  20 + f.puts route_line
  21 + end
  22 + end
  23 +end
38 features/step_definitions/rails_application_steps.rb
@@ -34,6 +34,10 @@
34 34 end
35 35 end
36 36
  37 +When /^I print the console output$/ do
  38 + puts @terminal.output
  39 +end
  40 +
37 41 Given /^I have installed the "([^\"]*)" gem$/ do |gem_name|
38 42 @terminal.install_gem(gem_name)
39 43 end
@@ -289,6 +293,20 @@ def rails_non_initializer_hoptoad_config_file
289 293 @terminal.invoke_heroku_rake_tasks_locally = true
290 294 end
291 295
  296 +When /^I configure the Heroku gem shim with "([^\"]*)"$/ do |api_key|
  297 + heroku_script_bin = File.join(TEMP_DIR, "bin")
  298 + FileUtils.mkdir_p(heroku_script_bin)
  299 + heroku_script = File.join(heroku_script_bin, "heroku")
  300 + File.open(heroku_script, "w") do |f|
  301 + f.puts "#!/bin/bash"
  302 + f.puts "if [[ $1 == 'console' && $2 == 'puts ENV[%{HOPTOAD_API_KEY}]' ]]; then"
  303 + f.puts " echo #{api_key}"
  304 + f.puts "fi"
  305 + end
  306 + FileUtils.chmod(0755, heroku_script)
  307 + @terminal.prepend_path(heroku_script_bin)
  308 +end
  309 +
292 310 When /^I configure the application to filter parameter "([^\"]*)"$/ do |parameter|
293 311 if rails3?
294 312 application_filename = File.join(RAILS_ROOT, 'config', 'application.rb')
@@ -338,6 +356,26 @@ def rails_non_initializer_hoptoad_config_file
338 356 end
339 357 end
340 358
  359 +Given /^I should see the following value as the html head:$/ do |value|
  360 + document_body = '<html>' + @terminal.output.split('<html>').last
  361 + document_body.should include(value.strip)
  362 +end
  363 +
  364 +Then "the notifier JavaScript should provide the following errorDefaults:" do |table|
  365 + hash = table.hashes.first
  366 +
  367 + document_body = '<html>' + @terminal.output.split('<html>').last
  368 +
  369 + response = Nokogiri::HTML.parse(document_body)
  370 + response.css("script[type='text/javascript']:last-child").each do |element|
  371 + content = element.content
  372 +
  373 + hash.each do |key, value|
  374 + content.should =~ %r{Hoptoad\.setErrorDefaults.*#{key}: "#{value}}m
  375 + end
  376 + end
  377 +end
  378 +
341 379 Then /^I should not see notifier JavaScript$/ do
342 380 response = Nokogiri::HTML.parse('<html>' + @terminal.output.split('<html>').last)
343 381 response.at_css("script[type='text/javascript'][src$='/javascripts/notifier.js']").should be_nil
7 features/support/terminal.rb
@@ -32,7 +32,8 @@ def run(command)
32 32
33 33 output << "#{command}\n"
34 34 FileUtils.cd(@cwd) do
35   - cmdline = "#{environment_settings} #{command} 2>&1"
  35 + # The ; forces ruby to shell out so the env settings work right
  36 + cmdline = "#{environment_settings} #{command} 2>&1 ; "
36 37 logger.debug(cmdline)
37 38 result = `#{cmdline}`
38 39 logger.debug(result)
@@ -74,6 +75,10 @@ def uninstall_gem(gem)
74 75 `gem uninstall -i #{BUILT_GEM_ROOT} #{gem}`
75 76 end
76 77
  78 + def prepend_path(path)
  79 + @environment_variables['PATH'] = path + ":" + @environment_variables['PATH']
  80 + end
  81 +
77 82 private
78 83
79 84 def install_gem_to(root, gem)
25 generators/hoptoad/hoptoad_generator.rb
@@ -32,6 +32,7 @@ def manifest
32 32 m.append_to 'config/environment.rb', "require 'config/hoptoad'"
33 33 end
34 34 end
  35 + determine_api_key if heroku?
35 36 m.rake "hoptoad:test --trace", :generate_only => true
36 37 end
37 38 end
@@ -44,6 +45,30 @@ def api_key_expression
44 45 end
45 46 end
46 47
  48 + def determine_api_key
  49 + puts "Attempting to determine your API Key from Heroku..."
  50 + ENV['HOPTOAD_API_KEY'] = heroku_api_key
  51 + if ENV['HOPTOAD_API_KEY'].blank?
  52 + puts "... Failed."
  53 + puts "WARNING: We were unable to detect the Hoptoad API Key from your Heroku environment."
  54 + puts "Your Heroku application environment may not be configured correctly."
  55 + exit 1
  56 + else
  57 + puts "... Done."
  58 + puts "Heroku's Hoptoad API Key is '#{ENV['HOPTOAD_API_KEY']}'"
  59 + end
  60 + end
  61 +
  62 + def heroku_api_key
  63 + `heroku console 'puts ENV[%{HOPTOAD_API_KEY}]'`.split("\n").first
  64 + end
  65 +
  66 + def heroku?
  67 + options[:heroku] ||
  68 + system("grep HOPTOAD_API_KEY config/initializers/hoptoad.rb") ||
  69 + system("grep HOPTOAD_API_KEY config/environment.rb")
  70 + end
  71 +
47 72 def use_initializer?
48 73 Rails::VERSION::MAJOR > 1
49 74 end
6 lib/hoptoad_notifier.rb
... ... @@ -1,7 +1,11 @@
1 1 require 'net/http'
2 2 require 'net/https'
3 3 require 'rubygems'
4   -require 'active_support'
  4 +begin
  5 + require 'active_support'
  6 +rescue LoadError
  7 + require 'activesupport'
  8 +end
5 9 require 'hoptoad_notifier/version'
6 10 require 'hoptoad_notifier/configuration'
7 11 require 'hoptoad_notifier/notice'
3  lib/hoptoad_notifier/configuration.rb
@@ -111,7 +111,8 @@ class Configuration
111 111 'ActionController::RoutingError',
112 112 'ActionController::InvalidAuthenticityToken',
113 113 'CGI::Session::CookieStore::TamperedWithCookie',
114   - 'ActionController::UnknownAction']
  114 + 'ActionController::UnknownAction',
  115 + 'AbstractController::ActionNotFound']
115 116
116 117 alias_method :secure?, :secure
117 118
10 lib/hoptoad_notifier/rails/controller_methods.rb
@@ -6,10 +6,18 @@ module ControllerMethods
6 6 # This method should be used for sending manual notifications while you are still
7 7 # inside the controller. Otherwise it works like HoptoadNotifier.notify.
8 8 def notify_hoptoad(hash_or_exception)
9   - unless consider_all_requests_local || local_request?
  9 + unless hoptoad_local_request?
10 10 HoptoadNotifier.notify(hash_or_exception, hoptoad_request_data)
11 11 end
12 12 end
  13 +
  14 + def hoptoad_local_request?
  15 + if defined?(::Rails.application.config)
  16 + ::Rails.application.config.consider_all_requests_local || request.local?
  17 + else
  18 + consider_all_requests_local || local_request?
  19 + end
  20 + end
13 21
14 22 def hoptoad_ignore_user_agent? #:nodoc:
15 23 # Rails 1.2.6 doesn't have request.user_agent, so check for it here
7 lib/hoptoad_notifier/rails/javascript_notifier.rb
@@ -34,9 +34,14 @@ def insert_hoptoad_javascript_notifier
34 34 end
35 35
36 36 if response.body.respond_to?(:gsub)
37   - response.body = response.body.gsub(/<(head)>/i, "<\\1>\n" + javascript)
  37 + response.body = insert_javascript_after_head response.body, javascript
38 38 end
39 39 end
  40 +
  41 + def insert_javascript_after_head(body, javascript)
  42 + body.gsub /<(head.*?)>/i, "<\\1>\n#{javascript}\n"
  43 + end
  44 +
40 45 end
41 46 end
42 47 end
11 lib/hoptoad_notifier/rails3_tasks.rb
... ... @@ -1,16 +1,7 @@
1 1 require 'hoptoad_notifier'
  2 +require File.join(File.dirname(__FILE__), 'shared_tasks')
2 3
3 4 namespace :hoptoad do
4   - desc "Notify Hoptoad of a new deploy."
5   - task :deploy => :environment do
6   - require 'hoptoad_tasks'
7   - HoptoadTasks.deploy(:rails_env => ENV['TO'],
8   - :scm_revision => ENV['REVISION'],
9   - :scm_repository => ENV['REPO'],
10   - :local_username => ENV['USER'],
11   - :api_key => ENV['API_KEY'])
12   - end
13   -
14 5 desc "Verify your gem installation by sending a test exception to the hoptoad service"
15 6 task :test => [:environment] do
16 7 Rails.logger = Logger.new(STDOUT)
4 lib/hoptoad_notifier/railtie.rb
@@ -21,7 +21,9 @@ class Railtie < Rails::Railtie
21 21
22 22 if defined?(::ActionController::Base)
23 23 require 'hoptoad_notifier/rails/javascript_notifier'
24   -
  24 + require 'hoptoad_notifier/rails/controller_methods'
  25 +
  26 + ::ActionController::Base.send(:include, HoptoadNotifier::Rails::ControllerMethods)
25 27 ::ActionController::Base.send(:include, HoptoadNotifier::Rails::JavascriptNotifier)
26 28 end
27 29 end
29 lib/hoptoad_notifier/shared_tasks.rb
... ... @@ -0,0 +1,29 @@
  1 +namespace :hoptoad do
  2 + desc "Notify Hoptoad of a new deploy."
  3 + task :deploy => :environment do
  4 + require 'hoptoad_tasks'
  5 + HoptoadTasks.deploy(:rails_env => ENV['TO'],
  6 + :scm_revision => ENV['REVISION'],
  7 + :scm_repository => ENV['REPO'],
  8 + :local_username => ENV['USER'],
  9 + :api_key => ENV['API_KEY'])
  10 + end
  11 +
  12 + task :log_stdout do
  13 + require 'logger'
  14 + RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
  15 + end
  16 +
  17 + namespace :heroku do
  18 + desc "Install Heroku deploy notifications addon"
  19 + task :add_deploy_notification => [:environment] do
  20 + heroku_api_key = `heroku console 'puts ENV[%{HOPTOAD_API_KEY}]' | head -n 1`.strip
  21 + heroku_rails_env = `heroku console 'puts RAILS_ENV' | head -n 1`.strip
  22 +
  23 + command = %Q(heroku addons:add deployhooks:http url="http://hoptoadapp.com/deploys.txt?deploy[rails_env]=#{heroku_rails_env}&api_key=#{heroku_api_key}")
  24 +
  25 + puts "\nRunning:\n#{command}\n"
  26 + puts `#{command}`
  27 + end
  28 + end
  29 +end
16 lib/hoptoad_notifier/tasks.rb
... ... @@ -1,21 +1,7 @@
1 1 require 'hoptoad_notifier'
  2 +require File.join(File.dirname(__FILE__), 'shared_tasks')
2 3
3 4 namespace :hoptoad do
4   - desc "Notify Hoptoad of a new deploy."
5   - task :deploy => :environment do
6   - require 'hoptoad_tasks'
7   - HoptoadTasks.deploy(:rails_env => ENV['TO'],
8   - :scm_revision => ENV['REVISION'],
9   - :scm_repository => ENV['REPO'],
10   - :local_username => ENV['USER'],
11   - :api_key => ENV['API_KEY'])
12   - end
13   -
14   - task :log_stdout do
15   - require 'logger'
16   - RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
17   - end
18   -
19 5 desc "Verify your gem installation by sending a test exception to the hoptoad service"
20 6 task :test => ['hoptoad:log_stdout', :environment] do
21 7 RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
2  lib/hoptoad_notifier/version.rb
... ... @@ -1,3 +1,3 @@
1 1 module HoptoadNotifier
2   - VERSION = "2.3.7".freeze
  2 + VERSION = "2.4.2".freeze
3 3 end
25 lib/rails/generators/hoptoad/hoptoad_generator.rb
@@ -14,6 +14,7 @@ def install
14 14 ensure_plugin_is_not_present
15 15 append_capistrano_hook
16 16 generate_initializer unless api_key_configured?
  17 + determine_api_key if heroku?
17 18 test_hoptoad
18 19 end
19 20
@@ -55,6 +56,30 @@ def generate_initializer
55 56 template 'initializer.rb', 'config/initializers/hoptoad.rb'
56 57 end
57 58
  59 + def determine_api_key
  60 + puts "Attempting to determine your API Key from Heroku..."
  61 + ENV['HOPTOAD_API_KEY'] = heroku_api_key
  62 + if ENV['HOPTOAD_API_KEY'].blank?
  63 + puts "... Failed."
  64 + puts "WARNING: We were unable to detect the Hoptoad API Key from your Heroku environment."
  65 + puts "Your Heroku application environment may not be configured correctly."
  66 + exit 1
  67 + else
  68 + puts "... Done."
  69 + puts "Heroku's Hoptoad API Key is '#{ENV['HOPTOAD_API_KEY']}'"
  70 + end
  71 + end
  72 +
  73 + def heroku_api_key
  74 + `heroku console 'puts ENV[%{HOPTOAD_API_KEY}]'`.split("\n").first
  75 + end
  76 +
  77 + def heroku?
  78 + options[:heroku] ||
  79 + system("grep HOPTOAD_API_KEY config/initializers/hoptoad.rb") ||
  80 + system("grep HOPTOAD_API_KEY config/environment.rb")
  81 + end
  82 +
58 83 def api_key_configured?
59 84 File.exists?('config/initializers/hoptoad.rb')
60 85 end
5 lib/templates/javascript_notifier.erb
@@ -9,4 +9,9 @@ document.write(unescape("%3Cscript src='" + notifierJsScheme + "<%= host %>/java
9 9 Hoptoad.setKey('<%= api_key %>');
10 10 Hoptoad.setHost('<%= host %>');
11 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 + });
12 17 </script>
3  test/helper.rb
@@ -6,7 +6,7 @@
6 6 gem "actionpack", "= 2.3.8"
7 7 gem "nokogiri", "= 1.4.3.1"
8 8 gem "shoulda", "= 2.11.3"
9   -gem 'jferris-mocha', '>= 0.9.5.0.1241126838'
  9 +gem 'bourne', '>= 1.0'
10 10
11 11 $LOAD_PATH << File.join(File.dirname(__FILE__), *%w[.. vendor ginger lib])
12 12 $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
@@ -24,6 +24,7 @@
24 24 require 'active_support'
25 25 require 'nokogiri'
26 26 require 'rack'
  27 +require 'bourne'
27 28
28 29 require "hoptoad_notifier"
29 30
38 test/javascript_notifier_test.rb
... ... @@ -0,0 +1,38 @@
  1 +require File.dirname(__FILE__) + '/helper'
  2 +
  3 +require 'hoptoad_notifier/rails/javascript_notifier'
  4 +
  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
  22 + end
  23 +
  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
  36 + end
  37 +
  38 +end
37 test/notice_test.rb
@@ -310,29 +310,20 @@ def stub_request(attrs = {})
310 310 end
311 311 end
312 312
313   - should "ignore RecordNotFound error by default" do
314   - notice = build_notice(:error_class => 'ActiveRecord::RecordNotFound')
315   - assert notice.ignore?
316   - end
317   -
318   - should "ignore RoutingError error by default" do
319   - notice = build_notice(:error_class => 'ActionController::RoutingError')
320   - assert notice.ignore?
321   - end
322   -
323   - should "ignore InvalidAuthenticityToken error by default" do
324   - notice = build_notice(:error_class => 'ActionController::InvalidAuthenticityToken')
325   - assert notice.ignore?
326   - end
327   -
328   - should "ignore TamperedWithCookie error by default" do
329   - notice = build_notice(:error_class => 'CGI::Session::CookieStore::TamperedWithCookie')
330   - assert notice.ignore?
331   - end
332   -
333   - should "ignore UnknownAction error by default" do
334   - notice = build_notice(:error_class => 'ActionController::UnknownAction')
335   - assert notice.ignore?
  313 + ignored_error_classes = %w(
  314 + ActiveRecord::RecordNotFound
  315 + AbstractController::ActionNotFound
  316 + ActionController::RoutingError
  317 + ActionController::InvalidAuthenticityToken
  318 + CGI::Session::CookieStore::TamperedWithCookie
  319 + ActionController::UnknownAction
  320 + )
  321 +
  322 + ignored_error_classes.each do |ignored_error_class|
  323 + should "ignore #{ignored_error_class} error by default" do
  324 + notice = build_notice(:error_class => ignored_error_class)
  325 + assert notice.ignore?
  326 + end
336 327 end
337 328
338 329 should "act like a hash" do

0 comments on commit 5dfa7fc

Please sign in to comment.
Something went wrong with that request. Please try again.