From 444059a16ace054d94c38435dfab05fae27220a1 Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Thu, 27 Jan 2011 18:44:33 -0300 Subject: [PATCH] Notify exceptions by email --- INSTALL | 20 +++++++++++++++++++- config/initializers/01_load_config.rb | 2 ++ config/initializers/exception_notification.rb | 7 +++++++ config/initializers/load_config.rb | 2 -- config/noosfero.yml.dist | 1 + test/integration/exception_notification_test.rb | 28 ++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 config/initializers/01_load_config.rb create mode 100644 config/initializers/exception_notification.rb delete mode 100644 config/initializers/load_config.rb create mode 100644 test/integration/exception_notification_test.rb diff --git a/INSTALL b/INSTALL index 0fc02c2..1018c91 100644 --- a/INSTALL +++ b/INSTALL @@ -215,6 +215,24 @@ At this point you have a functional Noosfero installation running, the only thing left is to configure your webserver as a reverse proxy to pass requests to them. +Enabling exception notifications +================================ + +This is an optional step. You will need it only if you want to receive e-mail +notifications when some exception occurs on Noosfero. + +First, install this version of the gem. +Others versions may not be compatible with Noosfero: + +# gem install exception_notification -v 1.0.20090728 + +You can configure the e-mails that will receive the notifications. +Change the file config/noosfero.yml as the following example, replacing the +e-mails by real ones: + + production: + exception_recipients: [admin@example.com, you@example.com] + ================== Apache instalation ================== @@ -224,7 +242,7 @@ Apache instalation Apache configuration -------------------- -Firts you have to enable the following some apache modules: +First you have to enable the following some apache modules: deflate expires diff --git a/config/initializers/01_load_config.rb b/config/initializers/01_load_config.rb new file mode 100644 index 0000000..f1e5dd2 --- /dev/null +++ b/config/initializers/01_load_config.rb @@ -0,0 +1,2 @@ +file = "#{RAILS_ROOT}/config/noosfero.yml" +NOOSFERO_CONF = File.exists?(file) ? YAML.load_file(file)[RAILS_ENV] || {} : {} diff --git a/config/initializers/exception_notification.rb b/config/initializers/exception_notification.rb new file mode 100644 index 0000000..7ba2fab --- /dev/null +++ b/config/initializers/exception_notification.rb @@ -0,0 +1,7 @@ +unless NOOSFERO_CONF['exception_recipients'].blank? + require 'exception_notification.rb' + ExceptionNotifier.sender_address = "noreply@#{Environment.default.default_hostname}" + ExceptionNotifier.email_prefix = "[Noosfero ERROR] " + ExceptionNotifier.exception_recipients = NOOSFERO_CONF['exception_recipients'] + ActionController::Base.send :include, ExceptionNotifiable +end diff --git a/config/initializers/load_config.rb b/config/initializers/load_config.rb deleted file mode 100644 index f1e5dd2..0000000 --- a/config/initializers/load_config.rb +++ /dev/null @@ -1,2 +0,0 @@ -file = "#{RAILS_ROOT}/config/noosfero.yml" -NOOSFERO_CONF = File.exists?(file) ? YAML.load_file(file)[RAILS_ENV] || {} : {} diff --git a/config/noosfero.yml.dist b/config/noosfero.yml.dist index 4d5e657..5a9fcd1 100644 --- a/config/noosfero.yml.dist +++ b/config/noosfero.yml.dist @@ -7,6 +7,7 @@ development: addthis_options: favorites, email, digg, delicious, technorati, slashdot, twitter, more gravatar: wavatar googlemaps_initial_zoom: 4 + exception_recipients: [admin@example.com] test: diff --git a/test/integration/exception_notification_test.rb b/test/integration/exception_notification_test.rb new file mode 100644 index 0000000..0b2f106 --- /dev/null +++ b/test/integration/exception_notification_test.rb @@ -0,0 +1,28 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'account_controller' +require 'exception_notification.rb' +ActionController::Base.send :include, ExceptionNotifiable +ExceptionNotifier.exception_recipients = ['admin@example.com', 'user@example.com'] + +class ExceptionNotificationTest < ActionController::IntegrationTest + def setup + ActionMailer::Base.delivery_method = :test + ActionMailer::Base.perform_deliveries = true + ActionMailer::Base.deliveries = [] + AccountController.any_instance.stubs(:signup).raises(RuntimeError) + AccountController.any_instance.stubs(:local_request?).returns(false) + AccountController.any_instance.stubs(:consider_all_requests_local).returns(false) + end + + should 'deliver mail notification about exceptions' do + assert_difference ActionMailer::Base.deliveries, :size do + get '/account/signup' + end + end + + should 'deliver mails to addresses listed in Noosfero configuration noosfero.yml' do + get '/account/signup' + assert_includes ActionMailer::Base.deliveries.map(&:to).flatten, 'admin@example.com' + assert_includes ActionMailer::Base.deliveries.map(&:to).flatten, 'user@example.com' + end +end -- libgit2 0.21.2