From 58fc0ee452ea946e646bda2837cc9355b02b7384 Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Thu, 4 Feb 2016 00:31:09 +0000 Subject: [PATCH] Detect release before application initializers run This allows users to override the detected release in an initializer. The before_initialize hook was added in Rails 3.0, which is the oldest version we support. Both Rails.logger and Rails.root are available when it runs. --- lib/raven/integrations/rails.rb | 2 +- spec/raven/integrations/rails_spec.rb | 13 +++++++++++++ spec/support/test_rails_app/app.rb | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/raven/integrations/rails.rb b/lib/raven/integrations/rails.rb index c499d8b3b..e324f72af 100644 --- a/lib/raven/integrations/rails.rb +++ b/lib/raven/integrations/rails.rb @@ -13,7 +13,7 @@ class Rails < ::Rails::Railtie end end - config.after_initialize do + config.before_initialize do Raven.configure do |config| config.logger ||= ::Rails.logger config.project_root ||= ::Rails.root diff --git a/spec/raven/integrations/rails_spec.rb b/spec/raven/integrations/rails_spec.rb index 0de02efb3..66ada6c71 100644 --- a/spec/raven/integrations/rails_spec.rb +++ b/spec/raven/integrations/rails_spec.rb @@ -7,6 +7,7 @@ Raven.configure do |config| config.dsn = 'dummy://notaserver' config.encoding = 'json' + config.logger = nil end Rails.env = "production" TestApp.initialize! @@ -35,4 +36,16 @@ expect(event['request']['url']).to eq("http://www.example.com/exception") end + + it "sets Raven.configuration.logger correctly" do + expect(Raven.configuration.logger).to eq(Rails.logger) + end + + it "sets Raven.configuration.project_root correctly" do + expect(Raven.configuration.project_root).to eq(Rails.root) + end + + it "doesn't clobber a manually configured release" do + expect(Raven.configuration.release).to eq('beta') + end end diff --git a/spec/support/test_rails_app/app.rb b/spec/support/test_rails_app/app.rb index ba980c6ef..2b199d9e9 100644 --- a/spec/support/test_rails_app/app.rb +++ b/spec/support/test_rails_app/app.rb @@ -25,6 +25,12 @@ class TestApp < Rails::Application get "/exception", :to => "hello#exception" root :to => "hello#world" end + + initializer :configure_release do + Raven.configure do |config| + config.release = 'beta' + end + end end class HelloController < ActionController::Base