rambulance 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 41a24d609992f2ce07071bb783b231bbc358c66f
4
- data.tar.gz: bee5f47a4df8ed67999da43b29652b613f7fab02
2
+ SHA256:
3
+ metadata.gz: 56cafb27235f043f1b05600421ba5a01671aa3cd10d9f56beea8b29554e158a9
4
+ data.tar.gz: 78329235f2a74d2250f33cf80ab32c1312a507808a056a74a1b12c8fe956cdd3
5
5
  SHA512:
6
- metadata.gz: 216306d2a9b1f76ececd7cf671823f8731f7f7bf4a99c90eb869b20b77fbc6e587d3a4806e3ab23610fe1ad66739d9fa6c06d2e2de80c4e7e34e72efd0bff3d0
7
- data.tar.gz: c51fa8b131ab5fd77b00d73c7a6d85db0dc63bf8fe298643088b36714281d3e787bd1cc8085c798a0498b3ece725dfc35559435420dbca74e26bd97f839d661f
6
+ metadata.gz: 6d64689dae226f3d81305cf569f8de5ea5d90a261de6dd305441dfb231b5565f3821681de0d88895019953d2db6b50829b3c2dde3dcd8c919b4b430f844d3cff
7
+ data.tar.gz: 3783088dae915e9ac27897858dedb939017fc82d4bda229db4d10ea629bad01e1d14cdfef195e1c04877bee893fda0ae4e258df507d4f0f7552b5c992b05dba3
@@ -15,7 +15,7 @@ rvm:
15
15
  - 2.4.3
16
16
  - 2.5.0
17
17
  - ruby-head
18
- - jruby-9.1.15.0
18
+ - jruby-9.1.16.0
19
19
  - jruby-head
20
20
 
21
21
  gemfile:
@@ -25,6 +25,7 @@ gemfile:
25
25
  - gemfiles/rails_42.gemfile
26
26
  - gemfiles/rails_50.gemfile
27
27
  - gemfiles/rails_51.gemfile
28
+ - gemfiles/rails_52.gemfile
28
29
  - gemfiles/rails_edge.gemfile
29
30
 
30
31
  matrix:
@@ -33,18 +34,28 @@ matrix:
33
34
  gemfile: gemfiles/rails_50.gemfile
34
35
  - rvm: 2.0.0
35
36
  gemfile: gemfiles/rails_51.gemfile
37
+ - rvm: 2.0.0
38
+ gemfile: gemfiles/rails_52.gemfile
36
39
  - rvm: 2.0.0
37
40
  gemfile: gemfiles/rails_edge.gemfile
38
41
  - rvm: 2.1
39
42
  gemfile: gemfiles/rails_50.gemfile
40
43
  - rvm: 2.1
41
44
  gemfile: gemfiles/rails_51.gemfile
45
+ - rvm: 2.1
46
+ gemfile: gemfiles/rails_52.gemfile
42
47
  - rvm: 2.1
43
48
  gemfile: gemfiles/rails_edge.gemfile
44
49
  - rvm: 2.2.9
45
50
  gemfile: gemfiles/rails_32.gemfile
51
+ - rvm: 2.2.9
52
+ gemfile: gemfiles/rails_51.gemfile
53
+ - rvm: 2.2.9
54
+ gemfile: gemfiles/rails_edge.gemfile
46
55
  - rvm: 2.3.6
47
56
  gemfile: gemfiles/rails_32.gemfile
57
+ - rvm: 2.3.6
58
+ gemfile: gemfiles/rails_edge.gemfile
48
59
  - rvm: 2.4.3
49
60
  gemfile: gemfiles/rails_32.gemfile
50
61
  - rvm: 2.4.3
@@ -63,11 +74,11 @@ matrix:
63
74
  gemfile: gemfiles/rails_40.gemfile
64
75
  - rvm: ruby-head
65
76
  gemfile: gemfiles/rails_41.gemfile
66
- - rvm: jruby-9.1.15.0
77
+ - rvm: jruby-9.1.16.0
67
78
  gemfile: gemfiles/rails_32.gemfile
68
- - rvm: jruby-9.1.15.0
79
+ - rvm: jruby-9.1.16.0
69
80
  gemfile: gemfiles/rails_40.gemfile
