rails_exception_handler 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/Gemfile +11 -3
  2. data/Gemfile.lock +32 -30
  3. data/README.markdown +2 -2
  4. data/Rakefile +1 -0
  5. data/VERSION +1 -1
  6. data/lib/rails_exception_handler.rb +1 -0
  7. data/lib/rails_exception_handler/handler.rb +7 -1
  8. data/rails_exception_handler.gemspec +18 -42
  9. data/spec/testapp_32/.gitignore +15 -0
  10. data/spec/testapp_32/app/mailers/.gitkeep +0 -0
  11. data/spec/testapp_32/app/models/.gitkeep +0 -0
  12. data/spec/testapp_32/lib/assets/.gitkeep +0 -0
  13. data/spec/testapp_32/lib/tasks/.gitkeep +0 -0
  14. data/spec/testapp_32/log/.gitkeep +0 -0
  15. data/spec/testapp_32/vendor/assets/javascripts/.gitkeep +0 -0
  16. data/spec/testapp_32/vendor/assets/stylesheets/.gitkeep +0 -0
  17. data/spec/testapp_32/vendor/plugins/.gitkeep +0 -0
  18. metadata +21 -45
  19. data/spec/integration/configuration_spec.rb +0 -220
  20. data/spec/integration/rails_exception_handler_spec.rb +0 -67
  21. data/spec/spec_helper.rb +0 -24
  22. data/spec/test_macros.rb +0 -63
  23. data/spec/testapp_30/Gemfile +0 -31
  24. data/spec/testapp_30/Gemfile.lock +0 -75
  25. data/spec/testapp_30/Rakefile +0 -7
  26. data/spec/testapp_30/app/controllers/application_controller.rb +0 -16
  27. data/spec/testapp_30/app/controllers/home_controller.rb +0 -22
  28. data/spec/testapp_30/app/helpers/application_helper.rb +0 -2
  29. data/spec/testapp_30/app/models/stored_exception.rb +0 -9
  30. data/spec/testapp_30/app/views/home/view_error.html.erb +0 -2
  31. data/spec/testapp_30/app/views/layouts/fallback.html.erb +0 -15
  32. data/spec/testapp_30/app/views/layouts/home.html.erb +0 -15
  33. data/spec/testapp_30/config.ru +0 -4
  34. data/spec/testapp_30/config/application.rb +0 -44
  35. data/spec/testapp_30/config/boot.rb +0 -6
  36. data/spec/testapp_30/config/environment.rb +0 -5
  37. data/spec/testapp_30/config/environments/development.rb +0 -26
  38. data/spec/testapp_30/config/environments/production.rb +0 -49
  39. data/spec/testapp_30/config/environments/test.rb +0 -35
  40. data/spec/testapp_30/config/examples/database.yml +0 -13
  41. data/spec/testapp_30/config/locales/en.yml +0 -5
  42. data/spec/testapp_30/config/routes.rb +0 -6
  43. data/spec/testapp_30/db/migrate/20110630174538_create_error_messages.rb +0 -22
  44. data/spec/testapp_30/db/migrate/20110702131654_add_sessions_table.rb +0 -16
  45. data/spec/testapp_30/db/schema.rb +0 -39
  46. data/spec/testapp_30/db/seeds.rb +0 -7
  47. data/spec/testapp_30/script/rails +0 -6
  48. data/spec/testapp_30/script/setup +0 -19
  49. data/spec/unit/configuration_spec.rb +0 -37
  50. data/spec/unit/handler_spec.rb +0 -200
  51. data/spec/unit/parser_spec.rb +0 -136
