rambulance 0.6.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56cafb27235f043f1b05600421ba5a01671aa3cd10d9f56beea8b29554e158a9
4
- data.tar.gz: 78329235f2a74d2250f33cf80ab32c1312a507808a056a74a1b12c8fe956cdd3
3
+ metadata.gz: 82265aa18e23300634878ce073d6b72effb62a3a8326832f603d9b17b7640634
4
+ data.tar.gz: 67abe21526c25ab05b2faada53dbadafd62bf414638752cdec3450256e326e3a
5
5
  SHA512:
6
- metadata.gz: 6d64689dae226f3d81305cf569f8de5ea5d90a261de6dd305441dfb231b5565f3821681de0d88895019953d2db6b50829b3c2dde3dcd8c919b4b430f844d3cff
7
- data.tar.gz: 3783088dae915e9ac27897858dedb939017fc82d4bda229db4d10ea629bad01e1d14cdfef195e1c04877bee893fda0ae4e258df507d4f0f7552b5c992b05dba3
6
+ metadata.gz: 97932a0989390b458d8b697cb3be797f0441b623898a34d03e1920ff50f1d298b6ec5c03650b63adf6191a18ed22e66efda0c71686022691e48dab3cd5bcc836
7
+ data.tar.gz: 2af8602230f377774c17cb1f2ce0e1861a28880f7e5682807d135772fb51d9f69c8613f772866b082efccdfc8e5158971acfeedce16bbfb95c24afc812d77053
data/.travis.yml CHANGED
@@ -1,94 +1,62 @@
1
1
  language: ruby
2
- script: bundle exec rake
3
2
  cache: bundler
4
3
  sudo: false
5
4
 
5
+ script:
6
+ - bundle exec rake
7
+
6
8
  before_install:
7
9
  - gem update --system
8
- - gem pristine bundler
10
+ - gem install bundler
9
11
 
10
12
  rvm:
11
- - 2.0.0
12
- - 2.1
13
- - 2.2.9
14
- - 2.3.6
15
- - 2.4.3
16
- - 2.5.0
13
+ - 2.3.8
14
+ - 2.4.10
15
+ - 2.5.8
16
+ - 2.6.6
17
+ - 2.7.1
17
18
  - ruby-head
18
- - jruby-9.1.16.0
19
+ - jruby-9.2.11.1
19
20
  - jruby-head
20
21
 
21
22
  gemfile:
22
- - gemfiles/rails_32.gemfile
23
- - gemfiles/rails_40.gemfile
24
- - gemfiles/rails_41.gemfile
25
23
  - gemfiles/rails_42.gemfile
26
24
  - gemfiles/rails_50.gemfile
27
25
  - gemfiles/rails_51.gemfile
28
26
  - gemfiles/rails_52.gemfile
27
+ - gemfiles/rails_60.gemfile
29
28
  - gemfiles/rails_edge.gemfile
30
29
 
31
30
  matrix:
32
31
  exclude:
33
- - rvm: 2.0.0
34
- gemfile: gemfiles/rails_50.gemfile
35
- - rvm: 2.0.0
36
- gemfile: gemfiles/rails_51.gemfile
37
- - rvm: 2.0.0
38
- gemfile: gemfiles/rails_52.gemfile
39
- - rvm: 2.0.0
32
+ - rvm: 2.3.8
33
+ gemfile: gemfiles/rails_60.gemfile
34
+ - rvm: 2.3.8
40
35
  gemfile: gemfiles/rails_edge.gemfile
41
- - rvm: 2.1
36
+ - rvm: 2.4.10
37
+ gemfile: gemfiles/rails_60.gemfile
38
+ - rvm: 2.4.10
39
+ gemfile: gemfiles/rails_edge.gemfile
40
+ - rvm: 2.6.6
41
+ gemfile: gemfiles/rails_42.gemfile
42
+ - rvm: 2.7.1
43
+ gemfile: gemfiles/rails_42.gemfile
44
+ - rvm: 2.7.1
42
45
  gemfile: gemfiles/rails_50.gemfile
43
- - rvm: 2.1
46
+ - rvm: 2.7.1
44
47
  gemfile: gemfiles/rails_51.gemfile
45
- - rvm: 2.1
48
+ - rvm: 2.7.1
46
49
  gemfile: gemfiles/rails_52.gemfile