70
- - rvm: jruby-9.1.15.0
81
+ - rvm: jruby-9.1.16.0
71
82
  gemfile: gemfiles/rails_41.gemfile
72
83
  - rvm: jruby-head
73
84
  gemfile: gemfiles/rails_32.gemfile
@@ -77,7 +88,7 @@ matrix:
77
88
  gemfile: gemfiles/rails_41.gemfile
78
89
  allow_failures:
79
90
  - rvm: ruby-head
80
- - rvm: jruby-9.1.15.0
91
+ - rvm: jruby-9.1.16.0
81
92
  - rvm: jruby-head
82
93
  - gemfile: gemfiles/rails_edge.gemfile
83
94
  - gemfile: gemfiles/rails_32.gem
data/Appraisals CHANGED
@@ -42,6 +42,12 @@ appraise "rails_51" do
42
42
  gem "railties", "~> 5.1.0"
43
43
  end
44
44
 
45
+ appraise "rails_52" do
46
+ gem "activesupport", "~> 5.2.0.rc1"
47
+ gem "actionpack", "~> 5.2.0.rc1"
48
+ gem "railties", "~> 5.2.0.rc1"
49
+ end
50
+
45
51
  appraise "rails_edge" do
46
52
  git 'git://github.com/rails/rails.git' do
47
53
  gem "activesupport", require: 'active_support'