@@ -1,220 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RailsExceptionHandler::Configuration do
4
- describe ".storage_strategies" do
5
- it "should store errors in the database when storage_strategies contains :active_record" do
6
- RailsExceptionHandler.configure { |config| config.storage_strategies = [:active_record] }
7
- get('/incorrect_route')
8
- ErrorMessage.count.should == 1
9
- end
10
-
11
- it "should store errors in the rails log when storage_strategies contains :rails_log" do
12
- RailsExceptionHandler.configure { |config| config.storage_strategies = [:rails_log] }
13
- get('/home/model_error')
14
- read_test_log.should match /NoMethodError \(undefined method `foo' for nil:NilClass\)/
15
- read_test_log.should match /lib\/active_support\/whiny_nil\.rb:48/
16
- read_test_log.should match /PARAMS:\s+\{/
17
- read_test_log.should match /TARGET:\s+http:\/\/example\.org\/home\/model_error/
18
- end
19
-
20
- # No idea how to integration test remote_url without spawning a dedicated test server
21
- end
22
-
23
- describe '.filters' do
24
- describe ":all_404s" do
25
- it "should ignore routing errors when the filters contains :all_404s" do
26
- RailsExceptionHandler.configure { |config| config.filters = [:all_404s]}
27
- get('/incorrect_route')
28
- ErrorMessage.count.should == 0
29
- end
30
-
31
- it "should not ignore routing errors when the filters doesnt contain :all_404s" do
32
- RailsExceptionHandler.configure { |config| config.filters = []}
33
- get('/incorrect_route')
34
- ErrorMessage.count.should == 1
35
- end
36
- end
37
-
38
- describe ":no_referer_404s" do
39
- it "should not store a routing error that contains a referer" do
40
- RailsExceptionHandler.configure { |config| config.filters = [:no_referer_404s]}
41
- get "/incorrect_route"
42
- ErrorMessage.count.should == 0
43
- end
44
-
45
- it "should store a routing error that has a referer" do
46
- RailsExceptionHandler.configure { |config| config.filters = [:no_referer_404s]}
47
- get "/incorrect_route", {}, {'HTTP_REFERER' => 'http://example.com'}
48
- ErrorMessage.count.should == 1
49
- end
50
-
51
- it "should store a non routing error without referer" do
52
- RailsExceptionHandler.configure { |config| config.filters = [:no_referer_404s]}
53
- get "/home/view_error"
54
- ErrorMessage.count.should == 1
55
- end
56
-
57
- end
58
-
59
- describe ":user_agent_regxp" do
60
- it "should not store the error message when the user agent matches this regxp" do
61
- RailsExceptionHandler.configure { |config| config.filters = [:user_agent_regxp => /\b(NaughtyBot)\b/]}
62
- get "/incorrect_route", {}, {'HTTP_USER_AGENT' => 'I am a NaughtyBot'}
63
- ErrorMessage.count.should == 0
64
- end
65
-
66
- it "should store the error message when the user agent doesnt match this regxp" do
67
- RailsExceptionHandler.configure { |config| config.filters = [:user_agent_regxp => /\b(NaughtyBot)\b/]}
68
- get "/incorrect_route", {}, {'HTTP_USER_AGENT' => "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0"}
69
- ErrorMessage.count.should == 1
70
- end
71
- end
72
-
73
- describe ":target_url_regxp" do
74
- it "should not store the error message when the url matches this regxp" do
75
- RailsExceptionHandler.configure { |config| config.filters = [:target_url_regxp => /incorrect/]}
76
- get "/incorrect_route"
77
- ErrorMessage.count.should == 0
78
- end
79
-
80
- it "should store the error message when the url doesnt matche this regxp" do
81
- RailsExceptionHandler.configure { |config| config.filters = [:target_url_regxp => /\b(phpMyAdmin)\b/]}
82
- get "/incorrect_route"
83
- ErrorMessage.count.should == 1
84
- end
85
- end
86
-
87
- describe ":anon_404s" do
88
- it "should log a 404 from a logged in user" do
89
- RailsExceptionHandler.configure do |config|
90
- config.environments = [Rails.env.to_sym]
91
- config.storage_strategies = [:active_record]
92
- config.store_user_info = {:method => :current_user, :field => :login}
93
- config.filters = [:anon_404s]
94
- end
95
- get "/incorrect_route"
96
- ErrorMessage.count.should == 1
97
- end
98
-
99
- it "should filter 404s from anonymous users" do
100
- RailsExceptionHandler.configure do |config|
101
- config.environments = [Rails.env.to_sym]
102
- config.storage_strategies = [:active_record]
103
- config.store_user_info = {:method => :nil_user, :field => :login}
104
- config.filters = [:anon_404s]
105
- end
106
- get "/incorrect_route"
107
- ErrorMessage.count.should == 0
108
- end
109
-
110
- it "should not filter 500s from anonymous users" do
111
- RailsExceptionHandler.configure do |config|
112
- config.environments = [Rails.env.to_sym]
113
- config.storage_strategies = [:active_record]
114
- config.store_user_info = {:method => :nil_user, :field => :login}
115
- config.filters = [:anon_404s]
116
- end
117
- get "/home/model_error"
118
- ErrorMessage.count.should == 1
119
- end
120
- end
121
- end
122
-
123
- describe ".environments" do
124
- it "should not log routing errors if the current rails environment is not included" do
125
- Rails.configuration.middleware.delete RailsExceptionHandler
126
- RailsExceptionHandler.configure { |config| config.environments = [:production] }
127
- lambda { get('/incorrect_route') }.should raise_exception
128
- ErrorMessage.count.should == 0
129
- end
130
-
131
- it "should not log regular errors if the current rails environment is not included" do
132
- Rails.configuration.middleware.delete RailsExceptionHandler
133
- RailsExceptionHandler.configure { |config| config.environments = [:production] }
134
- lambda { get('/home/model_error') }.should raise_exception
135
- ErrorMessage.count.should == 0
136
- end
137
-
138
- it "should log routing errors if the rails environment is included" do
139
- Rails.configuration.middleware.delete RailsExceptionHandler
140
- RailsExceptionHandler.configure { |config| config.environments = [Rails.env.to_sym] }
141
- get('/incorrect_route')
142
- ErrorMessage.count.should == 1
143
- last_response.body.should match(/this_is_the_fallback_layout/)
144
- end
145
-
146
- it "should log regular errors if the rails environment is included" do
147
- Rails.configuration.middleware.delete RailsExceptionHandler
148
- RailsExceptionHandler.configure { |config| config.environments = [Rails.env.to_sym] }
149
- get('/home/model_error')
150
- ErrorMessage.count.should == 1
151
- last_response.body.should match(/this_is_the_home_layout/)
152
- end
153
- end
154
-
155
- describe ".fallback_layout" do
156
- it "should use the supplied layout on routing errors" do
157
- RailsExceptionHandler.configure { |config| config.fallback_layout = 'home' }
158
- get('/incorrect_route')
159
- last_response.body.should match(/this_is_the_home_layout/)
160
- end
161
- end
162
-
163
- describe ".store_user_info" do
164
- it "should not store user info when disbled" do
165
- RailsExceptionHandler.configure do |config|
166
- config.environments = [Rails.env.to_sym]
167
- config.storage_strategies = [:active_record]
168
- config.store_user_info = nil
169
- end
170
- get('/incorrect_route')
171
- ErrorMessage.count.should == 1
172
- ErrorMessage.first.user_info.should == nil
173
- end
174
-
175
- it "should store user info on routing errors" do
176
- RailsExceptionHandler.configure do |config|
177
- config.environments = [Rails.env.to_sym]
178
- config.storage_strategies = [:active_record]
179
- config.store_user_info = {:method => :current_user, :field => :login}
180
- end
181
- get('/incorrect_route')
182
- ErrorMessage.count.should == 1
183
- ErrorMessage.first.user_info.should == 'matz'
184
- end
185
-
186
- it "should store user info on application errors" do
187
- RailsExceptionHandler.configure do |config|
188
- config.environments = [Rails.env.to_sym]
189
- config.storage_strategies = [:active_record]
190
- config.store_user_info = {:method => :current_user, :field => :login}
191
- end
192
- get('/home/view_error')
193
- ErrorMessage.count.should == 1
194
- ErrorMessage.first.user_info.should == 'matz'
195
- end
196
- end
197
-
198
- describe "reponses and response_mapping" do
199
- it "should use the default response on non-mapped errors" do
200
- RailsExceptionHandler.configure do |config|
201
- config.environments = [Rails.env.to_sym]
202
- config.storage_strategies = []
203
- config.responses = {:default => 'Customized response'}
204
- end
205
- get('/home/view_error')
206
- last_response.body.should match(/Customized response/)
207
- end
208
-
209
- it "should use mapped response where they exist" do
210
- RailsExceptionHandler.configure do |config|
211
- config.environments = [Rails.env.to_sym]
212
- config.storage_strategies = []
213
- config.responses[:not_found] = 'custom_routing_response_text'
214
- config.response_mapping['ActionController::RoutingError'] = :not_found
215
- end
216
- get('/incorrect_route')
217
- last_response.body.should match(/custom_routing_response_text/)
218
- end
219
- end
220
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RailsExceptionHandler do
4
- it "should catch controller errors" do
5
- get "/home/controller_error"
6
- ErrorMessage.count.should == 1
7
- last_response.body.should match(/Internal server error/)
8
- ErrorMessage.first.class_name.should == 'NoMethodError'
9
- end
10
-
11
- it "should catch model errors" do
12
- get "/home/model_error"
13
- ErrorMessage.count.should == 1
14
- last_response.body.should match(/Internal server error/)
15
- ErrorMessage.first.class_name.should == 'NoMethodError'
16
- end
17
-
18
- it "should catch view errors" do
19
- get "/home/view_error"
20
- ErrorMessage.count.should == 1
21
- last_response.body.should match(/Internal server error/)
22
- ErrorMessage.first.class_name.should == 'ActionView::Template::Error'
23
- end
24
-
25
- it "should catch routing errors" do
26
- get "/incorrect_route"
27
- ErrorMessage.count.should == 1
28
- last_response.body.should match(/Internal server error/)
29
- ErrorMessage.first.class_name.should == 'ActionController::RoutingError'
30
- end
31
-
32
- it "should catch syntax errors" do
33
- get "/home/syntax_error"
34
- ErrorMessage.count.should == 1
35
- last_response.body.should match(/Internal server error/)
36
- ErrorMessage.first.class_name.should == 'SyntaxError'
37
- end
38
-
39
- it "should append the failed controllers view layout when rendering the response" do
40
- get "/home/view_error"
41
- last_response.body.should match(/this_is_the_home_layout/)
42
- end
43
-
44
- it "should fall back to using the application layout on routing errors" do
45
- get "/incorrect_route"
46
- last_response.body.should match(/this_is_the_fallback_layout/)
47
- end
48
-
49
- it "should store the correct information in the database" do
50
- RailsExceptionHandler.configure { |config| config.store_user_info = {:method => :current_user, :field => :login} }
51
- get "/home/controller_error", {}, {'HTTP_REFERER' => 'http://google.com/', 'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 8.0)'}
52
- ErrorMessage.count.should == 1
53
- msg = ErrorMessage.first
54
- msg.app_name.should == 'ExceptionHandlerTestApp'
55
- msg.class_name.should == 'NoMethodError'
56
- msg.message.should == "undefined method `foo' for nil:NilClass"
57
- msg.trace.should match /#{TEST_APP}\/app\/controllers\/home_controller.rb:5:in `controller_error'/
58
- msg.params.should match /"controller"=>"home"/
59
- msg.params.should match /"action"=>"controller_error"/
60
- msg.user_agent.should == 'Mozilla/4.0 (compatible; MSIE 8.0)'
61
- msg.target_url.should == 'http://example.org/home/controller_error'
62
- msg.referer_url.should == 'http://google.com/'
63
- msg.user_info.should == 'matz'
64
- msg.created_at.should be > 5.seconds.ago
65
- msg.created_at.should be < Time.now
66
- end
67
- end
data/spec/spec_helper.rb DELETED
@@ -1,24 +0,0 @@
1
-
2
- TEST_APP = 'testapp_30'
3
- ENV["RAILS_ENV"] = 'test'
4
- require File.expand_path(File.dirname(__FILE__)) + "/#{TEST_APP}/config/environment.rb"
5
-
6
- require File.expand_path(File.dirname(__FILE__)) + '/test_macros.rb'
7
-
8
- require "rspec/rails"
9
- require "rack/test"
10
-
11
- ActiveRecord::Base.logger = nil
12
- ActionController::Base.logger = nil
13
-
14
- RSpec.configure do |config|
15
- config.include Rack::Test::Methods
16
- config.include TestMacros
17
- config.color_enabled = true
18
- config.full_backtrace = true
19
- config.before(:each) do
20
- ErrorMessage.delete_all
21
- clear_test_log
22
- reset_configuration
23
- end
24
- end
data/spec/test_macros.rb DELETED
@@ -1,63 +0,0 @@
1
-
2
- require 'fileutils'
3
-
4
- module TestMacros
5
- def app # Used by by Rack::Test to get the application object
6
- Rails.application.app
7
- end
8
-
9
- def create_env(*args)
10
- options = args.extract_options!
11
- referer = options[:referer] || 'http://google.com/'
12
- s = Rack::Test::Session.new(nil)
13
- env = s.send(:env_for,'/home', {:params => {:foo => 'bar'}, 'HTTP_REFERER' => referer, 'HTTP_USER_AGENT' => "Mozilla/4.0 (compatible; MSIE 8.0)"})
14
- end
15
-
16
- def create_parser(exception = nil, request = nil, controller = nil)
17
- env = create_env
18
- controller ||= mock(ApplicationController, :current_user => mock(Object, :login => 'matz'))
19
- request ||= ActionDispatch::Request.new(env)
20
- exception ||= create_exception
21
- parser = RailsExceptionHandler::Parser.new(exception, request, controller)
22
- end
23
-
24
- def create_exception
25
- exception = nil
26
- begin
27
- nil.foo
28
- rescue Exception => e
29
- exception = e
30
- end
31
- end
32
-
33
- def clear_test_log
34
- File.open(log_path, 'w') {|f| f.write('') }
35
- end
36
-
37
- def read_test_log
38
- data = ""
39
- File.open(log_path, 'r').each_line do |line|
40
- data += line + '\n'
41
- end
42
- return data
43
- end
44
-
45
- def reset_configuration
46
- Rails.configuration.middleware.delete(RailsExceptionHandler)
47
- RailsExceptionHandler.configure do |config|
48
- config.storage_strategies = [:active_record]
49
- config.environments = [:test]
50
- config.store_user_info = false
51
- config.filters = []
52
- config.fallback_layout = 'fallback'
53
- config.response_mapping = {}
54
- config.responses = { :default => '<h1>Internal server error</h1><p>The application has encountered an unexpected issue.</p>' }
55
- end
56
- end
57
-
58
- private
59
-
60
- def log_path
61
- File.expand_path(File.dirname(__FILE__)) + "/#{TEST_APP}/log/test.log"
62
- end
63
- end
@@ -1,31 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'rails', '3.0.9'
4
-
5
- # Bundle edge Rails instead:
6
- # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
-
8
- gem 'mysql2', '0.2.6'
9
-
10
- # Use unicorn as the web server
11
- # gem 'unicorn'
12
-
13
- # Deploy with Capistrano
14
- # gem 'capistrano'
15
-
16
- # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
17
- # gem 'ruby-debug'
18
- # gem 'ruby-debug19', :require => 'ruby-debug'
19
-
20
- # Bundle the extra gems:
21
- # gem 'bj'
22
- # gem 'nokogiri'
23
- # gem 'sqlite3-ruby', :require => 'sqlite3'
24
- # gem 'aws-s3', :require => 'aws/s3'
25
-
26
- # Bundle gems for the local environment. Make sure to
27
- # put test-only gems in this group so their generators
28
- # and rake tasks are available in development mode:
29
- # group :development, :test do
30
- # gem 'webrat'
31
- # end
@@ -1,75 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.9)
6
- actionpack (= 3.0.9)
7
- mail (~> 2.2.19)
8
- actionpack (3.0.9)
9
- activemodel (= 3.0.9)
10
- activesupport (= 3.0.9)
11
- builder (~> 2.1.2)
12
- erubis (~> 2.6.6)
13
- i18n (~> 0.5.0)
14
- rack (~> 1.2.1)
15
- rack-mount (~> 0.6.14)
16
- rack-test (~> 0.5.7)
17
- tzinfo (~> 0.3.23)
18
- activemodel (3.0.9)
19
- activesupport (= 3.0.9)
20
- builder (~> 2.1.2)
21
- i18n (~> 0.5.0)
22
- activerecord (3.0.9)
23
- activemodel (= 3.0.9)
24
- activesupport (= 3.0.9)
25
- arel (~> 2.0.10)
26
- tzinfo (~> 0.3.23)
27
- activeresource (3.0.9)
28
- activemodel (= 3.0.9)
29
- activesupport (= 3.0.9)
30
- activesupport (3.0.9)
31
- arel (2.0.10)
32
- builder (2.1.2)
33
- erubis (2.6.6)
34
- abstract (>= 1.0.0)
35
- i18n (0.5.0)
36
- mail (2.2.19)
37
- activesupport (>= 2.3.6)
38
- i18n (>= 0.4.0)
39
- mime-types (~> 1.16)
40
- treetop (~> 1.4.8)
41
- mime-types (1.16)
42
- mysql2 (0.2.6)
43
- polyglot (0.3.1)
44
- rack (1.2.3)
45
- rack-mount (0.6.14)
46
- rack (>= 1.0.0)
47
- rack-test (0.5.7)
48
- rack (>= 1.0)
49
- rails (3.0.9)
50
- actionmailer (= 3.0.9)
51
- actionpack (= 3.0.9)
52
- activerecord (= 3.0.9)
53
- activeresource (= 3.0.9)
54
- activesupport (= 3.0.9)
55
- bundler (~> 1.0)
56
- railties (= 3.0.9)
57
- railties (3.0.9)
58
- actionpack (= 3.0.9)
59
- activesupport (= 3.0.9)
60
- rake (>= 0.8.7)
61
- rdoc (~> 3.4)
62
- thor (~> 0.14.4)
63
- rake (0.9.2)
64
- rdoc (3.8)
65
- thor (0.14.6)
66
- treetop (1.4.9)
67
- polyglot (>= 0.3.1)
68
- tzinfo (0.3.29)
69
-
70
- PLATFORMS
71
- ruby
72
-
73
- DEPENDENCIES
74
- mysql2 (= 0.2.6)
75
- rails (= 3.0.9)