47
- - rvm: 2.1
48
- gemfile: gemfiles/rails_edge.gemfile
49
- - rvm: 2.2.9
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
55
- - rvm: 2.3.6
56
- gemfile: gemfiles/rails_32.gemfile
57
- - rvm: 2.3.6
58
- gemfile: gemfiles/rails_edge.gemfile
59
- - rvm: 2.4.3
60
- gemfile: gemfiles/rails_32.gemfile
61
- - rvm: 2.4.3
62
- gemfile: gemfiles/rails_40.gemfile
63
- - rvm: 2.4.3
64
- gemfile: gemfiles/rails_41.gemfile
65
- - rvm: 2.5.0
66
- gemfile: gemfiles/rails_32.gemfile
67
- - rvm: 2.5.0
68
- gemfile: gemfiles/rails_40.gemfile
69
- - rvm: 2.5.0
70
- gemfile: gemfiles/rails_41.gemfile
71
50
  - rvm: ruby-head
72
- gemfile: gemfiles/rails_32.gemfile
51
+ gemfile: gemfiles/rails_42.gemfile
73
52
  - rvm: ruby-head
74
- gemfile: gemfiles/rails_40.gemfile
53
+ gemfile: gemfiles/rails_50.gemfile
75
54
  - rvm: ruby-head
76
- gemfile: gemfiles/rails_41.gemfile
77
- - rvm: jruby-9.1.16.0
78
- gemfile: gemfiles/rails_32.gemfile
79
- - rvm: jruby-9.1.16.0
80
- gemfile: gemfiles/rails_40.gemfile
81
- - rvm: jruby-9.1.16.0
82
- gemfile: gemfiles/rails_41.gemfile
83
- - rvm: jruby-head
84
- gemfile: gemfiles/rails_32.gemfile
85
- - rvm: jruby-head
86
- gemfile: gemfiles/rails_40.gemfile
87
- - rvm: jruby-head
88
- gemfile: gemfiles/rails_41.gemfile
55
+ gemfile: gemfiles/rails_51.gemfile
56
+ - rvm: ruby-head
57
+ gemfile: gemfiles/rails_52.gemfile
89
58
  allow_failures:
90
59
  - rvm: ruby-head
91
- - rvm: jruby-9.1.16.0
60
+ - rvm: jruby-9.2.11.1
92
61
  - rvm: jruby-head
93
62
  - gemfile: gemfiles/rails_edge.gemfile
94
- - gemfile: gemfiles/rails_32.gem
data/Appraisals CHANGED
@@ -43,9 +43,15 @@ appraise "rails_51" do
43
43
  end
44
44
 
45
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"
46
+ gem "activesupport", "~> 5.2.0"
47
+ gem "actionpack", "~> 5.2.0"
48
+ gem "railties", "~> 5.2.0"
49
+ end
50
+
51
+ appraise "rails_60" do
52
+ gem "activesupport", "~> 6.0.0.rc1"
53
+ gem "actionpack", "~> 6.0.0.rc1"
54
+ gem "railties", "~> 6.0.0.rc1"
49
55
  end
50
56
 
51
57
  appraise "rails_edge" do
