rambulance 1.0.2 → 2.0.0

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: 74116493ad5ada66c35eb31534fadb7392c54847bdbc2fc156c14a10fa050c44
4
- data.tar.gz: 2272a7686a4b88815488ccd3a7f0e3325ecc5596e4ec687552407a0f4d9b21e4
3
+ metadata.gz: 1592ef1d6b4e68634579d8f663c1bfac1b90b5274e3b4c855b7b2701a02dce75
4
+ data.tar.gz: e99889eca33ec4df242bb234d8824ce8badad039bce96acf61997bb697df82c0
5
5
  SHA512:
6
- metadata.gz: c680ce9ec05c5ef1c89cc91dc59606294d482cebc8a8b0795f47715b80ee4108c3818e2760e5c9eb738876c61bd99d7cb65f97876dc3754a1af1b61b2ac5299c
7
- data.tar.gz: af312ac6bdcfa74255360d17d84a736c615fd833be9586892500267c440332a765e6c16015cdaaa69d694695d4360f09efa5ad9b91ac4500dbf8210a973b8282
6
+ metadata.gz: 60999da77e4ea5792dee0edc0725ed212156e0cf0299c0362cd1790c8740817b8aa3186dea64478272ffb5a6e3ec815c6e61ea6e4f5078c6342be9269bcdcafd
7
+ data.tar.gz: 76ab3afe64eda416e60946160e3bbb2f373c7c83ba2466de94b71b79c049e16c6af35d837c8269227abac757b5ddb5dfec1078e964ce18247282f008869087bc
@@ -0,0 +1,109 @@
1
+ name: build
2
+
3
+ on:
4
+ - push
5
+
6
+ jobs:
7
+ stable:
8
+ strategy:
9
+ matrix:
10
+ ruby_version:
11
+ - '3.0'
12
+ - '2.7'
13
+ - '2.6'
14
+ - '2.5'
15
+ - '2.4'
16
+ - '2.3'
17
+ - 'jruby-9.2.19.0'
18
+ gemfile:
19
+ - gemfiles/rails_61.gemfile
20
+ - gemfiles/rails_60.gemfile
21
+ - gemfiles/rails_52.gemfile
22
+ - gemfiles/rails_51.gemfile
23
+ - gemfiles/rails_50.gemfile
24
+ - gemfiles/rails_42.gemfile
25
+ exclude:
26
+ - ruby_version: '3.0'
27
+ gemfile: gemfiles/rails_52.gemfile
28
+ - ruby_version: '3.0'
29
+ gemfile: gemfiles/rails_51.gemfile
30
+ - ruby_version: '3.0'
31
+ gemfile: gemfiles/rails_50.gemfile
32
+ - ruby_version: '3.0'
33
+ gemfile: gemfiles/rails_42.gemfile
34
+ - ruby_version: '2.7'
35
+ gemfile: gemfiles/rails_52.gemfile
36
+ - ruby_version: '2.7'
37
+ gemfile: gemfiles/rails_51.gemfile
38
+ - ruby_version: '2.7'
39
+ gemfile: gemfiles/rails_50.gemfile
40
+ - ruby_version: '2.7'
41
+ gemfile: gemfiles/rails_42.gemfile
42
+ - ruby_version: '2.6'
43
+ gemfile: gemfiles/rails_42.gemfile
44
+ - ruby_version: '2.4'
45
+ gemfile: gemfiles/rails_61.gemfile
46
+ - ruby_version: '2.4'
47
+ gemfile: gemfiles/rails_60.gemfile
48
+ - ruby_version: '2.3'
49
+ gemfile: gemfiles/rails_61.gemfile
50
+ - ruby_version: '2.3'
51
+ gemfile: gemfiles/rails_60.gemfile
52
+ - ruby_version: 'jruby-9.2.19.0'
53
+ gemfile: gemfiles/rails_51.gemfile
54
+ - ruby_version: 'jruby-9.2.19.0'
55
+ gemfile: gemfiles/rails_50.gemfile
56
+ - ruby_version: 'jruby-9.2.19.0'
57
+ gemfile: gemfiles/rails_42.gemfile
58
+ runs-on: ubuntu-18.04
59
+ env:
60
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
61
+ steps:
62
+ - uses: actions/checkout@v2
63
+ - name: Set up Ruby
64
+ uses: ruby/setup-ruby@v1
65
+ with:
66
+ ruby-version: ${{ matrix.ruby_version }}
67
+ bundler-cache: true
68
+ - run: bundle exec rake
69
+
70
+ rails_edge:
71
+ strategy:
72
+ matrix:
73
+ ruby_version:
74
+ - '3.0'
75
+ - '2.7'
76
+ gemfile:
77
+ - gemfiles/rails_edge.gemfile
78
+ runs-on: ubuntu-18.04
79
+ env:
80
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
81
+ steps:
82
+ - uses: actions/checkout@v2
83
+ - name: Set up Ruby
84
+ uses: ruby/setup-ruby@v1
85
+ with:
86
+ ruby-version: ${{ matrix.ruby_version }}
87
+ bundler-cache: true
88
+ - run: bundle exec rake
89
+
90
+ ruby_edge:
91
+ strategy:
92
+ matrix:
93
+ ruby_version:
94
+ - 'ruby-head'
95
+ gemfile:
96
+ - gemfiles/rails_edge.gemfile
97
+ - gemfiles/rails_61.gemfile
98
+ - gemfiles/rails_60.gemfile
99
+ runs-on: ubuntu-18.04
100
+ env:
101
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
102
+ steps:
103
+ - uses: actions/checkout@v2
104
+ - name: Set up Ruby
105
+ uses: ruby/setup-ruby@v1
106
+ with:
107
+ ruby-version: ${{ matrix.ruby_version }}
108
+ bundler-cache: true
109
+ - run: bundle exec rake || echo "Ruby edge test is done."
data/Appraisals CHANGED
@@ -1,26 +1,3 @@
1
- appraise "rails_32" do
2
- gem "activesupport", "~> 3.2.0"
3
- gem "actionpack", "~> 3.2.0"
4
- gem "railties", "~> 3.2.0"
5
- gem "test-unit" if RUBY_VERSION >= "2.2.0"
6
- gem 'nokogiri', '1.6.8.1' if RUBY_VERSION == "2.0.0"
7
- end
8
-
9
- appraise "rails_40" do
10
- gem "activesupport", "~> 4.0.0"
11
- gem "actionpack", "~> 4.0.0"
12
- gem "railties", "~> 4.0.0"
13
- gem "test-unit" if RUBY_VERSION >= "2.2.0"
14
- gem 'nokogiri', '1.6.8.1' if RUBY_VERSION == "2.0.0"
15
- end
16
-
17
- appraise "rails_41" do
18
- gem "activesupport", "~> 4.1.0"
19
- gem "actionpack", "~> 4.1.0"
20
- gem "railties", "~> 4.1.0"
21
- gem 'nokogiri', '1.6.8.1' if RUBY_VERSION == "2.0.0"
22
- end
23
-
24
1
  appraise "rails_42" do
