super_exception_notifier 3.0.13 → 3.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,89 +0,0 @@
1
- module Rails
2
- def self.public_path
3
- File.dirname(__FILE__)
4
- end
5
-
6
- def self.env
7
- 'test'
8
- end
9
- end
10
-
11
- class ApplicationController < ActionController::Base
12
-
13
- def runtime_error
14
- raise "This is a runtime error that we should be emailed about"
15
- end
16
-
17
- def ar_record_not_found
18
- #From SuperExceptionNotifier::CustomExceptionMethods
19
- record_not_found
20
- end
21
-
22
- def name_error
23
- raise NameError
24
- end
25
-
26
- def unknown_controller
27
- raise ActionController::UnknownController
28
- end
29
-
30
- def local_request?
31
- false
32
- end
33
-
34
- end
35
-
36
- class SpecialErrorThing < RuntimeError
37
- end
38
-
39
- class BasicController < ApplicationController
40
- include ExceptionNotification::ExceptionNotifiable
41
- self.exception_notifiable_noisy_environments = ['test']
42
- end
43
-
44
- class CustomSilentExceptions < ApplicationController
45
- include ExceptionNotification::ExceptionNotifiable
46
- self.exception_notifiable_noisy_environments = ['test']
47
- self.exception_notifiable_verbose = false
48
- self.exception_notifiable_silent_exceptions = [RuntimeError]
49
- end
50
-
51
- class EmptySilentExceptions < ApplicationController
52
- include ExceptionNotification::ExceptionNotifiable
53
- self.exception_notifiable_noisy_environments = ['test']
54
- self.exception_notifiable_verbose = false
55
- self.exception_notifiable_silent_exceptions = []
56
- end
57
-
58
- class NilSilentExceptions < ApplicationController
59
- include ExceptionNotification::ExceptionNotifiable
60
- self.exception_notifiable_noisy_environments = ['test']
61
- self.exception_notifiable_verbose = false
62
- self.exception_notifiable_silent_exceptions = nil
63
- end
64
-
65
- class DefaultSilentExceptions < ApplicationController
66
- include ExceptionNotification::ExceptionNotifiable
67
- self.exception_notifiable_noisy_environments = ['test']
68
- self.exception_notifiable_verbose = false
69
- end
70
-
71
- class OldStyle < ApplicationController
72
- include ExceptionNotification::ExceptionNotifiable
73
- self.exception_notifiable_noisy_environments = ['test']
74
- self.exception_notifiable_verbose = false
75
- end
76
-
77
- class NewStyle < ApplicationController
78
- include ExceptionNotification::ExceptionNotifiable
79
- self.exception_notifiable_noisy_environments = ['test']
80
- self.exception_notifiable_verbose = false
81
-
82
- rescue_from ActiveRecord::RecordNotFound do |exception|
83
- render :text => "404", :status => 404
84
- end
85
-
86
- rescue_from RuntimeError do |exception|
87
- render :text => "500", :status => 500
88
- end
89
- end
@@ -1,79 +0,0 @@
1
- # This is to test the ability to handle exceptions raised outside of the request response cycle
2
- require File.expand_path(File.dirname(__FILE__) + '/test_helper')
3
- require 'test/unit'
4
-
5
- class Spaceship
6
- # It is included by the init.rb in the Object super class,
7
- # so we don't actually need to do anything to get notifiable { method } goodness.
8
- #include ExceptionNotifiable.rb
9
- end
10
-
11
- class SpaceCarrier < Spaceship
12
- end
13
-
14
- class NotifiableTest < Test::Unit::TestCase
15
-
16
- def setup
17
- @@delivered_mail = []
18
- ActionMailer::Base.class_eval do
19
- def deliver!(mail = @mail)
20
- @@delivered_mail << mail
21
- end
22
- end
23
- end
24
-
25
- def test_notifiable_in_noisy_environment
26
- @class = Spaceship.new
27
- Spaceship.notifiable_noisy_environments = ['test']
28
- ExceptionNotification::Notifier.config[:skip_local_notification] = true
29
- assert_raises( AccessDenied ) {
30
- notifiable { @class.access_denied }
31
- assert_error_mail_contains("AccessDenied")
32
- }
33
- end
34
-
35
- def test_notifiable_in_quiet_environment_not_skipping_local
36
- @class = Spaceship.new
37
- Spaceship.notifiable_noisy_environments = []
38
- ExceptionNotification::Notifier.config[:skip_local_notification] = false
39
- assert_raises( AccessDenied ) {
40
- notifiable { @class.access_denied }
41
- assert_error_mail_contains("AccessDenied")
42
- }
43
- end
44
-
45
- def test_notifiable_in_quiet_environment_skipping_local
46
- @class = Spaceship.new
47
- Spaceship.notifiable_noisy_environments = []
48
- ExceptionNotification::Notifier.config[:skip_local_notification] = true
49
- assert_raises( AccessDenied ) {
50
- notifiable { @class.access_denied }
51
- assert_nothing_mailed
52
- }
53
- end
54
-
55
- private
56
-
57
- def assert_view_path_for_status_cd_is_string(status)
58
- assert(ExceptionNotification::Notifier.get_view_path_for_status_code(status).is_a?(String), "View Path is not a string for status code '#{status}'")
59
- end
60
-
61
- def assert_view_path_for_class_is_string(exception)
62
- assert(ExceptionNotification::Notifier.get_view_path_for_class(exception).is_a?(String), "View Path is not a string for exception '#{exception}'")
63
- end
64
-
65
- def assert_error_mail_contains(text)
66
- assert(mailed_error.index(text),
67
- "Expected mailed error body to contain '#{text}', but not found. \n actual contents: \n#{mailed_error}")
68
- end
69
-
70
- def assert_nothing_mailed
71
- assert @@delivered_mail.empty?, "Expected to have NOT mailed out a notification about an error occuring, but mailed: \n#{@@delivered_mail}"
72
- end
73
-
74
- def mailed_error
75
- assert @@delivered_mail.last, "Expected to have mailed out a notification about an error occuring, but none mailed"
76
- @@delivered_mail.last.encoded
77
- end
78
-
79
- end
data/test/test_helper.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
-
4
- require 'rake'
5
- require 'rake/tasklib'
6
- require 'action_mailer'
7
- require 'active_record'
8
-
9
- #just requiring active record wasn't loading classes soon enough for SILENT_EXCEPTIONS
10
- ActiveRecord::Base
11
-
12
- require 'action_controller'
13
- require 'action_controller/test_case'
14
- require 'action_controller/test_process'
15
-
16
- #just requiring action controller wasn't loading classes soon enough for SILENT_EXCEPTIONS
17
- ActionController::Base
18
-
19
- RAILS_ROOT = '.' unless defined?(RAILS_ROOT)
20
- RAILS_ENV = 'test' unless defined?(RAILS_ENV)
21
- RAILS_DEFAULT_LOGGER = Logger.new(StringIO.new) unless defined?(RAILS_DEFAULT_LOGGER)
22
- #$:.unshift File.join(File.dirname(__FILE__), '../lib')
23
-
24
- #require File.join(File.dirname(__FILE__), "..", "init")
25
- require "init"
26
-
27
- ExceptionNotification::Notifier.configure_exception_notifier do |config|
28
- # If left empty web hooks will not be engaged
29
- config[:web_hooks] = []
30
- config[:exception_recipients] = ["test.errors@example.com"]
31
- config[:view_path] = File.join(File.dirname(__FILE__), "mocks")
32
- config[:skip_local_notification] = false
33
- config[:notify_other_errors] = true
34
- end