gaffe 0.2.1 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ce01c4c09894fecd78f12031f46135cbc4c8abf
4
+ data.tar.gz: 60960d0ee25ed32565227492b3014d491c45571a
5
+ SHA512:
6
+ metadata.gz: db16c3dc353687abeadccf095aa5b6000d94f9f68938e3106b19528a9f14a322f06f1d389fa5edef8c6cafd6a6f9f6f33e779eee8d0ef1f450bba99c4b147dd5
7
+ data.tar.gz: 7083bbd24ada18edd68684b8d544e9ee22446f9bd0161721990a4437f04d39773bcdac294efe07a50cff5b77511c5812470abac52672a9478e8f5719d2e6394f
data/README.md CHANGED
@@ -1,14 +1,23 @@
1
- # Gaffe
2
-
3
- [![Gem Version](https://badge.fury.io/rb/gaffe.png)](https://rubygems.org/gems/gaffe)
4
- [![Build Status](https://travis-ci.org/mirego/gaffe.png?branch=master)](https://travis-ci.org/mirego/gaffe)
5
-
6
- Gaffe handles Rails error pages in a clean, simple way. The default error page looks like this:
1
+ <p align="center">
2
+ <a href="https://github.com/mirego/gaffe">
3
+ <img src="http://i.imgur.com/k9Vo08q.png" alt="gaffe" />
4
+ </a>
5
+ <br />
6
+ Gaffe makes having customized error pages in Rails applications an easy thing.<br /> It takes advantage of a feature present in Rails 3.2+ called <code>exceptions_app</code>.
7
+ <br /><br />
8
+ <a href="https://rubygems.org/gems/gaffe"><img src="https://badge.fury.io/rb/gaffe.png" /></a>
9
+ <a href="https://codeclimate.com/github/mirego/gaffe"><img src="https://codeclimate.com/github/mirego/gaffe.png" /></a>
10
+ <a href='https://coveralls.io/r/mirego/gaffe?branch=master'><img src='https://coveralls.io/repos/mirego/gaffe/badge.png?branch=master' /></a>
11
+ <a href='https://gemnasium.com/mirego/gaffe'><img src="https://gemnasium.com/mirego/gaffe.png" /></a>
12
+ <a href="https://travis-ci.org/mirego/gaffe"><img src="https://travis-ci.org/mirego/gaffe.png?branch=master" /></a>
13
+ </p>
14
+
15
+ ---
16
+
17
+ It comes with default error pages but makes it very easy to override them (which you should do). The default error pages look like this:
7
18
 
8
19
  ![](http://i.imgur.com/9gPfCOm.png)
9
20
 
10
- You should overwrite it though, it’s very easy to do so.
11
-
12
21
  ## Installation
13
22
 
14
23
  Add this line to your application’s Gemfile:
@@ -57,7 +66,11 @@ Gaffe.enable!
57
66
 
58
67
  The only required thing to do in your custom controller is to include the `Gaffe::Errors` module.
59
68
 
60
- Only `show` will be called so you might want to overwrite it. You might also want to get rid of filters and other stuff.
69
+ Only `show` will be called so you might want to override it. If you don’t override it, Gaffe will
70
+ try to render the view `"errors/#{@rescue_response}"` within your application (or use its default
71
+ error page if the view doesn’t exist).
72
+
73
+ You might also want to get rid of filters and other stuff to make sure that error pages are always accessible.
61
74
 
62
75
  ```ruby
63
76
  class ErrorsController < ApplicationController
@@ -73,6 +86,19 @@ class ErrorsController < ApplicationController
73
86
  end
74
87
  ```
75
88
 
89
+ For example, you might want your `Api::ErrorsController` to return a standard JSON response:
90
+
91
+ ```ruby
92
+ class Api::ErrorsController < Api::ApplicationController
93
+ include Gaffe::Errors
94
+ skip_before_filter :ensure_current_user
95
+
96
+ def show
97
+ render json: { error: @rescue_response }, status: @status_code
98
+ end
99
+ end
100
+ ```
101
+
76
102
  ### Custom views
77
103
 
78
104
  You can (and should!) also use your own views. You just have to create a layout:
@@ -98,14 +124,27 @@ specific rescue responses.
98
124
 
99
125
  ```ruby
100
126
  # config/application.rb
101
- config.action_dispatch.rescue_responses.merge!('CanCan::AccessDenied' => :forbidden)
102
- config.action_dispatch.rescue_responses.merge!('MyCustomException' => :not_acceptable)
127
+ config.action_dispatch.rescue_responses.merge! 'CanCan::AccessDenied' => :forbidden
128
+ config.action_dispatch.rescue_responses.merge! 'MyCustomException' => :not_acceptable
129
+ ```
130
+
131
+ ### Rails development mode
132
+
133
+ Rails prefers to render its own debug-friendly errors in the `development` environment,
134
+ which is totally understandable. However, if you want to test Gaffe’s behavior in development
135
+ you’ll have to edit the `config/environments/development.rb` file.
136
+
137
+ ```ruby
138
+ # Make Rails use `exceptions_app` in development
139
+ config.consider_all_requests_local = false
103
140
  ```
104
141
 
105
142
  ## License
106
143
 
107
144
  `Gaffe` is © 2013 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/gaffe/blob/master/LICENSE.md) file.
108
145
 
146
+ The mushroom cloud logo is based on [this lovely icon](http://thenounproject.com/noun/mushroom-cloud/#icon-No18596) by [Gokce Ozan](http://thenounproject.com/occultsearcher), from The Noun Project. Used under a [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/) license.
147
+
109
148
  ## About Mirego
110
149
 
111
150
  Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We proudly build mobile applications for [iPhone](http://mirego.com/en/iphone-app-development/ "iPhone application development"), [iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"), [Android](http://mirego.com/en/android-app-development/ "Android application development"), [Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"), [Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and [Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development") in beautiful Quebec City.
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.3'
22
22
  spec.add_development_dependency 'rake'
23
23
  spec.add_development_dependency 'rspec', '~> 2.14'
24
+ spec.add_development_dependency 'coveralls'
24
25
 
25
26
  spec.add_dependency 'rails', '>= 3.2.0'
26
27
  end
@@ -1,3 +1,3 @@
1
1
  module Gaffe
2
- VERSION = '0.2.1'
2
+ VERSION = '1.0' # Woo-hoo
3
3
  end
@@ -55,5 +55,21 @@ describe Gaffe do
55
55
  it { expect(controller).to eql Gaffe::ErrorsController }
56
56
  end
57
57
  end
58
+
59
+ describe :enable! do
60
+ let(:env) { ActionDispatch::TestRequest.new.env }
61
+ let(:action_double) { double(call: lambda { |env| [400, {}, 'SOMETHING WENT WRONG.'] }) }
62
+ before { Gaffe.enable! }
63
+
64
+ specify do
65
+ expect(Gaffe).to receive(:errors_controller_for_request).with(env).and_call_original
66
+ expect(Gaffe::ErrorsController).to receive(:action).with(:show).and_return(action_double)
67
+ expect(action_double).to receive(:call).with(env)
68
+
69
+ # This is the line Rails itself calls
70
+ # https://github.com/rails/rails/blob/fee49a10492efc99409c03f7096d5bd3377b0bbc/actionpack/lib/action_dispatch/middleware/show_exceptions.rb#L43
71
+ Rails.application.config.exceptions_app.call(env)
72
+ end
73
+ end
58
74
  end
59
75
  end
@@ -1,5 +1,8 @@
1
1
  $:.unshift File.expand_path('../../lib', __FILE__)
2
2
 
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
3
6
  require 'rspec'
4
7
  require "action_controller/railtie"
5
8
  require 'gaffe'
@@ -9,6 +12,9 @@ RSpec.configure do |config|
9
12
  # Fake Rails.root
10
13
  Rails.stub(:root).and_return(RAILS_ROOT)
11
14
 
15
+ # Fake Rails.application
16
+ Rails.stub(:application).and_return OpenStruct.new(config: OpenStruct.new, env_config: {})
17
+
12
18
  # Make sure we clear memoized variables before each test
13
19
  [:@configuration].each do |variable|
14
20
  Gaffe.send :remove_instance_variable, variable if Gaffe.instance_variable_defined?(variable)
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaffe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: '1.0'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rémi Prévost
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-08-09 00:00:00.000000000 Z
12
+ date: 2013-10-17 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: bundler
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ~>
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :development
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ~>
29
26
  - !ruby/object:Gem::Version
@@ -31,23 +28,20 @@ dependencies:
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rake
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: rspec
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
46
  - - ~>
53
47
  - !ruby/object:Gem::Version
@@ -55,25 +49,36 @@ dependencies:
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
53
  - - ~>
61
54
  - !ruby/object:Gem::Version
62
55
  version: '2.14'
56
+ - !ruby/object:Gem::Dependency
57
+ name: coveralls
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
63
70
  - !ruby/object:Gem::Dependency
64
71
  name: rails
65
72
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
73
  requirements:
68
- - - ! '>='
74
+ - - '>='
69
75
  - !ruby/object:Gem::Version
70
76
  version: 3.2.0
71
77
  type: :runtime
72
78
  prerelease: false
73
79
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
80
  requirements:
76
- - - ! '>='
81
+ - - '>='
77
82
  - !ruby/object:Gem::Version
78
83
  version: 3.2.0
79
84
  description: Gaffe handles Rails error pages in a clean, simple way.
@@ -115,33 +120,26 @@ files:
115
120
  homepage: https://github.com/mirego/gaffe
116
121
  licenses:
117
122
  - BSD 3-Clause
123
+ metadata: {}
118
124
  post_install_message:
119
125
  rdoc_options: []
120
126
  require_paths:
121
127
  - lib
122
128
  required_ruby_version: !ruby/object:Gem::Requirement
123
- none: false
124
129
  requirements:
125
- - - ! '>='
130
+ - - '>='
126
131
  - !ruby/object:Gem::Version
127
132
  version: '0'
128
- segments:
129
- - 0
130
- hash: 843740072442851156
131
133
  required_rubygems_version: !ruby/object:Gem::Requirement
132
- none: false
133
134
  requirements:
134
- - - ! '>='
135
+ - - '>='
135
136
  - !ruby/object:Gem::Version
136
137
  version: '0'
137
- segments:
138
- - 0
139
- hash: 843740072442851156
140
138
  requirements: []
141
139
  rubyforge_project:
142
- rubygems_version: 1.8.23
140
+ rubygems_version: 2.1.0
143
141
  signing_key:
144
- specification_version: 3
142
+ specification_version: 4
145
143
  summary: Gaffe handles Rails error pages in a clean, simple way.
146
144
  test_files:
147
145
  - spec/gaffe/errors_spec.rb