lib/rollbar/rake_tasks.rb in rollbar-2.11.5 vs lib/rollbar/rake_tasks.rb in rollbar-2.12.0
- old
+ new
@@ -1,72 +1,98 @@
require 'rollbar'
+require 'rack/mock'
require 'logger'
namespace :rollbar do
- desc "Verify your gem installation by sending a test exception to Rollbar"
+ desc 'Verify your gem installation by sending a test exception to Rollbar'
task :test => [:environment] do
- Rails.logger = defined?(ActiveSupport::TaggedLogging) ?
- ActiveSupport::TaggedLogging.new(Logger.new(STDOUT)) :
- Logger.new(STDOUT)
+ if defined?(Rails)
+ Rails.logger = if defined?(ActiveSupport::TaggedLogging)
+ ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
+ else
+ Logger.new(STDOUT)
+ end
- Rails.logger.level = Logger::DEBUG
- Rollbar.preconfigure do |config|
- config.logger = Rails.logger
+ Rails.logger.level = Logger::DEBUG
+ Rollbar.preconfigure do |config|
+ config.logger = Rails.logger
+ end
end
class RollbarTestingException < RuntimeError; end
unless Rollbar.configuration.access_token
- puts "Rollbar needs an access token configured. Check the README for instructions."
+ puts 'Rollbar needs an access token configured. Check the README for instructions.'
+
exit
end
+ puts 'Testing manual report...'
Rollbar.error('Test error from rollbar:test')
- begin
- require './app/controllers/application_controller'
- rescue LoadError
- end
+ # Module to inject into the Rails controllers or
+ # rack apps
+ module RollbarTest
+ def test_rollbar
+ puts 'Raising RollbarTestingException to simulate app failure.'
- unless defined?(ApplicationController)
- puts "No ApplicationController found, using ActionController::Base instead"
- class ApplicationController < ActionController::Base; end
+ raise RollbarTestingException.new, 'Testing rollbar with "rake rollbar:test". If you can see this, it works.'
+ end
end
- puts "Setting up the controller."
- class ApplicationController
- prepend_before_filter :test_rollbar
- def test_rollbar
- puts "Raising RollbarTestingException to simulate app failure."
- raise RollbarTestingException.new, 'Testing rollbar with "rake rollbar:test". If you can see this, it works.'
+ if defined?(Rails)
+ begin
+ require './app/controllers/application_controller'
+ rescue LoadError
end
- def verify
+ unless defined?(ApplicationController)
+ puts 'No ApplicationController found, using ActionController::Base instead'
+ class ApplicationController < ActionController::Base; end
end
- def logger
- nil
+ puts 'Setting up the controller.'
+
+ class RollbarTestController < ApplicationController
+ include RollbarTest
+
+ def verify
+ test_rollbar
+ end
+
+ def logger
+ nil
+ end
end
- end
- class RollbarTestController < ApplicationController; end
+ Rails.application.routes_reloader.execute_if_updated
+ Rails.application.routes.draw do
+ get 'verify' => 'rollbar_test#verify', :as => 'verify'
+ end
- Rails.application.routes_reloader.execute_if_updated
- Rails.application.routes.draw do
- get 'verify' => 'application#verify', :as => 'verify'
- end
+ # from http://stackoverflow.com/questions/5270835/authlogic-activation-problems
+ if defined? Authlogic
+ Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
+ end
- # from http://stackoverflow.com/questions/5270835/authlogic-activation-problems
- if defined? Authlogic
- Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
+ protocol = (defined? Rails.application.config.force_ssl && Rails.application.config.force_ssl) ? 'https' : 'http'
+ app = Rails.application
+ else
+ protocol = 'http'
+ app = Class.new do
+ include RollbarTest
+
+ def self.call(_env)
+ new.test_rollbar
+ end
+ end
end
- puts "Processing..."
- protocol = (defined? Rails.application.config.force_ssl && Rails.application.config.force_ssl) ? 'https' : 'http'
+ puts 'Processing...'
env = Rack::MockRequest.env_for("#{protocol}://www.example.com/verify")
- status, headers, response = Rails.application.call(env)
+ status, = app.call(env)
unless status.to_i == 500
- puts "Test failed! You may have a configuration issue, or you could be using a gem that's blocking the test. Contact support@rollbar.com if you need help troubleshooting."
+ puts 'Test failed! You may have a configuration issue, or you could be using a gem that\'s blocking the test. Contact support@rollbar.com if you need help troubleshooting.'
end
end
end