err_merchant 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Fabian Schwahn
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,32 @@
1
+ = err_merchant
2
+ This is a very simple Rails Engine for replacing the standard (ugly) Rails exception pages, with pages which are rendered in your layout. There are several gems out there that do the same, but this one takes the approach proposed by AccUser[http://accuser.cc/posts/1-rails-3-0-exception-handling]. I just made a gem out of it because I use it in every project.
3
+
4
+ == Installation
5
+ Add the gem to your Gemfile, run +bundle install+ and restart your server:
6
+
7
+ gem 'err_merchant'
8
+
9
+ This is it. If you want to check the error pages in development mode, make sure to set +config.consider_all_requests_local+ to +false+ and restart your development server.
10
+
11
+ == I18n
12
+ You can translate the error messages, by default they are the same as the standard Rails errors:
13
+
14
+ err_merchant:
15
+ '404':
16
+ title: "The page you were looking for doesn't exist."
17
+ description: "You may have mistyped the address or the page may have moved."
18
+ '422':
19
+ title: "The change you wanted was rejected."
20
+ description: "Maybe you tried to change something you didn't have access to."
21
+ '500':
22
+ title: "We're sorry, but something went wrong."
23
+ description: "We've been notified about this issue and we'll take a look at it shortly."
24
+
25
+ Please note that there are +translation missing+-errors in development mode if you don't supply translations for your locale. In production however, +config.i18n.fallbacks+ is usually set to +true+, so the english error message will be shown if the lookup is unsuccessful.
26
+
27
+ == Changelog
28
+ === 0.1.0
29
+ * Initial release
30
+
31
+ == License
32
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ErrMerchant'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rspec/core/rake_task'
26
+ RSpec::Core::RakeTask.new
27
+
28
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ require 'rails/engine'
2
+ require 'err_merchant/show_exceptions_patch'
3
+
4
+ module ErrMerchant
5
+ class Engine < ::Rails::Engine
6
+ initializer "err_merchant.show_exceptions_patch" do
7
+ ActionDispatch::ShowExceptions.send(:include, ShowExceptionsPatch)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ require 'active_support/concern'
2
+
3
+ module ErrMerchant
4
+ module ShowExceptionsPatch
5
+ extend ActiveSupport::Concern
6
+
7
+ included { alias_method_chain :render_exception, :template unless Rails.application.config.consider_all_requests_local }
8
+
9
+ private
10
+ def render_exception_with_template(env, exception)
11
+ body = ErrMerchant::ErrorsController.action(rescue_responses[exception.class.name]).call(env)
12
+ log_error(exception)
13
+ body
14
+ rescue
15
+ render_exception_without_template(env, exception)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module ErrMerchant
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1 @@
1
+ require 'err_merchant/engine'
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ErrMerchant' do
4
+ it 'shows a 500 when an exception is raised' do
5
+ visit '/failures/wild_error'
6
+
7
+ page.should have_content("We're sorry, but something went wrong.")
8
+ page.status_code.should == 500
9
+ end
10
+
11
+ it 'shows a 404 when record not found' do
12
+ visit '/failures/where_is_it'
13
+
14
+ page.should have_content("The page you were looking for doesn't exist.")
15
+ page.status_code.should == 404
16
+ end
17
+
18
+ it 'shows a 422 when an unprocessable entity is encountered' do
19
+ visit '/failures/dont_process_this'
20
+
21
+ page.should have_content("The change you wanted was rejected.")
22
+ page.status_code.should == 422
23
+ end
24
+
25
+ it 'shows the error in the application layout' do
26
+ visit '/failures/wild_error'
27
+
28
+ page.should have_content("ErrMerchant Test Application")
29
+ end
30
+
31
+ it 'does not kick in if there are no errors' do
32
+ visit '/failures/usual_action'
33
+
34
+ page.should have_content("This is a usual action.")
35
+ page.status_code.should == 200
36
+ end
37
+
38
+ it 'shows english error message when no translation available' do
39
+ I18n.locale = :de
40
+ visit '/failures/wild_error'
41
+
42
+ page.should have_content("We're sorry, but something went wrong.")
43
+ end
44
+
45
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,16 @@
1
+ class FailuresController < ApplicationController
2
+ def usual_action
3
+ end
4
+
5
+ def wild_error
6
+ raise
7
+ end
8
+
9
+ def where_is_it
10
+ raise ActiveRecord::RecordNotFound
11
+ end
12
+
13
+ def dont_process_this
14
+ raise ActiveRecord::RecordNotSaved
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ <p>This is a usual action.</p>
@@ -0,0 +1,7 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <body>
4
+ <h1>ErrMerchant Test Application</h1>
5
+ <%= yield %>
6
+ </body>
7
+ </html>
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/combustion_test.sqlite
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ match ':controller(/:action(/:id(.:format)))'
3
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ ActiveRecord::Schema.define do
2
+ #
3
+ end