gaffe 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +6 -5
- data/lib/gaffe/errors_controller_resolver.rb +6 -1
- data/lib/gaffe/version.rb +1 -1
- data/spec/application_controller_helper.rb +3 -0
- data/spec/gaffe/errors_controller_resolver_spec.rb +7 -1
- data/spec/spec_helper.rb +2 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a299d255e8e71ef667c749630dfca9ea9aac630a
|
4
|
+
data.tar.gz: 762d2f648c24cfd0714331e22894f839c1d80ee9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6ae8586749c662a4e4427ff64d9e9254d3770dbd05467d31ce2125c075962448eb788def45c58d7c2ab6511713943914e4b41d8d3abd3a161ad6d3440225e31
|
7
|
+
data.tar.gz: 641f0bdb5cf608df3093cc3b8e20fba86a6affba4cb29841a432b3d0574602ae8a11b8230e28fef8f69dadc3b86edbcca09ece7b54558fea8a62e43fbf5bc7c7
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -47,16 +47,17 @@ end
|
|
47
47
|
Gaffe.enable!
|
48
48
|
```
|
49
49
|
|
50
|
-
It’s also possible to use a custom controller based on the URL in which the error has occured.
|
51
|
-
useful if you have an application that also serves API requests via
|
52
|
-
through JSON and regular errors through HTML pages.
|
50
|
+
It’s also possible to use a custom controller based on the URL in which the error has occured. Both absolute and
|
51
|
+
relative URL supported. This is especially useful if you have an application that also serves API requests via
|
52
|
+
JSON. You would probably want to serve API errors through JSON and regular errors through HTML pages.
|
53
53
|
|
54
54
|
```ruby
|
55
55
|
# config/initializers/gaffe.rb
|
56
56
|
Gaffe.configure do |config|
|
57
57
|
config.errors_controller = {
|
58
58
|
%r[^/api/] => 'Api::ErrorsController',
|
59
|
-
%r[^/] => 'ErrorsController'
|
59
|
+
%r[^/] => 'ErrorsController',
|
60
|
+
%r[^www.example.com] => 'HostSpecificErrorsController'
|
60
61
|
}
|
61
62
|
end
|
62
63
|
|
@@ -179,7 +180,7 @@ To test responses sent by Gaffe, you must use *request tests*.
|
|
179
180
|
|
180
181
|
## License
|
181
182
|
|
182
|
-
`Gaffe` is © 2013-
|
183
|
+
`Gaffe` is © 2013-2016 [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.
|
183
184
|
|
184
185
|
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.
|
185
186
|
|
@@ -30,7 +30,12 @@ module Gaffe
|
|
30
30
|
private
|
31
31
|
|
32
32
|
def request_controller(controllers)
|
33
|
-
controllers.find
|
33
|
+
matched_controllers = controllers.find do |pattern, _|
|
34
|
+
relative_url = @env['REQUEST_URI']
|
35
|
+
absolute_url = @env['HTTP_HOST'] + relative_url
|
36
|
+
[relative_url, absolute_url].any? { |url| (url =~ pattern).present? }
|
37
|
+
end
|
38
|
+
matched_controllers.try(:last)
|
34
39
|
end
|
35
40
|
end
|
36
41
|
end
|
data/lib/gaffe/version.rb
CHANGED
@@ -32,7 +32,8 @@ describe Gaffe::ErrorsControllerResolver do
|
|
32
32
|
Gaffe.configure do |config|
|
33
33
|
config.errors_controller = {
|
34
34
|
%r{^/web/} => :web_controller,
|
35
|
-
%r{^/api/} => :api_controller
|
35
|
+
%r{^/api/} => :api_controller,
|
36
|
+
%r{^www.com} => :host_specific_controller
|
36
37
|
}
|
37
38
|
end
|
38
39
|
end
|
@@ -42,6 +43,11 @@ describe Gaffe::ErrorsControllerResolver do
|
|
42
43
|
it { expect(controller).to eql :api_controller }
|
43
44
|
end
|
44
45
|
|
46
|
+
context 'with error coming from matching HTTP_HOST' do
|
47
|
+
let(:env) { request.env.merge('HTTP_HOST' => 'www.com', 'REQUEST_URI' => '/') }
|
48
|
+
it { expect(controller).to eql :host_specific_controller }
|
49
|
+
end
|
50
|
+
|
45
51
|
context 'with errors coming from non-matching URL' do
|
46
52
|
let(:env) { request.env.merge 'REQUEST_URI' => '/what' }
|
47
53
|
it { expect(controller).to eql Gaffe::ErrorsController }
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,8 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
3
3
|
require 'rspec'
|
4
4
|
require 'action_controller/railtie'
|
5
5
|
require 'gaffe'
|
6
|
+
require_relative './application_controller_helper'
|
7
|
+
require 'gaffe/errors_controller'
|
6
8
|
|
7
9
|
RSpec.configure do |config|
|
8
10
|
# Disable `should` syntax
|
@@ -25,10 +27,6 @@ RSpec.configure do |config|
|
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
# We need a fake "ApplicationController" because Gaffe's default controller inherits from it
|
29
|
-
class ApplicationController < ActionController::Base
|
30
|
-
end
|
31
|
-
|
32
30
|
def test_request
|
33
31
|
if Rails::VERSION::MAJOR >= 5
|
34
32
|
ActionDispatch::TestRequest.create
|
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: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rémi Prévost
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- lib/gaffe/errors_controller.rb
|
133
133
|
- lib/gaffe/errors_controller_resolver.rb
|
134
134
|
- lib/gaffe/version.rb
|
135
|
+
- spec/application_controller_helper.rb
|
135
136
|
- spec/gaffe/errors_controller_resolver_spec.rb
|
136
137
|
- spec/gaffe/errors_spec.rb
|
137
138
|
- spec/gaffe/gaffe_spec.rb
|
@@ -161,6 +162,7 @@ signing_key:
|
|
161
162
|
specification_version: 4
|
162
163
|
summary: Gaffe handles Rails error pages in a clean, simple way.
|
163
164
|
test_files:
|
165
|
+
- spec/application_controller_helper.rb
|
164
166
|
- spec/gaffe/errors_controller_resolver_spec.rb
|
165
167
|
- spec/gaffe/errors_spec.rb
|
166
168
|
- spec/gaffe/gaffe_spec.rb
|