@@ -1,3 +1,21 @@
1
+ ## [v0.5.0](https://github.com/yuki24/rambulance/tree/v0.5.0)
2
+
3
+ _<sup>released at 2018-01-02 21:36:02 UTC</sup>_
4
+
5
+ #### New features
6
+
7
+ - Add support for Ruby 2.5.0
8
+ - Add support for Rails 5.1
9
+
10
+ #### Breaking changes & deprecations
11
+
12
+ - Drop support for Ruby 1.9.3
13
+ - Drop support for Haml and Slim templates
14
+
15
+ #### Bug fixes
16
+
17
+ - Fixes a bug where the exceptions app fails to show an error page properly when a malformed body is posted ([<tt>474b6b3</tt>](https://github.com/yuki24/rambulance/commit/474b6b329e5590db3c0a7e33c795b18c00812729), [#40](https://github.com/yuki24/rambulance/issues/40), [@jasim](https://github.com/jasim))
18
+
1
19
  ## [v0.4.0](https://github.com/yuki24/rambulance/tree/v0.4.0)
2
20
 
3
21
  _<sup>released at 2016-10-12 02:25:55 UTC</sup>_
data/README.md CHANGED
@@ -96,10 +96,44 @@ It'll generate your own custom exceptions app. You can use whatever techniques y
96
96
 
97
97
  **Keep in mind that you shouldn't do too many things because something already went wrong with your application!**
98
98
 
99
+ ## Testing
100
+
101
+ Ramnurance ships with a test helper that allows you to test an error page generated by Rails. All you have to do is to `include Rambulance::TestHelper` and you will be able to use the `with_exceptions_app` DSDL:
102
+
103
+ Rspec:
104
+
105
+ ```ruby
106
+ include Rambulance::TestHelper
107
+
108
+ it "shows an error page" do
109
+ with_exceptions_app do
110
+ get '/does_not_exist'
111
+ end
112
+
113
+ assert_equal 404, response.status
114
+ end
115
+ ```
116
+
117
+ Minitest:
118
+
119
+ ```ruby
120
+ include Rambulance::TestHelper
121
+
122
+ test "it shows an error page" do
123
+ with_exceptions_app do
124
+ get '/does_not_exist'
125
+ end
126
+
127
+ assert_equal 404, response.status
128
+ end
129
+ ```
130
+
131
+ Note that testing error pages is not encouraged in Rails as it leads to overuse of the `rescue_from` DSL in controllers.
132
+
99
133
  ## Supported Versions
100
134
 
101
- * Ruby 2.0.0, 2.1, 2.2, 2.3, JRuby 1.7.19, JRuby head, Rubinius 2.4.1 and 2.5.3
102
- * Rails 3.2, 4.0, 4.1, 4.2, 5.0 and edge
135
+ * Ruby 2.0.0, 2.1, 2.2, 2.3, 2,4, 2,5, trunk, JRuby 9.1.16.0, and JRuby head
136
+ * Rails 3.2, 4.0, 4.1, 4.2, 5.0, 5,1, 5,2 and edge
103
137
 
104
138
  Rambulance doesn't work with Rails 3.1 and below since they don't provide a way to use a custom exceptions app.
105
139
 
@@ -0,0 +1 @@
1
+ Something went wrong.
@@ -0,0 +1 @@
1
+ The requested content type is not acceptable.
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 5.2.0.rc1"
6
+ gem "actionpack", "~> 5.2.0.rc1"
7
+ gem "railties", "~> 5.2.0.rc1"
8
+
9
+ gemspec path: "../"
@@ -1,5 +1,7 @@
1
1
  require "rambulance/version"
2
2
  require "rambulance/railtie"
3
+ require "rambulance/engine"
4
+ require "rambulance/test_helper"
3
5
 
4
6
  module Rambulance
5
7
 
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ module Rambulance #:nodoc:
3
+ class Engine < ::Rails::Engine #:nodoc:
4
+ end
5
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rambulance
2
4
  ERROR_HTTP_STATUSES = Rack::Utils::SYMBOL_TO_STATUS_CODE.select do |status_in_words, http_status|
3
5
  # Exclude http statuses that:
@@ -34,7 +36,7 @@ module Rambulance
34
36
  end if ActionPack::VERSION::STRING >= "4.2.0"
35
37
 
36
38
  ERROR_HTTP_STATUSES.values.each do |status_in_words|
37
- eval <<-ACTION
39
+ eval <<-ACTION, nil, __FILE__, __LINE__ + 1
38
40
  def #{status_in_words}
39
41
  render(template_exists?(error_path) ? error_path : error_path(:internal_server_error))
40
42
  end
@@ -43,9 +45,8 @@ module Rambulance
43
45
 
44
46
  def process(action, *args)
45
47
  if action.to_s.empty?
46
- action = request.env["PATH_INFO"][1..-1].to_sym.tap do |status_in_words|
47
- request.env["PATH_INFO"] = "/#{Rack::Utils::SYMBOL_TO_STATUS_CODE[status_in_words]}"
48
- end
48
+ action = request.env["PATH_INFO"][1..-1].to_sym
49
+ request.env["PATH_INFO"] = "/#{Rack::Utils::SYMBOL_TO_STATUS_CODE[action]}"
49
50
  end
50
51
 
51
52
  super
@@ -66,6 +67,14 @@ module Rambulance
66
67
  request.env["MALFORMED_BODY"], request.env["rack.input"] = request.env["rack.input"], StringIO.new
67
68
  end
68
69
 
70
+ # The #formats method needs to be called after the sanitization above.
71
+ if request.respond_to?(:formats)
72
+ request.formats << Mime::Type.lookup('text/plain')
73
+ elsif request.respond_to?(:format) && status == 406
74
+ # TODO: Remove this conditional when dropping support for Rails 3.2
75
+ request.format = Mime::Type.lookup('text/plain')
76
+ end
77
+
69
78
  super
70
79
  end
71
80
 
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ module Rambulance #:nodoc:
3
+ module TestHelper
4
+ # enables the exceptions app in the block.
5
+ #
6
+ # Rspec:
7
+ #
8
+ # it "shows an error page" do
9
+ # with_exceptions_app do
10
+ # get '/'
11
+ # end
12
+ #
13
+ # ...
14
+ # end
15
+ #
16
+ # Minitest:
17
+ #
18
+ # test "it shows an error page" do
19
+ # with_exceptions_app do
20
+ # get '/'
21
+ # end
22
+ #
23
+ # ...
24
+ # end
25
+ #
26
+ def with_exceptions_app(enabled: true)
27
+ org_show_detailed_exceptions = Rails.application.env_config['action_dispatch.show_detailed_exceptions']
28
+ org_show_exceptions = Rails.application.env_config['action_dispatch.show_exceptions']
29
+
30
+ Rails.application.env_config['action_dispatch.show_detailed_exceptions'] = !enabled
31
+ Rails.application.env_config['action_dispatch.show_exceptions'] = enabled
32
+
33
+ yield
34
+ ensure
35
+ Rails.application.env_config['action_dispatch.show_detailed_exceptions'] = org_show_detailed_exceptions
36
+ Rails.application.env_config['action_dispatch.show_exceptions'] = org_show_exceptions
37
+ end
38
+ end
39
+ end
40
+
@@ -1,3 +1,3 @@
1
1
  module Rambulance
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class ExeptionsAppTest < ActionDispatch::IntegrationTest
4
+ test 'returns 404 for unknown format for pages that do not exist' do
5
+ get '/does_not_exist', headers: { 'Accept' => '*/*' }
6
+
7
+ assert_equal 404, response.status
8
+ end
9
+ end
10
+
@@ -15,6 +15,7 @@ Rails.application.initialize!
15
15
  # routes
16
16
  Rails.application.routes.draw do
17
17
  resources :users
18
+ resources :projects, only: :index
18
19
  end
19
20
 
20
21
  # custom exception class
@@ -74,3 +75,12 @@ class UsersController < ApplicationController
74
75
  raise ForbiddenException
75
76
  end
76
77
  end
78
+ class ProjectsController < ApplicationController
79
+ if self.respond_to? :skip_before_action
80
+ skip_before_action :bad_filter
81
+ else
82
+ skip_filter :bad_filter
83
+ end
84
+
85
+ def index; end
86
+ end
@@ -1,6 +1,22 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ErrorPageTest < ActionDispatch::IntegrationTest
4
+ test 'displays the corresponding error page if /rambulance/status_in_words is requested in development' do
5
+ skip
6
+
7
+ visit '/rambulance/forbidden'
8
+
9
+ assert_equal 403, page.status_code
10
+ assert_includes page.body, "Error page"
11
+ assert_includes page.body, "Forbidden."
12
+
13
+ visit '/rambulance/internal_server_error'
14
+
15
+ assert_equal 500, page.status_code
16
+ assert_includes page.body, "Error page"
17
+ assert_includes page.body, "Something went wrong."
18
+ end
19
+
4
20
  test 'displays the 500 page for RuntimeError' do
5
21
  visit '/users/1'
6
22
 
@@ -17,6 +33,21 @@ class ErrorPageTest < ActionDispatch::IntegrationTest
17
33
  assert_includes page.body, "Page not found."
18
34
  end
19
35
 
36
+ test 'displays the 406 page for unknown format' do
37
+ visit '/projects'
38
+
39
+ assert_equal 200, page.status_code # Just to make sure normal html request succeeds
40
+
41
+ visit '/projects.jpeg'
42
+
43
+ if Rails.version < '5.0.0'
44
+ assert_equal 500, page.status_code
45
+ else
46
+ assert_equal 406, page.status_code
47
+ assert_includes page.body, "The requested content type is not acceptable."
48
+ end
49
+ end
50
+
20
51
  test 'displays the 404 page for ActionController::RoutingError' do
21
52
  visit '/doesnt_exist'
22
53
 
@@ -1,6 +1,9 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
 
4
+ # RAILS_ENV needs to be set to development to mount the error page debug view
5
+ ENV['RAILS_ENV'] ||= 'development'
6
+
4
7
  require 'rails'
5
8
  require 'minitest/autorun'
6
9
  require 'minitest/pride'
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ class TestHelperTest < ActionDispatch::IntegrationTest
4
+ include Rambulance::TestHelper
5
+
6
+ test '#with_exceptions_app can enable the exceptions app in test' do
7
+ with_exceptions_app do
8
+ get '/does_not_exist'
9
+ end
10
+
11
+ assert_equal 404, response.status
12
+ end
13
+
14
+ test '#with_exceptions_app can disable the exceptions app in test' do
15
+ with_exceptions_app enabled: false do
16
+ assert_raises ActionController::RoutingError do
17
+ get '/does_not_exist'
18
+ end
19
+ end
20
+ end
21
+ end
22
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rambulance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Nishijima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-02 00:00:00.000000000 Z
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -152,12 +152,15 @@ files:
152
152
  - LICENSE.txt
153
153
  - README.md
154
154
  - Rakefile
155
+ - app/views/errors/internal_server_error.text.erb
156
+ - app/views/errors/not_acceptable.text.erb
155
157
  - gemfiles/rails_32.gemfile
156
158
  - gemfiles/rails_40.gemfile
157
159
  - gemfiles/rails_41.gemfile
158
160
  - gemfiles/rails_42.gemfile
159
161
  - gemfiles/rails_50.gemfile
160
162
  - gemfiles/rails_51.gemfile
163
+ - gemfiles/rails_52.gemfile
161
164
  - gemfiles/rails_edge.gemfile
162
165
  - lib/generators/rambulance/exceptions_app_generator.rb
163
166
  - lib/generators/rambulance/install_generator.rb
@@ -169,15 +172,19 @@ files:
169
172
  - lib/generators/rambulance/templates/views/forbidden.json.jbuilder
170
173
  - lib/generators/rambulance/templates/views/internal_server_error.html.erb
171
174
  - lib/generators/rambulance/templates/views/internal_server_error.json.jbuilder
175
+ - lib/generators/rambulance/templates/views/not_acceptable.text.erb
172
176
  - lib/generators/rambulance/templates/views/not_found.html.erb
173
177
  - lib/generators/rambulance/templates/views/not_found.json.jbuilder
174
178
  - lib/generators/rambulance/templates/views/unprocessable_entity.html.erb
175
179
  - lib/generators/rambulance/templates/views/unprocessable_entity.json.jbuilder
176
180
  - lib/rambulance.rb
181
+ - lib/rambulance/engine.rb
177
182
  - lib/rambulance/exceptions_app.rb
178
183
  - lib/rambulance/railtie.rb
184
+ - lib/rambulance/test_helper.rb
179
185
  - lib/rambulance/version.rb
180
186
  - rambulance.gemspec
187
+ - test/exceptions_app_test.rb
181
188
  - test/fake_app/app/helpers/application_helper.rb
182
189
  - test/fake_app/app/views/errors/bad_request.html.erb
183
190
  - test/fake_app/app/views/errors/forbidden.html.erb
@@ -187,11 +194,13 @@ files:
187
194
  - test/fake_app/app/views/errors/not_found.json.jbuilder
188
195
  - test/fake_app/app/views/layouts/application.html.erb
189
196
  - test/fake_app/app/views/layouts/error.html.erb
197
+ - test/fake_app/app/views/projects/index.html.erb
190
198
  - test/fake_app/lib/exceptions_app.rb
191
199
  - test/fake_app/rails_app.rb
192
200
  - test/requests/error_json_test.rb
193
201
  - test/requests/error_page_test.rb
194
202
  - test/test_helper.rb
203
+ - test/test_helper_test.rb
195
204
  homepage: http://github.com/yuki24/rambulance
196
205
  licenses:
197
206
  - MIT
@@ -212,11 +221,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
221
  version: '0'
213
222
  requirements: []
214
223
  rubyforge_project:
215
- rubygems_version: 2.6.14
224
+ rubygems_version: 2.7.6
216
225
  signing_key:
217
226
  specification_version: 4
218
227
  summary: Simple and safe way to dynamically generate error pages
219
228
  test_files:
229
+ - test/exceptions_app_test.rb
220
230
  - test/fake_app/app/helpers/application_helper.rb
221
231
  - test/fake_app/app/views/errors/bad_request.html.erb
222
232
  - test/fake_app/app/views/errors/forbidden.html.erb
@@ -226,8 +236,10 @@ test_files:
226
236
  - test/fake_app/app/views/errors/not_found.json.jbuilder
227
237
  - test/fake_app/app/views/layouts/application.html.erb
228
238
  - test/fake_app/app/views/layouts/error.html.erb
239
+ - test/fake_app/app/views/projects/index.html.erb
229
240
  - test/fake_app/lib/exceptions_app.rb
230
241
  - test/fake_app/rails_app.rb
231
242
  - test/requests/error_json_test.rb
232
243
  - test/requests/error_page_test.rb
233
244
  - test/test_helper.rb
245
+ - test/test_helper_test.rb