data/CHANGELOG.md CHANGED
@@ -1,3 +1,75 @@
1
+ ## v1.1.1 (unreleased)
2
+
3
+ - Fixes a bug where a malformed `Content-Type` header could break the exceptions app (#55, @gingerlime)
4
+
5
+ ## [v1.1.0](https://github.com/yuki24/rambulance/tree/v1.1.0)
6
+
7
+ _<sup>released at 2020-05-23 02:52:27 UTC</sup>_
8
+
9
+ #### Features
10
+
11
+ - Add support for Ruby 2.7 ([<tt>718531c</tt>](https://github.com/yuki24/rambulance/commit/718531c45b61d01dce91f401fd81dd6aefdefb31))
12
+
13
+ #### Bug fixes
14
+
15
+ - Fixes a bug where malformed MIME type in HTTP headers could break the exceptions app ([#53](https://github.com/yuki24/rambulance/issues/53), [#54](https://github.com/yuki24/rambulance/pull/54), [@gingerlime](https://github.com/gingerlime))
16
+
17
+ ## [v1.0.3](https://github.com/yuki24/rambulance/tree/v1.0.3)
18
+
19
+ _<sup>released at 2019-10-03 03:39:17 UTC</sup>_
20
+
21
+ #### Fixes
22
+
23
+ - Fixes a bug where custom exceptions app can not be loaded properly on Rails 6 and Zeitwerk ([#52](https://github.com/yuki24/rambulance/issues/52), [@sho918](https://github.com/sho918))
24
+
25
+ ## [v1.0.2](https://github.com/yuki24/rambulance/tree/v1.0.2)
26
+
27
+ _<sup>released at 2019-06-06 23:39:38 UTC</sup>_
28
+
29
+ #### Fixes
30
+
31
+ - Fixes a bug where `ExceptionsApp` is not loaded when action controller is not loaded ([<tt>ec9d9e5</tt>](https://github.com/yuki24/rambulance/commit/ec9d9e5de98eeec501042a0bbb95ae8ac8d7b4e3))
32
+
33
+ ## [v1.0.1](https://github.com/yuki24/rambulance/tree/v1.0.1)
34
+
35
+ _<sup>released at 2019-06-04 16:30:38 UTC</sup>_
36
+
37
+ #### Fixes
38
+
39
+ - Fixes an issue where `ExceptionsApp` prevents Rails from booting up ([#49](https://github.com/yuki24/rambulance/issues/49))
40
+
41
+ ## [v1.0.0](https://github.com/yuki24/rambulance/tree/v1.0.0)
42
+
43
+ _<sup>released at 2019-06-03 05:01:14 UTC</sup>_
44
+
45
+ #### Features
46
+
47
+ - Add support for Ruby 2.6
48
+ - Add support for Rails 6.0
49
+
50
+ #### Bug fixes
51
+
52
+ - Fixes a bug where POST requests cause the exceptions app to throw an `ActionController::InvalidAuthenticityToken` error on Rails 5.2 ([<tt>d68d677</tt>](https://github.com/yuki24/rambulance/commit/d68d677de75059fa09f70e37c97f4bae95885c53), [#48](https://github.com/yuki24/rambulance/issues/48), [@adrianhuna](https://github.com/adrianhuna))
53
+
54
+ #### Breaking Changes
55
+
56
+ - Drop support for Ruby \<= 2.2
57
+ - Drop support for Rails \<= 4.1
58
+
59
+ ## [v0.6.0](https://github.com/yuki24/rambulance/tree/v0.6.0)
60
+
61
+ _<sup>released at 2018-03-08 18:36:16 UTC</sup>_
62
+
63
+ #### New features
64
+
65
+ - Add support for Rails 5.2
66
+ - Add a test helper method `#with_exceptions_app` for easier testing ([<tt>f5c16b9</tt>](https://github.com/yuki24/rambulance/commit/f5c16b90ecf5eb4903faa30d760bf5863441e9c5), [#27](https://github.com/yuki24/rambulance/pull/27), [@kbaba1001](https://github.com/kbaba1001))
67
+
68
+ #### Bug fixes
69
+
70
+ - Fixed a bug where an `ActionController::UnknownFormat` error could cause a number of issues ([<tt>1b824e6</tt>](https://github.com/yuki24/rambulance/commit/1b824e6c170479ed90e24df1680dd2dec7c98160), [#41](https://github.com/yuki24/rambulance/issues/41), [#42](https://github.com/yuki24/rambulance/pull/42), [@willnet](https://github.com/willnet), [@joker-777](https://github.com/joker-777))
71
+ - Fixed a bug where the methods on the `ExceptionApp` weren't easily inspectable ([<tt>6b4c834</tt>](https://github.com/yuki24/rambulance/commit/6b4c834bb0b8e81f619d9f598310ce68f4f9c66b))
72
+
1
73
  ## [v0.5.0](https://github.com/yuki24/rambulance/tree/v0.5.0)
2
74
 
3
75
  _<sup>released at 2018-01-02 21:36:02 UTC</sup>_
data/Dangerfile ADDED
@@ -0,0 +1,13 @@
1
+ # Sometimes it's a README fix, or something like that - which isn't relevant for
2
+ # including in a project's CHANGELOG for example
3
+ declared_trivial = github.pr_title.include? "#trivial"
4
+
5
+ # Make it more obvious that a PR is a work in progress and shouldn't be merged yet
6
+ warn("PR is classed as Work in Progress") if github.pr_title.include? "WIP"
7
+
8
+ # Warn when there is a big PR
9
+ warn("Big PR") if git.lines_of_code > 500
10
+
11
+ # Don't let testing shortcuts get into master by accident
12
+ fail("fdescribe left in tests") if `grep -r fdescribe test/ `.length > 1
13
+ fail("fit left in tests") if `grep -r fit test/ `.length > 1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Rambulance [![Build Status](https://travis-ci.org/yuki24/rambulance.svg?branch=master)](https://travis-ci.org/yuki24/rambulance)
1
+ # Rambulance [![Build Status](https://travis-ci.org/yuki24/rambulance.svg?branch=master)](https://travis-ci.org/yuki24/rambulance) [![Gem Version](https://badge.fury.io/rb/rambulance.svg)](https://rubygems.org/gems/rambulance)
2
2
 
3
- Rambulance provides a simple and safe way to dynamically render error pages for Rails apps.
3
+ A simple and safe way to dynamically render error pages for Rails apps.
4
4
 
5
5
  ## Features
6
6
 
@@ -10,7 +10,7 @@ Rambulance's exceptions app is simple, skinny and well-tested. It inherits from
10
10
 
11
11
  ### Flexible
12
12
 
13
- You have full control of showing a specific error page for a specific exception. It can also render json responses. It even provides a way to create a custom exceptions app.
13
+ You have full control of which error page to show for a specific exception. It also json rendering (perfect for API apps). It even provides a way to create a custom exceptions app.
14
14
 
15
15
  ### Easy installation and development
16
16
 
@@ -30,7 +30,7 @@ And then execute:
30
30
  $ rails g rambulance:install
31
31
  ```
32
32
 
33
- Rambulance only has support for `erb`. If you would like to use haml or slim templates, please see [How to Convert Your `.erb` to `.slim`](https://github.com/slim-template/slim/wiki/Template-Converters-ERB-to-SLIM) or [html2haml](https://github.com/haml/html2haml).
33
+ Rambulance's generator can only generate `erb` templates. If you want to use haml or slim templates, please see [How to Convert Your `.erb` to `.slim`](https://github.com/slim-template/slim/wiki/Template-Converters-ERB-to-SLIM) or [html2haml](https://github.com/haml/html2haml).
34
34
 
35
35
  Now you can start editing templates like `app/views/errors/not_found.html.erb`. Edit, run `rails server` and open [`localhost:3000/rambulance/not_found`](http://localhost:3000/rambulance/not_found)!
36
36
 
@@ -56,19 +56,10 @@ config.rescue_responses = {
56
56
 
57
57
  ## Local Development
58
58
 
59
- There are 2 ways of editing the templates.
60
-
61
- <!---
62
- ### Open [`localhost:3000/rambulance`](http://localhost:3000/rambulance) in Your Browser
63
-
64
- This page tells all the error pages as well as all the pairs of exceptions/corresponding http status. This is useful when you want to edit templates without changing Rails configuration. Click on one of the links in the page to see what the error page looks like.
65
-
66
- **This feature hasn't been implemented yet.**
67
- -->
68
-
69
59
  ### Open `localhost:3000/rambulance/***` in Your Browser
70
60
 
71
- Just go to one of the error pages via Rambulance:
61
+ Just open one of the error pages via Rambulance:
62
+
72
63
  * [`localhost:3000/rambulance/not_found`](http://localhost:3000/rambulance/not_found) or
73
64
  * [`localhost:3000/rambulance/internal_server_error`](http://localhost:3000/rambulance/internal_server_error)
74
65
 
@@ -92,13 +83,13 @@ If you want to do some more things in a exceptions app, you can also write your
92
83
  $ rails g rambulance:exceptions_app
93
84
  ```
94
85
 
95
- It'll generate your own custom exceptions app. You can use whatever techniques you use in controllers like `before_filter` and `flash[:notice] = "message..."` since it's a grandchild of `ActionController::Base`!
86
+ It will generate your own custom exceptions app. You can use whatever techniques you want to use in controllers like `before_filter` and `flash[:notice] = "message..."` since it's a grandchild of `ActionController::Base`!
96
87
 
97
- **Keep in mind that you shouldn't do too many things because something already went wrong with your application!**
88
+ **Heavily customizing the exceptions app is strongly discouraged as there would be no guard against bugs that occur in the exceptions app.**
98
89
 
99
90
  ## Testing
100
91
 
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:
92
+ Rambulance 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
93
 
103
94
  Rspec:
104
95
 
@@ -132,8 +123,8 @@ Note that testing error pages is not encouraged in Rails as it leads to overuse
132
123
 
133
124
  ## Supported Versions
134
125
 
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
126
+ * Ruby 2.3, 2,4, 2,5, 2.6, trunk, JRuby 9.2, and JRuby head
127
+ * Rails 4.2, 5.0, 5.1, 5.2, 6.0 and edge
137
128
 
138
129
  Rambulance doesn't work with Rails 3.1 and below since they don't provide a way to use a custom exceptions app.
139
130
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activesupport", "~> 5.2.0.rc1"
6
- gem "actionpack", "~> 5.2.0.rc1"
7
- gem "railties", "~> 5.2.0.rc1"
5
+ gem "activesupport", "~> 5.2.0"
6
+ gem "actionpack", "~> 5.2.0"
7
+ gem "railties", "~> 5.2.0"
8
8
 
9
9
  gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 6.0.0.rc1"
6
+ gem "actionpack", "~> 6.0.0.rc1"
7
+ gem "railties", "~> 6.0.0.rc1"
8
+
9
+ gemspec path: "../"
@@ -22,12 +22,12 @@ Rambulance.setup do |config|
22
22
  }
23
23
 
24
24
  # The template name for the layout of the error pages. The default value is
25
- # 'error'. For exmaple, if this value is set to "error_page", Rambulance uses
25
+ # 'error'. For example, if this value is set to "error_page", Rambulance uses
26
26
  # 'app/views/layout/error_page.html.erb' as a layout for all the error pages.
27
27
  config.layout_name = "error"
28
28
 
29
29
  # The directry name to organize error page templates. The default value is
30
- # 'errors'. For exmaple, if this value is set to "error_pages", Rambulance
30
+ # 'errors'. For example, if this value is set to "error_pages", Rambulance
31
31
  # uses e.g. 'app/views/error_pages/not_found.html.erb'.
32
32
  config.view_path = "errors"
33
33
 
@@ -12,11 +12,11 @@ module Rambulance
12
12
  class ExceptionsApp < ActionController::Base
13
13
  layout :layout_name
14
14
 
15
- BAD_REQUEST_EXCEPTION = begin
16
- ActionController::BadRequest
17
- rescue NameError
18
- TypeError # Rails 3.2 doesn't know about ActionController::BadRequest
19
- end
15
+ begin
16
+ skip_forgery_protection
17
+ rescue
18
+ # ignore errors from #skip_forgery_protection since older Rails adds this method later.
19
+ end
20
20
 
21
21
  def self.call(env)
22
22
  exception = env["action_dispatch.exception"]
@@ -33,7 +33,7 @@ module Rambulance
33
33
 
34
34
  def self.local_prefixes
35
35
  [Rambulance.view_path]
36
- end if ActionPack::VERSION::STRING >= "4.2.0"
36
+ end
37
37
 
38
38
  ERROR_HTTP_STATUSES.values.each do |status_in_words|
39
39
  eval <<-ACTION, nil, __FILE__, __LINE__ + 1
@@ -55,26 +55,33 @@ module Rambulance
55
55
  private
56
56
 
57
57
  def process_action(*)
58
+ begin
59
+ request.content_mime_type
60
+ rescue Mime::Type::InvalidMimeType
61
+ request.env["MALFORMED_CONTENT_TYPE"], request.env["CONTENT_TYPE"] = request.env["CONTENT_TYPE"], "text/plain"
62
+ end
63
+
58
64
  begin
59
65
  request.GET
60
- rescue BAD_REQUEST_EXCEPTION
66
+ rescue ActionController::BadRequest
61
67
  request.env["MALFORMED_QUERY_STRING"], request.env["QUERY_STRING"] = request.env["QUERY_STRING"], ""
62
68
  end
63
69
 
64
70
  begin
65
71
  request.POST
66
- rescue BAD_REQUEST_EXCEPTION, ArgumentError
72
+ rescue ActionController::BadRequest
67
73
  request.env["MALFORMED_BODY"], request.env["rack.input"] = request.env["rack.input"], StringIO.new
68
74
  end
69
75
 
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
+ begin
77
+ request.accepts
78
+ rescue Mime::Type::InvalidMimeType
79
+ request.env["MALFORMED_HTTP_ACCEPT"], request.env["HTTP_ACCEPT"] = request.env["HTTP_ACCEPT"], "*/*"
76
80
  end
77
81
 
82
+ # The #formats method needs to be called after the sanitization above.
83
+ request.formats << Mime::Type.lookup('text/plain')
84
+
78
85
  super
79
86
  end
80
87
 
@@ -1,14 +1,30 @@
1
1
  module Rambulance
2
2
  class Railtie < Rails::Railtie
3
3
  initializer 'rambulance', after: :prepend_helpers_path do |app|
4
- require "rambulance/exceptions_app"
4
+ ActiveSupport.on_load(:action_controller) do
5
+ require "rambulance/exceptions_app"
6
+ end
5
7
 
6
8
  app.config.exceptions_app =
7
- begin
8
- ActiveSupport::Dependencies.load_missing_constant(Object, :ExceptionsApp)
9
- ->(env){ ::ExceptionsApp.call(env) }
10
- rescue NameError
11
- ::Rambulance::ExceptionsApp
9
+ if app.config.respond_to?(:autoloader) && app.config.autoloader == :classic
10
+ ->(env) {
11
+ begin
12
+ ActiveSupport::Dependencies.load_missing_constant(Object, :ExceptionsApp)
13
+ ::ExceptionsApp.call(env)
14
+ rescue NameError
15
+ require "rambulance/exceptions_app" if !defined?(::Rambulance::ExceptionsApp)
16
+ ::Rambulance::ExceptionsApp.call(env)
17
+ end
18
+ }
19
+ else
20
+ ->(env) {
21
+ begin
22
+ ::ExceptionsApp.call(env)
23
+ rescue NameError
24
+ require "rambulance/exceptions_app" if !defined?(::Rambulance::ExceptionsApp)
25
+ ::Rambulance::ExceptionsApp.call(env)
26
+ end
27
+ }
12
28
  end
13
29
 
14
30
  ActiveSupport.on_load(:after_initialize) do
@@ -1,3 +1,3 @@
1
1
  module Rambulance
2
- VERSION = "0.6.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -8,6 +8,11 @@ class TestApp < Rails::Application
8
8
  config.eager_load = false
9
9
  config.root = File.dirname(__FILE__)
10
10
  config.autoload_paths += ["#{config.root}/lib"] if ENV["CUSTOM_EXCEPTIONS_APP"]
11
+ config.hosts = "www.example.com"
12
+
13
+ if Rails::VERSION::STRING >= "5.2"
14
+ config.action_controller.default_protect_from_forgery = true
15
+ end
11
16
  end
12
17
  Rails.backtrace_cleaner.remove_silencers!
13
18
  Rails.application.initialize!
@@ -15,7 +20,7 @@ Rails.application.initialize!
15
20
  # routes
16
21
  Rails.application.routes.draw do
17
22
  resources :users
18
- resources :projects, only: :index
23
+ resources :projects, only: [:index, :create]
19
24
  end
20
25
 
21
26
  # custom exception class
@@ -46,6 +51,7 @@ class ApplicationController < ActionController::Base
46
51
  raise "This is a bad filter."
47
52
  end
48
53
  end
54
+
49
55
  class UsersController < ApplicationController
50
56
  if self.respond_to? :skip_before_action
51
57
  skip_before_action :bad_filter, except: :show
@@ -75,12 +81,18 @@ class UsersController < ApplicationController
75
81
  raise ForbiddenException
76
82
  end
77
83
  end
84
+
78
85
  class ProjectsController < ApplicationController
86
+ if self.respond_to?(:skip_forgery_protection)
87
+ skip_forgery_protection
88
+ end
89
+
79
90
  if self.respond_to? :skip_before_action
80
- skip_before_action :bad_filter
91
+ skip_before_action :bad_filter, except: :create
81
92
  else
82
- skip_filter :bad_filter
93
+ skip_filter :bad_filter, except: :create
83
94
  end
84
95
 
85
96
  def index; end
97
+ def create; end
86
98
  end
@@ -29,6 +29,51 @@ class ErrorJsonTest < ActionDispatch::IntegrationTest
29
29
  assert_equal "Page not found", json_response['message']
30
30
  end
31
31
 
32
+ test 'renders an error page on a POST request' do
33
+ post '/projects.json'
34
+
35
+ assert_equal 500, response.status
36
+ assert_equal "Something went wrong", json_response['message']
37
+ end
38
+
39
+ test 'returns an appropriate status based on the rails version when the HTTP Accept header is malformed' do
40
+ if Rails::VERSION::STRING >= '5.1.0'
41
+ post '/users', headers: { "HTTP_ACCEPT" => "image/apng*/*" }
42
+ else
43
+ post '/users', nil, "HTTP_ACCEPT" => "image/apng*/*"
44
+ end
45
+
46
+ if Rails::VERSION::STRING >= '6.0.0'
47
+ assert_equal 406, response.status
48
+ assert_equal "The requested content type is not acceptable.\n", response.body
49
+ elsif Rails::VERSION::STRING >= '5.2.0'
50
+ assert_equal 422, response.status
51
+ elsif Rails::VERSION::STRING >= '5.1.0'
52
+ assert_equal 500, response.status
53
+ elsif Rails::VERSION::STRING >= '4.2.0'
54
+ assert_equal 201, response.status
55
+ end
56
+ end
57
+
58
+ test 'returns an appropriate status based on the rails version when the HTTP Content-type header is malformed' do
59
+ if Rails::VERSION::STRING >= '5.1.0'
60
+ post '/users', headers: { "CONTENT_TYPE" => "charset=gbk" }
61
+ else
62
+ post '/users', nil, "CONTENT_TYPE" => "charset=gbk"
63
+ end
64
+
65
+ if Rails::VERSION::STRING >= '6.0.0'
66
+ assert_equal 406, response.status
67
+ assert_equal "The requested content type is not acceptable.\n", response.body
68
+ elsif Rails::VERSION::STRING >= '5.2.0'
69
+ assert_equal 422, response.status
70
+ elsif Rails::VERSION::STRING >= '5.1.0'
71
+ assert_equal 500, response.status
72
+ elsif Rails::VERSION::STRING >= '4.2.0'
73
+ assert_equal 201, response.status
74
+ end
75
+ end
76
+
32
77
  private
33
78
 
34
79
  def without_layouts
@@ -41,12 +86,12 @@ class ErrorJsonTest < ActionDispatch::IntegrationTest
41
86
  `mv error.html.erb test/fake_app/app/views/layouts/`
42
87
  end
43
88
 
44
- def get(path)
89
+ def get(path, params: {}, headers: {})
45
90
  without_layouts do
46
91
  if Rails::VERSION::STRING >= '5.1.0'
47
- super path, headers: { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }
92
+ super path, params: params, headers: { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }.merge(headers)
48
93
  else
49
- super path, nil, "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json"
94
+ super path, params, { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }.merge(headers)
50
95
  end
51
96
  end
52
97
  end
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.6.0
4
+ version: 1.1.1
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-03-08 00:00:00.000000000 Z
11
+ date: 2020-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -148,6 +148,7 @@ files:
148
148
  - ".travis.yml"
149
149
  - Appraisals
150
150
  - CHANGELOG.md
151
+ - Dangerfile
151
152
  - Gemfile
152
153
  - LICENSE.txt
153
154
  - README.md
@@ -161,6 +162,7 @@ files:
161
162
  - gemfiles/rails_50.gemfile
162
163
  - gemfiles/rails_51.gemfile
163
164
  - gemfiles/rails_52.gemfile
165
+ - gemfiles/rails_60.gemfile
164
166
  - gemfiles/rails_edge.gemfile
165
167
  - lib/generators/rambulance/exceptions_app_generator.rb
166
168
  - lib/generators/rambulance/install_generator.rb
@@ -220,8 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
222
  - !ruby/object:Gem::Version
221
223
  version: '0'
222
224
  requirements: []
223
- rubyforge_project:
224
- rubygems_version: 2.7.6
225
+ rubygems_version: 3.1.3
225
226
  signing_key:
226
227
  specification_version: 4
227
228
  summary: Simple and safe way to dynamically generate error pages