gaffe 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -83,7 +83,7 @@ You can (and should!) also use your own views. You just have to create a layout:
83
83
  <%= yield %>
84
84
  ```
85
85
 
86
- And create a different view for [each possible error rescue response](https://github.com/rails/rails/blob/f9ceefd3b9c3cea2460a89799156f2c532c4491c/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb). For example, for `404` errors:
86
+ And create a different view for [each possible error rescue response](https://github.com/mirego/gaffe/tree/master/app/views/errors) ([rails reference](https://github.com/rails/rails/blob/f9ceefd3b9c3cea2460a89799156f2c532c4491c/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb)). For example, for `404` errors:
87
87
 
88
88
  ```erb
89
89
  <!-- app/views/errors/not_found.html.erb -->
@@ -57,4 +57,6 @@ pre {
57
57
  pre em {
58
58
  font-style: normal;
59
59
  color: rgba(0,0,0,0.5);
60
+ border-bottom: 1px dotted;
61
+ cursor: help;
60
62
  }
@@ -0,0 +1 @@
1
+ Bad Request
@@ -0,0 +1 @@
1
+ Method Not Allowed
@@ -0,0 +1 @@
1
+ Not Acceptable
@@ -0,0 +1 @@
1
+ Not Implemented
@@ -0,0 +1 @@
1
+ Unprocessable Entity
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <title>Error!</title>
6
6
  <style type="text/css">
7
- <%= File.read(File.join(Gaffe.root, 'app/assets/stylesheets/errors.css')).gsub("\n", ' ').gsub(' ', ' ') %>
7
+ <%= File.read(Gaffe.root.join('app/assets/stylesheets/errors.css')).gsub("\n", ' ').gsub(' ', ' ') %>
8
8
  </style>
9
9
  </head>
10
10
  <body>
@@ -20,9 +20,10 @@
20
20
 
21
21
  <p>You can overwrite this page by creating these files:</p>
22
22
 
23
+ <% handlers = ActionView::Template::Handlers.extensions.map(&:to_s).join(', ') %>
23
24
  <pre>
24
- <code><%= Rails.root.join('app', 'views', 'layouts', "error.html.<em>[handler]</em>").to_s.html_safe %></code>
25
- <code><%= Rails.root.join('app', 'views', 'errors', "#{@rescue_response.to_s}.html.<em>[handler]</em>").to_s.html_safe %></code>
25
+ <code><%= Rails.root.join('app', 'views', 'layouts', "error.html.<em title='#{handlers}'>handler</em>").to_s.html_safe %></code>
26
+ <code><%= Rails.root.join('app', 'views', 'errors', "#{@rescue_response.to_s}.html.<em title='#{handlers}'>handler</em>").to_s.html_safe %></code>
26
27
  </pre>
27
28
  </div>
28
29
  </body>
data/lib/gaffe/errors.rb CHANGED
@@ -9,7 +9,11 @@ module Gaffe
9
9
  end
10
10
 
11
11
  def show
12
- render "errors/#{@rescue_response}", status: @status_code
12
+ begin
13
+ render "errors/#{@rescue_response}", status: @status_code
14
+ rescue ActionView::MissingTemplate
15
+ render "errors/internal_server_error", status: 500
16
+ end
13
17
  end
14
18
 
15
19
  protected
@@ -23,7 +27,7 @@ module Gaffe
23
27
  private
24
28
 
25
29
  def append_view_paths
26
- append_view_path File.expand_path('../../../app/views', __FILE__)
30
+ append_view_path Gaffe.root.join('app/views')
27
31
  end
28
32
  end
29
33
  end
data/lib/gaffe/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gaffe
2
- VERSION = '0.2'
2
+ VERSION = '0.2.1'
3
3
  end
data/lib/gaffe.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'gaffe/version'
2
2
 
3
3
  require 'ostruct'
4
+ require 'pathname'
4
5
  require 'gaffe/errors'
5
6
 
6
7
  module Gaffe
@@ -16,8 +17,10 @@ module Gaffe
16
17
 
17
18
  # Return our default controller
18
19
  def self.builtin_errors_controller
19
- require 'gaffe/errors_controller'
20
- Gaffe::ErrorsController
20
+ @builtin_errors_controller ||= begin
21
+ require 'gaffe/errors_controller'
22
+ Gaffe::ErrorsController
23
+ end
21
24
  end
22
25
 
23
26
  # Configure Rails to use our code when encountering exceptions
@@ -41,6 +44,6 @@ module Gaffe
41
44
 
42
45
  # Return the root path of the gem
43
46
  def self.root
44
- File.expand_path('../../', __FILE__)
47
+ Pathname.new(File.expand_path('../../', __FILE__))
45
48
  end
46
49
  end
@@ -5,13 +5,28 @@ describe Gaffe::Errors do
5
5
  describe :show do
6
6
  let(:request) { ActionDispatch::TestRequest.new }
7
7
  let(:env) { request.env.merge 'action_dispatch.exception' => exception }
8
- let(:exception) { ActionController::RoutingError.new(:foo) }
9
8
 
10
9
  let(:response) { Gaffe.errors_controller_for_request(env).action(:show).call(env) }
11
10
  subject { response.last }
12
11
 
13
- its(:status) { should eql 404 }
14
- its(:body) { should match /Not Found/ }
12
+ context 'with builtin exception' do
13
+ let(:exception) { ActionController::RoutingError.new(:foo) }
14
+ its(:status) { should eql 404 }
15
+ its(:body) { should match /Not Found/ }
16
+ end
17
+
18
+ context 'with custom exception and missing view' do
19
+ before { ActionDispatch::ExceptionWrapper.rescue_responses.merge! exception_class.name => 'my_custom_error' }
20
+
21
+ let(:exception_class) do
22
+ Object.instance_eval { remove_const :MyCustomError } if Object.const_defined?(:MyCustomError)
23
+ MyCustomError = Class.new(StandardError)
24
+ end
25
+
26
+ let(:exception) { exception_class.new }
27
+ its(:status) { should eql 500 }
28
+ its(:body) { should match /Internal Server Error/ }
29
+ end
15
30
  end
16
31
  end
17
32
  end
@@ -2,13 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe Gaffe do
4
4
  describe :ClassMethods do
5
- before do
6
- # Make sure we clear memoized variables before each test
7
- [:@configuration].each do |variable|
8
- Gaffe.send :remove_instance_variable, variable if Gaffe.instance_variable_defined?(variable)
9
- end
10
- end
11
-
12
5
  describe :configure do
13
6
  subject { Gaffe.configuration }
14
7
  before do
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,13 @@ require 'gaffe'
6
6
 
7
7
  RSpec.configure do |config|
8
8
  config.before(:each) do
9
+ # Fake Rails.root
9
10
  Rails.stub(:root).and_return(RAILS_ROOT)
11
+
12
+ # Make sure we clear memoized variables before each test
13
+ [:@configuration].each do |variable|
14
+ Gaffe.send :remove_instance_variable, variable if Gaffe.instance_variable_defined?(variable)
15
+ end
10
16
  end
11
17
  end
12
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaffe
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-01 00:00:00.000000000 Z
13
+ date: 2013-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -92,10 +92,15 @@ files:
92
92
  - README.md
93
93
  - Rakefile
94
94
  - app/assets/stylesheets/errors.css
95
+ - app/views/errors/bad_request.html.erb
95
96
  - app/views/errors/forbidden.html.erb
96
97
  - app/views/errors/internal_server_error.html.erb
98
+ - app/views/errors/method_not_allowed.html.erb
99
+ - app/views/errors/not_acceptable.html.erb
97
100
  - app/views/errors/not_found.html.erb
101
+ - app/views/errors/not_implemented.html.erb
98
102
  - app/views/errors/unauthorized.html.erb
103
+ - app/views/errors/unprocessable_entity.html.erb
99
104
  - app/views/layouts/error.html.erb
100
105
  - gaffe.gemspec
101
106
  - gemfiles/Gemfile.rails-3.2.x
@@ -122,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
127
  version: '0'
123
128
  segments:
124
129
  - 0
125
- hash: -2535410059027227615
130
+ hash: 843740072442851156
126
131
  required_rubygems_version: !ruby/object:Gem::Requirement
127
132
  none: false
128
133
  requirements:
@@ -131,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
136
  version: '0'
132
137
  segments:
133
138
  - 0
134
- hash: -2535410059027227615
139
+ hash: 843740072442851156
135
140
  requirements: []
136
141
  rubyforge_project:
137
142
  rubygems_version: 1.8.23