rails_exception_handler 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +11 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +91 -0
- data/LICENCE +20 -0
- data/README.markdown +192 -0
- data/Rakefile +31 -0
- data/VERSION +1 -0
- data/app/controllers/error_response_controller.rb +6 -0
- data/app/models/error_message.rb +3 -0
- data/lib/patch/show_exceptions.rb +14 -0
- data/lib/rails_exception_handler/configuration.rb +13 -0
- data/lib/rails_exception_handler/handler.rb +69 -0
- data/lib/rails_exception_handler/parser.rb +73 -0
- data/lib/rails_exception_handler.rb +37 -0
- data/rails_exception_handler.gemspec +87 -0
- data/spec/integration/configuration_spec.rb +161 -0
- data/spec/integration/rails_exception_handler_spec.rb +67 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/test_macros.rb +61 -0
- data/spec/testapp_30/.gitignore +4 -0
- data/spec/testapp_30/Gemfile +31 -0
- data/spec/testapp_30/Gemfile.lock +75 -0
- data/spec/testapp_30/Rakefile +7 -0
- data/spec/testapp_30/app/controllers/application_controller.rb +12 -0
- data/spec/testapp_30/app/controllers/home_controller.rb +22 -0
- data/spec/testapp_30/app/helpers/application_helper.rb +2 -0
- data/spec/testapp_30/app/models/stored_exception.rb +9 -0
- data/spec/testapp_30/app/views/home/view_error.html.erb +2 -0
- data/spec/testapp_30/app/views/layouts/fallback.html.erb +15 -0
- data/spec/testapp_30/app/views/layouts/home.html.erb +15 -0
- data/spec/testapp_30/config/application.rb +44 -0
- data/spec/testapp_30/config/boot.rb +6 -0
- data/spec/testapp_30/config/database.yml +12 -0
- data/spec/testapp_30/config/environment.rb +5 -0
- data/spec/testapp_30/config/environments/development.rb +26 -0
- data/spec/testapp_30/config/environments/production.rb +49 -0
- data/spec/testapp_30/config/environments/test.rb +35 -0
- data/spec/testapp_30/config/examples/database.yml +13 -0
- data/spec/testapp_30/config/locales/en.yml +5 -0
- data/spec/testapp_30/config/routes.rb +6 -0
- data/spec/testapp_30/config.ru +4 -0
- data/spec/testapp_30/db/migrate/20110630174538_create_error_messages.rb +22 -0
- data/spec/testapp_30/db/migrate/20110702131654_add_sessions_table.rb +16 -0
- data/spec/testapp_30/db/schema.rb +39 -0
- data/spec/testapp_30/db/seeds.rb +7 -0
- data/spec/testapp_30/lib/tasks/.gitkeep +0 -0
- data/spec/testapp_30/script/rails +6 -0
- data/spec/testapp_30/script/setup +19 -0
- data/spec/testapp_30/vendor/plugins/.gitkeep +0 -0
- data/spec/unit/configuration_spec.rb +37 -0
- data/spec/unit/handler_spec.rb +136 -0
- data/spec/unit/parser_spec.rb +112 -0
- metadata +107 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
ExceptionHandlerTestApp::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
+
# like if you have constraints or database-specific column types
|
31
|
+
# config.active_record.schema_format = :sql
|
32
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateErrorMessages < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :error_messages do |t|
|
4
|
+
t.text :class_name
|
5
|
+
t.text :message
|
6
|
+
t.text :trace
|
7
|
+
t.text :params
|
8
|
+
t.text :target_url
|
9
|
+
t.text :referer_url
|
10
|
+
t.text :user_agent
|
11
|
+
t.string :user_info
|
12
|
+
t.string :app_name
|
13
|
+
t.datetime :created_at
|
14
|
+
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.down
|
20
|
+
drop_table :error_messages
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class AddSessionsTable < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :sessions do |t|
|
4
|
+
t.string :session_id, :null => false
|
5
|
+
t.text :data
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
|
9
|
+
add_index :sessions, :session_id
|
10
|
+
add_index :sessions, :updated_at
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :sessions
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended to check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(:version => 20110702131654) do
|
14
|
+
|
15
|
+
create_table "error_messages", :force => true do |t|
|
16
|
+
t.text "class_name"
|
17
|
+
t.text "message"
|
18
|
+
t.text "trace"
|
19
|
+
t.text "params"
|
20
|
+
t.text "target_url"
|
21
|
+
t.text "referer_url"
|
22
|
+
t.text "user_agent"
|
23
|
+
t.string "user_info"
|
24
|
+
t.string "app_name"
|
25
|
+
t.datetime "created_at"
|
26
|
+
t.datetime "updated_at"
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table "sessions", :force => true do |t|
|
30
|
+
t.string "session_id", :null => false
|
31
|
+
t.text "data"
|
32
|
+
t.datetime "created_at"
|
33
|
+
t.datetime "updated_at"
|
34
|
+
end
|
35
|
+
|
36
|
+
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
|
37
|
+
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Mayor.create(:name => 'Daley', :city => cities.first)
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
Dir.chdir(File.expand_path(File.dirname(__FILE__)) + "/../")
|
6
|
+
|
7
|
+
source = "config/examples/database.yml"
|
8
|
+
target = "config/database.yml"
|
9
|
+
|
10
|
+
if File.exist?(target)
|
11
|
+
puts "#{target} already exists"
|
12
|
+
else
|
13
|
+
FileUtils.cp(source, target)
|
14
|
+
puts "#{target} copied"
|
15
|
+
end
|
16
|
+
|
17
|
+
system "bundle"
|
18
|
+
system "bundle exec rake db:create --trace RAILS_ENV=test"
|
19
|
+
system "bundle exec rake db:migrate --trace RAILS_ENV=test"
|
File without changes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
describe RailsExceptionHandler::Configuration do
|
4
|
+
describe ".initialize" do
|
5
|
+
before(:each) do
|
6
|
+
@configuration = RailsExceptionHandler::Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should add :production to environments" do
|
10
|
+
@configuration.environments.should == [:production]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set storage_strategies to []" do
|
14
|
+
@configuration.storage_strategies.should == []
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set store_user_info to false" do
|
18
|
+
@configuration.store_user_info = false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should set filters to [] " do
|
22
|
+
@configuration.filters.should == []
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set the 404 response" do
|
26
|
+
@configuration.responses['404'].should match(/Page not found/)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should set the 500 response" do
|
30
|
+
@configuration.responses['500'].should match(/Internal server error/)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should set the fallback layout to 'application'" do
|
34
|
+
@configuration.fallback_layout.should == 'application'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
describe RailsExceptionHandler::Handler do
|
4
|
+
before(:each) do
|
5
|
+
@handler = RailsExceptionHandler::Handler.new(create_env, create_exception)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".handle_exception" do
|
9
|
+
it "should parse error" do
|
10
|
+
@handler.handle_exception
|
11
|
+
@handler.instance_variable_get(:@parsed_error).should_not == nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should store error" do
|
15
|
+
@handler.should_receive(:store_error)
|
16
|
+
@handler.handle_exception
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return a rack tripple" do
|
20
|
+
response = @handler.handle_exception
|
21
|
+
response.length.should == 3
|
22
|
+
response[0].should == 200 # response code
|
23
|
+
response[1].class.should == Hash # headers
|
24
|
+
response[2].class.should == ActionDispatch::Response # body
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".store_error" do
|
29
|
+
it "should store an error message in the database when storage_strategies includes :active_record" do
|
30
|
+
RailsExceptionHandler.configure { |config| config.storage_strategies = [:active_record] }
|
31
|
+
@handler.handle_exception
|
32
|
+
ErrorMessage.count.should == 1
|
33
|
+
msg = ErrorMessage.first
|
34
|
+
msg.app_name.should == 'ExceptionHandlerTestApp'
|
35
|
+
msg.class_name.should == 'NoMethodError'
|
36
|
+
msg.message.should == "undefined method `foo' for nil:NilClass"
|
37
|
+
msg.trace.should match /active_support\/whiny_nil/
|
38
|
+
msg.params.should match /\"foo\"=>\"bar\"/
|
39
|
+
msg.user_agent.should == 'Mozilla/4.0 (compatible; MSIE 8.0)'
|
40
|
+
msg.target_url.should == 'http://example.org/home?foo=bar'
|
41
|
+
msg.referer_url.should == 'http://google.com/'
|
42
|
+
msg.created_at.should be > 5.seconds.ago
|
43
|
+
msg.created_at.should be < Time.now
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not store an error message in the database when storage_strategies does not include :active_record" do
|
47
|
+
RailsExceptionHandler.configure { |config| config.storage_strategies = [] }
|
48
|
+
ErrorMessage.count.should == 0
|
49
|
+
end
|
50
|
+
|
51
|
+
it "it should log an error to the rails log when storage_strategies includes :rails_log" do
|
52
|
+
RailsExceptionHandler.configure { |config| config.storage_strategies = [:rails_log] }
|
53
|
+
read_test_log.should == ''
|
54
|
+
@handler.handle_exception
|
55
|
+
read_test_log.should match /NoMethodError \(undefined method `foo' for nil:NilClass\)/
|
56
|
+
read_test_log.should match /lib\/active_support\/whiny_nil\.rb:48/
|
57
|
+
read_test_log.should match /PARAMS:\s+{\"foo\"=>\"bar\"}/
|
58
|
+
read_test_log.should match /USER_AGENT:\s+Mozilla\/4.0 \(compatible; MSIE 8\.0\)/
|
59
|
+
read_test_log.should match /TARGET:\s+http:\/\/example\.org\/home\?foo=bar/
|
60
|
+
read_test_log.should match /REFERER:\s+http:\/\/google\.com\//
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not log an error to the rails log when storage_strategies does not include :rails_log" do
|
64
|
+
RailsExceptionHandler.configure { |config| config.storage_strategies = [] }
|
65
|
+
read_test_log.should == ''
|
66
|
+
@handler.handle_exception
|
67
|
+
read_test_log.should == ''
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should send the error_message as an HTTP POST request when :remote_url is included" do
|
71
|
+
Time.stub!(:now => Time.now) # Otherwise the timestamps will be different, and comparison fail
|
72
|
+
@handler.handle_exception
|
73
|
+
parser = @handler.instance_variable_get(:@parsed_error)
|
74
|
+
RailsExceptionHandler.configure { |config| config.storage_strategies = [:remote_url => {:target => 'http://example.com/error_messages'}] }
|
75
|
+
uri = URI.parse('http://example.com/error_messages')
|
76
|
+
params = {}
|
77
|
+
parser.relevant_info.each do |key,value|
|
78
|
+
params["error_message[#{key}]"] = value
|
79
|
+
end
|
80
|
+
Net::HTTP.should_receive(:post_form).with(uri, params)
|
81
|
+
@handler.handle_exception
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should not send the error_message as an HTTP POST request when :remote_url is not included" do
|
85
|
+
RailsExceptionHandler.configure { |config| config.storage_strategies = [] }
|
86
|
+
Net::HTTP.should_not_receive(:post_form)
|
87
|
+
@handler.handle_exception
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should be able to use multiple storage strategies" do
|
91
|
+
RailsExceptionHandler.configure { |config| config.storage_strategies = [:active_record, :rails_log] }
|
92
|
+
read_test_log.should == ''
|
93
|
+
@handler.handle_exception
|
94
|
+
read_test_log.should match /NoMethodError \(undefined method `foo' for nil:NilClass\)/
|
95
|
+
ErrorMessage.count.should == 1
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '.response' do
|
100
|
+
it "should call index action on ErrorResponseController" do
|
101
|
+
ErrorResponseController.should_receive(:action).with(:index).and_return(mock(Object, :call => true))
|
102
|
+
@handler.handle_exception
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should set response_code to '404' on routing errors" do
|
106
|
+
exception = create_exception
|
107
|
+
env = create_env
|
108
|
+
exception.stub!(:class => ActiveRecord::RecordNotFound)
|
109
|
+
handler = RailsExceptionHandler::Handler.new(env, exception)
|
110
|
+
handler.handle_exception
|
111
|
+
env['exception_handler.response_code'].should == '404'
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should set response_code to '500' on all other errors" do
|
115
|
+
env = create_env
|
116
|
+
handler = RailsExceptionHandler::Handler.new(env, create_exception)
|
117
|
+
handler.handle_exception
|
118
|
+
env['exception_handler.response_code'].should == '500'
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should save the layout in env" do
|
122
|
+
env = create_env
|
123
|
+
handler = RailsExceptionHandler::Handler.new(env, create_exception)
|
124
|
+
handler.instance_variable_set("@controller",mock(Object, :_default_layout => 'home'))
|
125
|
+
handler.handle_exception
|
126
|
+
env['exception_handler.layout'].should == 'home'
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should use the fallback layout when no layout is defined" do
|
130
|
+
env = create_env
|
131
|
+
handler = RailsExceptionHandler::Handler.new(env, create_exception)
|
132
|
+
handler.handle_exception
|
133
|
+
env['exception_handler.layout'].should == 'fallback'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
describe RailsExceptionHandler::Parser do
|
4
|
+
before(:each) do
|
5
|
+
env = create_env
|
6
|
+
controller = mock(ApplicationController, :current_user => mock(Object, :login => 'matz'))
|
7
|
+
request = ActionDispatch::Request.new(env)
|
8
|
+
@parser = RailsExceptionHandler::Parser.new(create_exception, request, controller)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".relevant_info" do
|
12
|
+
it("should return app_name") { @parser.relevant_info[:app_name].should == 'ExceptionHandlerTestApp' }
|
13
|
+
it("should return class_name") { @parser.relevant_info[:class_name].should == 'NoMethodError' }
|
14
|
+
it("should return message") { @parser.relevant_info[:message].should == "undefined method `foo' for nil:NilClass" }
|
15
|
+
it("should return trace") { @parser.relevant_info[:trace].should match /active_support\/whiny_nil/ }
|
16
|
+
it("should return target_url") { @parser.relevant_info[:target_url].should == 'http://example.org/home?foo=bar' }
|
17
|
+
it("should return referer_url") { @parser.relevant_info[:referer_url].should == 'http://google.com/' }
|
18
|
+
it("should return params") { @parser.relevant_info[:params].should match(/\"foo\"=>\"bar\"/) }
|
19
|
+
it("should return user_agent") { @parser.relevant_info[:user_agent].should == "Mozilla/4.0 (compatible; MSIE 8.0)" }
|
20
|
+
it("should return user_info") { @parser.relevant_info[:user_info].should == nil }
|
21
|
+
it("should return created_at") { @parser.relevant_info[:created_at].should be > 5.seconds.ago }
|
22
|
+
it("should return created_at") { @parser.relevant_info[:created_at].should be < Time.now }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".ignore?" do
|
26
|
+
context "routing errors" do
|
27
|
+
it "should return true on routing errors when the filter contains :all_404s" do
|
28
|
+
RailsExceptionHandler.configure { |config| config.filters = [:all_404s] }
|
29
|
+
exception = create_exception
|
30
|
+
exception.stub!(:class => ActionController::RoutingError)
|
31
|
+
parser = create_parser(exception, nil, nil)
|
32
|
+
parser.ignore?.should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return true on routing errors without referer when the filter contains :no_referer_404s" do
|
36
|
+
RailsExceptionHandler.configure { |config| config.filters = [:no_referer_404s] }
|
37
|
+
exception = create_exception
|
38
|
+
exception.stub!(:class => ActionController::RoutingError)
|
39
|
+
request = ActionDispatch::Request.new(create_env(:referer => '/'))
|
40
|
+
parser = create_parser(exception, request, nil)
|
41
|
+
parser.ignore?.should == true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return true when the user agent matches against the filters :user_agent_regxp" do
|
45
|
+
RailsExceptionHandler.configure { |config| config.filters = [{:user_agent_regxp => /\b(Mozilla)\b/}] }
|
46
|
+
parser = create_parser(nil, nil, nil)
|
47
|
+
parser.ignore?.should == true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return true when the url matches against the filters :target_url_regxp" do
|
51
|
+
RailsExceptionHandler.configure { |config| config.filters = [{:target_url_regxp => /\b(home)\b/}] }
|
52
|
+
parser = create_parser(nil, nil, nil)
|
53
|
+
parser.ignore?.should == true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return false when the request is not caught by a filter" do
|
57
|
+
RailsExceptionHandler.configure { |config| config.filters = [] }
|
58
|
+
parser = create_parser(nil, nil, nil)
|
59
|
+
parser.ignore?.should == false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "routing_error?" do
|
65
|
+
it "should return true on ActionController::RoutingError" do
|
66
|
+
exception = create_exception
|
67
|
+
exception.stub!(:class => ActionController::RoutingError)
|
68
|
+
parser = create_parser(exception, nil, nil)
|
69
|
+
parser.routing_error?.should == true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return true on AbstractController::ActionNotFound" do
|
73
|
+
exception = create_exception
|
74
|
+
exception.stub!(:class => AbstractController::ActionNotFound)
|
75
|
+
parser = create_parser(exception, nil, nil)
|
76
|
+
parser.routing_error?.should == true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return true on ActiveRecord::RecordNotFound" do
|
80
|
+
exception = create_exception
|
81
|
+
exception.stub!(:class => ActiveRecord::RecordNotFound)
|
82
|
+
parser = create_parser(exception, nil, nil)
|
83
|
+
parser.routing_error?.should == true
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should return false on all other errors" do
|
87
|
+
@parser.routing_error?.should == false
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "user_info" do
|
92
|
+
it "should store user info based on the method and field provided" do
|
93
|
+
RailsExceptionHandler.configure {|config| config.store_user_info = {:method => :current_user, :field => :login}}
|
94
|
+
controller = mock(ApplicationController, :current_user => mock(Object, :login => 'matz'))
|
95
|
+
parser = create_parser(nil, nil, controller)
|
96
|
+
parser.relevant_info[:user_info].should == 'matz'
|
97
|
+
end
|
98
|
+
it "should store 'Anonymous' when store_user_info is enabled and no user is logged in" do
|
99
|
+
RailsExceptionHandler.configure {|config| config.store_user_info = {:method => :current_user, :field => :login}}
|
100
|
+
controller = mock(ApplicationController, :current_user => nil)
|
101
|
+
parser = create_parser(nil, nil, controller)
|
102
|
+
parser.relevant_info[:user_info].should == 'Anonymous'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should not store any info when configured store_user_info is false" do
|
106
|
+
RailsExceptionHandler.configure {|config| config.store_user_info = false}
|
107
|
+
controller = mock(ApplicationController, :current_user => mock(Object, :login => 'matz'))
|
108
|
+
parser = create_parser(nil, nil, controller)
|
109
|
+
parser.relevant_info[:user_info].should == nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_exception_handler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sharagoz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-17 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: ""
|
18
|
+
email: contact@sharagoz.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.markdown
|
25
|
+
files:
|
26
|
+
- .travis.yml
|
27
|
+
- Gemfile
|
28
|
+
- Gemfile.lock
|
29
|
+
- LICENCE
|
30
|
+
- README.markdown
|
31
|
+
- Rakefile
|
32
|
+
- VERSION
|
33
|
+
- app/controllers/error_response_controller.rb
|
34
|
+
- app/models/error_message.rb
|
35
|
+
- lib/patch/show_exceptions.rb
|
36
|
+
- lib/rails_exception_handler.rb
|
37
|
+
- lib/rails_exception_handler/configuration.rb
|
38
|
+
- lib/rails_exception_handler/handler.rb
|
39
|
+
- lib/rails_exception_handler/parser.rb
|
40
|
+
- rails_exception_handler.gemspec
|
41
|
+
- spec/integration/configuration_spec.rb
|
42
|
+
- spec/integration/rails_exception_handler_spec.rb
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
- spec/test_macros.rb
|
45
|
+
- spec/testapp_30/.gitignore
|
46
|
+
- spec/testapp_30/Gemfile
|
47
|
+
- spec/testapp_30/Gemfile.lock
|
48
|
+
- spec/testapp_30/Rakefile
|
49
|
+
- spec/testapp_30/app/controllers/application_controller.rb
|
50
|
+
- spec/testapp_30/app/controllers/home_controller.rb
|
51
|
+
- spec/testapp_30/app/helpers/application_helper.rb
|
52
|
+
- spec/testapp_30/app/models/stored_exception.rb
|
53
|
+
- spec/testapp_30/app/views/home/view_error.html.erb
|
54
|
+
- spec/testapp_30/app/views/layouts/fallback.html.erb
|
55
|
+
- spec/testapp_30/app/views/layouts/home.html.erb
|
56
|
+
- spec/testapp_30/config.ru
|
57
|
+
- spec/testapp_30/config/application.rb
|
58
|
+
- spec/testapp_30/config/boot.rb
|
59
|
+
- spec/testapp_30/config/database.yml
|
60
|
+
- spec/testapp_30/config/environment.rb
|
61
|
+
- spec/testapp_30/config/environments/development.rb
|
62
|
+
- spec/testapp_30/config/environments/production.rb
|
63
|
+
- spec/testapp_30/config/environments/test.rb
|
64
|
+
- spec/testapp_30/config/examples/database.yml
|
65
|
+
- spec/testapp_30/config/locales/en.yml
|
66
|
+
- spec/testapp_30/config/routes.rb
|
67
|
+
- spec/testapp_30/db/migrate/20110630174538_create_error_messages.rb
|
68
|
+
- spec/testapp_30/db/migrate/20110702131654_add_sessions_table.rb
|
69
|
+
- spec/testapp_30/db/schema.rb
|
70
|
+
- spec/testapp_30/db/seeds.rb
|
71
|
+
- spec/testapp_30/lib/tasks/.gitkeep
|
72
|
+
- spec/testapp_30/script/rails
|
73
|
+
- spec/testapp_30/script/setup
|
74
|
+
- spec/testapp_30/vendor/plugins/.gitkeep
|
75
|
+
- spec/unit/configuration_spec.rb
|
76
|
+
- spec/unit/handler_spec.rb
|
77
|
+
- spec/unit/parser_spec.rb
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: http://github.com/Sharagoz/rails_exception_handler
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: "0"
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.6.2
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Exception Handling for Rails 3
|
106
|
+
test_files: []
|
107
|
+
|