25
2
  gem "activesupport", "~> 4.2.0"
26
3
  gem "actionpack", "~> 4.2.0"
@@ -49,9 +26,15 @@ appraise "rails_52" do
49
26
  end
50
27
 
51
28
  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"
29
+ gem "activesupport", "~> 6.0.0"
30
+ gem "actionpack", "~> 6.0.0"
31
+ gem "railties", "~> 6.0.0"
32
+ end
33
+
34
+ appraise "rails_61" do
35
+ gem "activesupport", "~> 6.1.0"
36
+ gem "actionpack", "~> 6.1.0"
37
+ gem "railties", "~> 6.1.0"
55
38
  end
56
39
 
57
40
  appraise "rails_edge" do
data/CHANGELOG.md CHANGED
@@ -1,3 +1,54 @@
1
+ ## v2.0.0
2
+
3
+ #### Breaking Changes
4
+
5
+ - Drop support for Rails 4.1 and older (https://github.com/yuki24/rambulance/pull/62, @yuki24)
6
+
7
+ #### Features
8
+
9
+ - Add support for Rails 6.1 and Ruby 3.0 (https://github.com/yuki24/rambulance/pull/61, https://github.com/yuki24/rambulance/pull/63, @gingerlime, @yuki24)
10
+
11
+ #### Bug fixes
12
+
13
+ - POST with invalid JSON triggers a 500 (https://github.com/yuki24/rambulance/pull/59, @gingerlime)
14
+ - Fix 'directry' typo (https://github.com/yuki24/rambulance/pull/57, @andyw8)
15
+
16
+ ## [v1.1.1](https://github.com/yuki24/rambulance/tree/v1.1.1)
17
+
18
+ _<sup>released at 2020-05-28 23:22:10 UTC</sup>_
19
+
20
+ #### Bug fixes
21
+
22
+ - Fixes a bug where a malformed `Content-Type` header could break the exceptions app ([#55](https://github.com/yuki24/rambulance/pull/55), [@gingerlime](https://github.com/gingerlime))
23
+
24
+ ## [v1.1.0](https://github.com/yuki24/rambulance/tree/v1.1.0)
25
+
26
+ _<sup>released at 2020-05-23 02:52:27 UTC</sup>_
27
+
28
+ #### Features
29
+
30
+ - Add support for Ruby 2.7 ([<tt>718531c</tt>](https://github.com/yuki24/rambulance/commit/718531c45b61d01dce91f401fd81dd6aefdefb31))
31
+
32
+ #### Bug fixes
33
+
34
+ - 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))
35
+
36
+ ## [v1.0.3](https://github.com/yuki24/rambulance/tree/v1.0.3)
37
+
38
+ _<sup>released at 2019-10-03 03:39:17 UTC</sup>_
39
+
40
+ #### Fixes
41
+
42
+ - 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))
43
+
44
+ ## [v1.0.2](https://github.com/yuki24/rambulance/tree/v1.0.2)
45
+
46
+ _<sup>released at 2019-06-06 23:39:38 UTC</sup>_
47
+
48
+ #### Fixes
49
+
50
+ - Fixes a bug where `ExceptionsApp` is not loaded when action controller is not loaded ([<tt>ec9d9e5</tt>](https://github.com/yuki24/rambulance/commit/ec9d9e5de98eeec501042a0bbb95ae8ac8d7b4e3))
51
+
1
52
  ## [v1.0.1](https://github.com/yuki24/rambulance/tree/v1.0.1)
2
53
 
3
54
  _<sup>released at 2019-06-04 16:30:38 UTC</sup>_
@@ -50,7 +101,7 @@ _<sup>released at 2018-01-02 21:36:02 UTC</sup>_
50
101
  #### Breaking changes & deprecations
51
102
 
52
103
  - Drop support for Ruby 1.9.3
53
- - Drop support for generating Haml and Slim templates on `rails g rambulance:install`
104
+ - Drop support for Haml and Slim templates
54
105
 
55
106
  #### Bug fixes
56
107
 
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
- **Note that customizing the exceptions app is strongly discouraged as there would be no guard against bugs that occur in the exceptions app.**
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.3, 2,4, 2,5, trunk, JRuby 9.1.16.0, and JRuby head
136
- * Rails 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", "~> 6.0.0.rc1"
6
- gem "actionpack", "~> 6.0.0.rc1"
7
- gem "railties", "~> 6.0.0.rc1"
5
+ gem "activesupport", "~> 6.0.0"
6
+ gem "actionpack", "~> 6.0.0"
7
+ gem "railties", "~> 6.0.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.1.0"
6
+ gem "actionpack", "~> 6.1.0"
7
+ gem "railties", "~> 6.1.0"
8
+
9
+ gemspec path: "../"
@@ -26,7 +26,7 @@ Rambulance.setup do |config|
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
- # The directry name to organize error page templates. The default value is
29
+ # The directory name to organize error page templates. The default value is
30
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"
@@ -9,6 +9,16 @@ module Rambulance
9
9
  http_status >= 400 && ![418, 427, 430, 509].include?(http_status)
10
10
  end.invert
11
11
 
12
+ BAD_REQUEST_ERRORS = [
13
+ ActionController::BadRequest,
14
+ begin
15
+ ActionDispatch::Http::Parameters::ParseError # Rails >= 5.2.0
16
+ rescue NameError; end,
17
+ begin
18
+ ActionDispatch::ParamsParser::ParseError # Rails < 5.2.0
19
+ rescue NameError; end,
20
+ ].compact.freeze
21
+
12
22
  class ExceptionsApp < ActionController::Base
13
23
  layout :layout_name
14
24
 
@@ -55,6 +65,12 @@ module Rambulance
55
65
  private
56
66
 
57
67
  def process_action(*)
68
+ begin
69
+ request.content_mime_type
70
+ rescue Mime::Type::InvalidMimeType
71
+ request.env["MALFORMED_CONTENT_TYPE"], request.env["CONTENT_TYPE"] = request.env["CONTENT_TYPE"], "text/plain"
72
+ end
73
+
58
74
  begin
59
75
  request.GET
60
76
  rescue ActionController::BadRequest
@@ -63,10 +79,16 @@ module Rambulance
63
79
 
64
80
  begin
65
81
  request.POST
66
- rescue ActionController::BadRequest
82
+ rescue *BAD_REQUEST_ERRORS
67
83
  request.env["MALFORMED_BODY"], request.env["rack.input"] = request.env["rack.input"], StringIO.new
68
84
  end
69
85
 
86
+ begin
87
+ request.accepts
88
+ rescue Mime::Type::InvalidMimeType
89
+ request.env["MALFORMED_HTTP_ACCEPT"], request.env["HTTP_ACCEPT"] = request.env["HTTP_ACCEPT"], "*/*"
90
+ end
91
+
70
92
  # The #formats method needs to be called after the sanitization above.
71
93
  request.formats << Mime::Type.lookup('text/plain')
72
94
 
@@ -5,15 +5,27 @@ module Rambulance
5
5
  require "rambulance/exceptions_app"
6
6
  end
7
7
 
8
- app.config.exceptions_app = ->(env) {
9
- begin
10
- ActiveSupport::Dependencies.load_missing_constant(Object, :ExceptionsApp)
11
- ::ExceptionsApp.call(env)
12
- rescue NameError
13
- require "rambulance/exceptions_app" if !defined?(::Rambulance::ExceptionsApp)
14
- ::Rambulance::ExceptionsApp.call(env)
8
+ app.config.exceptions_app =
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
+ }
15
28
  end
16
- }
17
29
 
18
30
  ActiveSupport.on_load(:after_initialize) do
19
31
  Rails.application.routes.append do
@@ -1,3 +1,3 @@
1
1
  module Rambulance
2
- VERSION = "1.0.2"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/rambulance.rb CHANGED
@@ -13,7 +13,7 @@ module Rambulance
13
13
  mattr_accessor :layout_name
14
14
  @@layout_name = "application"
15
15
 
16
- # The directry name to organize error page templates.
16
+ # The directory name to organize error page templates.
17
17
  mattr_accessor :view_path
18
18
  @@view_path = "errors"
19
19
 
@@ -8,6 +8,7 @@ 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"
11
12
 
12
13
  if Rails::VERSION::STRING >= "5.2"
13
14
  config.action_controller.default_protect_from_forgery = true
@@ -50,6 +51,7 @@ class ApplicationController < ActionController::Base
50
51
  raise "This is a bad filter."
51
52
  end
52
53
  end
54
+
53
55
  class UsersController < ApplicationController
54
56
  if self.respond_to? :skip_before_action
55
57
  skip_before_action :bad_filter, except: :show
@@ -79,6 +81,7 @@ class UsersController < ApplicationController
79
81
  raise ForbiddenException
80
82
  end
81
83
  end
84
+
82
85
  class ProjectsController < ApplicationController
83
86
  if self.respond_to?(:skip_forgery_protection)
84
87
  skip_forgery_protection
@@ -36,6 +36,59 @@ class ErrorJsonTest < ActionDispatch::IntegrationTest
36
36
  assert_equal "Something went wrong", json_response['message']
37
37
  end
38
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
+
77
+ test 'returns an appropriate status when JSON data is malformed' do
78
+ if Rails::VERSION::STRING >= '5.1.0'
79
+ post '/unknown/path', params: 'x', headers: { "CONTENT_TYPE" => "application/json" }
80
+ else
81
+ post '/unknown/path', 'x', "CONTENT_TYPE" => "application/json"
82
+ end
83
+
84
+ if Rails::VERSION::STRING >= '5.0.0'
85
+ assert_equal 404, response.status
86
+ elsif Rails::VERSION::STRING >= '4.2.0'
87
+ assert_equal 400, response.status
88
+ end
89
+ end
90
+
91
+
39
92
  private
40
93
 
41
94
  def without_layouts
@@ -48,12 +101,12 @@ class ErrorJsonTest < ActionDispatch::IntegrationTest
48
101
  `mv error.html.erb test/fake_app/app/views/layouts/`
49
102
  end
50
103
 
51
- def get(path)
104
+ def get(path, params: {}, headers: {})
52
105
  without_layouts do
53
106
  if Rails::VERSION::STRING >= '5.1.0'
54
- super path, headers: { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }
107
+ super path, params: params, headers: { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }.merge(headers)
55
108
  else
56
- super path, nil, "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json"
109
+ super path, params, { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }.merge(headers)
57
110
  end
58
111
  end
59
112
  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: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Nishijima
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-06 00:00:00.000000000 Z
11
+ date: 2021-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -144,8 +144,8 @@ executables: []
144
144
  extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
+ - ".github/workflows/tests.yml"
147
148
  - ".gitignore"
148
- - ".travis.yml"
149
149
  - Appraisals
150
150
  - CHANGELOG.md
151
151
  - Dangerfile
@@ -155,14 +155,12 @@ files:
155
155
  - Rakefile
156
156
  - app/views/errors/internal_server_error.text.erb
157
157
  - app/views/errors/not_acceptable.text.erb
158
- - gemfiles/rails_32.gemfile
159
- - gemfiles/rails_40.gemfile
160
- - gemfiles/rails_41.gemfile
161
158
  - gemfiles/rails_42.gemfile
162
159
  - gemfiles/rails_50.gemfile
163
160
  - gemfiles/rails_51.gemfile
164
161
  - gemfiles/rails_52.gemfile
165
162
  - gemfiles/rails_60.gemfile
163
+ - gemfiles/rails_61.gemfile
166
164
  - gemfiles/rails_edge.gemfile
167
165
  - lib/generators/rambulance/exceptions_app_generator.rb
168
166
  - lib/generators/rambulance/install_generator.rb
@@ -207,7 +205,7 @@ homepage: http://github.com/yuki24/rambulance
207
205
  licenses:
208
206
  - MIT
209
207
  metadata: {}
210
- post_install_message:
208
+ post_install_message:
211
209
  rdoc_options: []
212
210
  require_paths:
213
211
  - lib
@@ -222,8 +220,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
220
  - !ruby/object:Gem::Version
223
221
  version: '0'
224
222
  requirements: []
225
- rubygems_version: 3.0.3
226
- signing_key:
223
+ rubygems_version: 3.2.26
224
+ signing_key:
227
225
  specification_version: 4
228
226
  summary: Simple and safe way to dynamically generate error pages
229
227
  test_files:
data/.travis.yml DELETED
@@ -1,51 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- sudo: false
4
-
5
- script:
6
- - bundle exec rake
7
-
8
- before_install:
9
- - gem update --system
10
- - gem install bundler
11
-
12
- rvm:
13
- - 2.3.8
14
- - 2.4.6
15
- - 2.5.5
16
- - 2.6.3
17
- - ruby-head
18
- - jruby-9.2.7.0
19
- - jruby-head
20
-
21
- gemfile:
22
- - gemfiles/rails_42.gemfile
23
- - gemfiles/rails_50.gemfile
24
- - gemfiles/rails_51.gemfile
25
- - gemfiles/rails_52.gemfile
26
- - gemfiles/rails_60.gemfile
27
- - gemfiles/rails_edge.gemfile
28
-
29
- matrix:
30
- exclude:
31
- - rvm: 2.3.8
32
- gemfile: gemfiles/rails_60.gemfile
33
- - rvm: 2.3.8
34
- gemfile: gemfiles/rails_edge.gemfile
35
- - rvm: 2.4.6
36
- gemfile: gemfiles/rails_60.gemfile
37
- - rvm: 2.4.6
38
- gemfile: gemfiles/rails_edge.gemfile
39
- - rvm: 2.6.3
40
- gemfile: gemfiles/rails_42.gemfile
41
- - rvm: ruby-head
42
- gemfile: gemfiles/rails_42.gemfile
43
- - rvm: ruby-head
44
- gemfile: gemfiles/rails_50.gemfile
45
- - rvm: ruby-head
46
- gemfile: gemfiles/rails_51.gemfile
47
- allow_failures:
48
- - rvm: ruby-head
49
- - rvm: jruby-9.2.7.0
50
- - rvm: jruby-head
51
- - gemfile: gemfiles/rails_edge.gemfile
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activesupport", "~> 3.2.0"
6
- gem "actionpack", "~> 3.2.0"
7
- gem "railties", "~> 3.2.0"
8
- gem "test-unit" if RUBY_VERSION >= "2.2.0"
9
- gem 'nokogiri', '1.6.8.1' if RUBY_VERSION == "2.0.0"
10
-
11
- gemspec path: "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activesupport", "~> 4.0.0"
6
- gem "actionpack", "~> 4.0.0"
7
- gem "railties", "~> 4.0.0"
8
- gem "test-unit" if RUBY_VERSION >= "2.2.0"
9
- gem 'nokogiri', '1.6.8.1' if RUBY_VERSION == "2.0.0"
10
-
11
- gemspec path: "../"
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activesupport", "~> 4.1.0"
6
- gem "actionpack", "~> 4.1.0"
7
- gem "railties", "~> 4.1.0"
8
- gem 'nokogiri', '1.6.8.1' if RUBY_VERSION == "2.0.0"
9
-
10
- gemspec path: "../"