rambulance 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -7
  3. data/Appraisals +9 -0
  4. data/Rakefile +12 -15
  5. data/gemfiles/rails_32.gemfile +2 -1
  6. data/gemfiles/rails_40.gemfile +1 -0
  7. data/gemfiles/rails_41.gemfile +1 -0
  8. data/gemfiles/rails_42.gemfile +1 -0
  9. data/gemfiles/rails_50.gemfile +10 -0
  10. data/lib/generators/rambulance/templates/rambulance.rb +1 -1
  11. data/lib/rambulance/exceptions_app.rb +15 -5
  12. data/lib/rambulance/railtie.rb +1 -1
  13. data/lib/rambulance/version.rb +1 -1
  14. data/rambulance.gemspec +1 -3
  15. data/test/fake_app/app/helpers/application_helper.rb +5 -0
  16. data/{spec → test}/fake_app/app/views/errors/bad_request.html.erb +0 -0
  17. data/test/fake_app/app/views/errors/forbidden.html.erb +1 -0
  18. data/{spec → test}/fake_app/app/views/errors/internal_server_error.html.erb +0 -0
  19. data/{spec → test}/fake_app/app/views/errors/internal_server_error.json.jbuilder +0 -0
  20. data/{spec → test}/fake_app/app/views/errors/not_found.html.erb +0 -0
  21. data/{spec → test}/fake_app/app/views/errors/not_found.json.jbuilder +0 -0
  22. data/{spec → test}/fake_app/app/views/layouts/application.html.erb +0 -0
  23. data/{spec → test}/fake_app/app/views/layouts/error.html.erb +0 -0
  24. data/test/fake_app/lib/exceptions_app.rb +23 -0
  25. data/{spec → test}/fake_app/rails_app.rb +17 -8
  26. data/test/requests/error_json_test.rb +57 -0
  27. data/test/requests/error_page_test.rb +87 -0
  28. data/test/test_helper.rb +21 -0
  29. metadata +35 -58
  30. data/spec/fake_app/lib/exceptions_app.rb +0 -14
  31. data/spec/requests/error_json_spec.rb +0 -52
  32. data/spec/requests/error_page_spec.rb +0 -89
  33. data/spec/spec_helper.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cbab6ea7d38072ab9ddf4b8eaaa06fd46be2ee1
4
- data.tar.gz: be1217d51c085bcc772d45deb9f64d3fdfd1415d
3
+ metadata.gz: e8652cd38fd09d82fef4cd8ef0d0c885aef91bc1
4
+ data.tar.gz: 1df7d4a06a2818bc5ac865fc4bfe64e90add5d8e
5
5
  SHA512:
6
- metadata.gz: caed478d2b08c895c525200c894d8d13ae623e1e0a9853702d719b36d845ce3eec3db92bee3bc0fdbaf4fafca40758c7f16ec3e18c525ff13af1826fbfa20846
7
- data.tar.gz: f73c89f22c997e5adf807bf515b76221a0ef938e0f394add8da2a3cb7deb0a61fbf2556a35349f19ae25940b01859cc10a3fd50fa41f5054831cf16427d463b8
6
+ metadata.gz: 551b76ece9517a8b7c4c1495363a33a16419e3a449347d28bc5037fa342a62436e60ddce380a0d675f910e32b1915a01e215671ca76eaa86c1b45be9ac9c8035
7
+ data.tar.gz: 9a8fec47fb990a7bfade1afffd719220e98dc826fc88382804d195f89a5c74687c017ab1596b311243055d9134026e1cf7a5a4dfdacbfb0e9964b72d9f0b1954
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
- script: bundle exec rake spec:all
2
+ script: bundle exec rake
3
3
  cache: bundler
4
4
  sudo: false
5
5
 
@@ -7,29 +7,37 @@ rvm:
7
7
  - 1.9.3
8
8
  - 2.0.0
9
9
  - 2.1
10
- - 2.2.2
10
+ - 2.2.5
11
+ - 2.3.1
11
12
  - ruby-head
12
13
  - jruby
13
14
  - jruby-head
14
- - rbx-2.4.1
15
- - rbx-2.5.3
16
15
 
17
16
  gemfile:
18
17
  - gemfiles/rails_32.gemfile
19
18
  - gemfiles/rails_40.gemfile
20
19
  - gemfiles/rails_41.gemfile
21
20
  - gemfiles/rails_42.gemfile
21
+ - gemfiles/rails_50.gemfile
22
22
  - gemfiles/rails_edge.gemfile
23
23
 
24
24
  matrix:
25
25
  exclude:
26
+ - rvm: 1.9.3
27
+ gemfile: gemfiles/rails_50.gemfile
26
28
  - rvm: 1.9.3
27
29
  gemfile: gemfiles/rails_edge.gemfile
30
+ - rvm: 2.0.0
31
+ gemfile: gemfiles/rails_50.gemfile
28
32
  - rvm: 2.0.0
29
33
  gemfile: gemfiles/rails_edge.gemfile
34
+ - rvm: 2.1
35
+ gemfile: gemfiles/rails_50.gemfile
30
36
  - rvm: 2.1
31
37
  gemfile: gemfiles/rails_edge.gemfile
32
- - rvm: 2.2.2
38
+ - rvm: 2.2.5
39
+ gemfile: gemfiles/rails_32.gemfile
40
+ - rvm: 2.3.1
33
41
  gemfile: gemfiles/rails_32.gemfile
34
42
  - rvm: ruby-head
35
43
  gemfile: gemfiles/rails_32.gemfile
@@ -37,8 +45,6 @@ matrix:
37
45
  - rvm: ruby-head
38
46
  - rvm: jruby
39
47
  - rvm: jruby-head
40
- - rvm: rbx-2.4.1
41
- - rvm: rbx-2.5.3
42
48
  - gemfile: gemfiles/rails_edge.gemfile
43
49
  - gemfile: gemfiles/rails_32.gem
44
50
  fast_finish: true
data/Appraisals CHANGED
@@ -2,6 +2,7 @@ appraise "rails_32" do
2
2
  gem "activesupport", "~> 3.2.0"
3
3
  gem "actionpack", "~> 3.2.0"
4
4
  gem "railties", "~> 3.2.0"
5
+ gem "test-unit" if RUBY_VERSION >= "2.2.0"
5
6
  end
6
7
 
7
8
  appraise "rails_40" do
@@ -25,6 +26,14 @@ appraise "rails_42" do
25
26
  gem 'minitest', '~> 5.3.4'
26
27
  end
27
28
 
29
+ appraise "rails_50" do
30
+ gem "activesupport", "~> 5.0.0"
31
+ gem "actionpack", "~> 5.0.0"
32
+ gem "railties", "~> 5.0.0"
33
+
34
+ gem 'minitest', '~> 5.3.4'
35
+ end
36
+
28
37
  appraise "rails_edge" do
29
38
  git 'git://github.com/rails/rails.git' do
30
39
  gem "activesupport", require: 'active_support'
data/Rakefile CHANGED
@@ -1,23 +1,20 @@
1
- # encoding: utf-8
2
1
  require "bundler/gem_tasks"
3
- require "rspec/core"
4
- require "rspec/core/rake_task"
2
+ require "rake/testtask"
5
3
 
6
- RSpec::Core::RakeTask.new(:spec)
4
+ Rake::TestTask.new('test:default') do |task|
5
+ task.libs << "test"
7
6
 
8
- task default: "spec:all"
9
-
10
- namespace :spec do
11
- desc "Run Tests with the default exceptions app"
12
- task :default do
13
- sh "bundle exec rake -t spec"
14
- end
7
+ task.test_files = Dir['test/**/*_test.rb']
8
+ task.verbose = true
9
+ task.warning = true
10
+ end
15
11
 
12
+ namespace :test do
16
13
  desc "Run Tests with a custom exceptions app"
17
14
  task :custom do
18
- sh "bundle exec rake -t spec CUSTOM_EXCEPTIONS_APP=1"
15
+ sh "rake test:default CUSTOM_EXCEPTIONS_APP=1"
19
16
  end
20
-
21
- desc "Run tests with both of the default and custom apps"
22
- task(:all).enhance(%w(default custom))
23
17
  end
18
+
19
+ task(:test).enhance %w(test:default test:custom)
20
+ task default: :test
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "activesupport", "~> 3.2.0"
6
6
  gem "actionpack", "~> 3.2.0"
7
7
  gem "railties", "~> 3.2.0"
8
- gem 'jbuilder', '2.2.13'
8
+ gem "test-unit" if RUBY_VERSION >= "2.2.0"
9
+ gem "mime-types", "2.99.3" if RUBY_VERSION < "2.0.0"
9
10
 
10
11
  gemspec :path => "../"
@@ -6,5 +6,6 @@ gem "activesupport", "~> 4.0.0"
6
6
  gem "actionpack", "~> 4.0.0"
7
7
  gem "railties", "~> 4.0.0"
8
8
  gem "test-unit" if RUBY_VERSION >= "2.2.0"
9
+ gem "mime-types", "2.99.3" if RUBY_VERSION < "2.0.0"
9
10
 
10
11
  gemspec :path => "../"
@@ -5,5 +5,6 @@ source "https://rubygems.org"
5
5
  gem "activesupport", "~> 4.1.0"
6
6
  gem "actionpack", "~> 4.1.0"
7
7
  gem "railties", "~> 4.1.0"
8
+ gem "mime-types", "2.99.3" if RUBY_VERSION < "2.0.0"
8
9
 
9
10
  gemspec :path => "../"
@@ -6,5 +6,6 @@ gem "activesupport", "~> 4.2.0"
6
6
  gem "actionpack", "~> 4.2.0"
7
7
  gem "railties", "~> 4.2.0"
8
8
  gem "minitest", "~> 5.3.4"
9
+ gem "mime-types", "2.99.3" if RUBY_VERSION < "2.0.0"
9
10
 
10
11
  gemspec :path => "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 5.0.0"
6
+ gem "actionpack", "~> 5.0.0"
7
+ gem "railties", "~> 5.0.0"
8
+ gem "minitest", "~> 5.3.4"
9
+
10
+ gemspec :path => "../"
@@ -10,7 +10,7 @@ Rambulance.setup do |config|
10
10
  %>
11
11
  #
12
12
  # If you add exceptions in this config, Rambulance uses the pairs you defined
13
- # here *in addition* to the default maddings. You can also override the default
13
+ # here *in addition* to the default mappings. You can also override the default
14
14
  # mappings although you don't have to in most cases.
15
15
  # If Rambulance receives an exception that is not listed here, it'll render
16
16
  # the internal server error template and return 500 as http status.
@@ -21,8 +21,8 @@ module Rambulance
21
21
  status_in_words = if exception
22
22
  ActionDispatch::ExceptionWrapper.rescue_responses[exception.class.to_s]
23
23
  else
24
- env["PATH_INFO"][1..-1].to_sym.tap do |status_in_words|
25
- env["PATH_INFO"] = "/#{Rack::Utils::SYMBOL_TO_STATUS_CODE[status_in_words]}"
24
+ env["PATH_INFO"][1..-1].to_sym.tap do |_status_in_words|
25
+ env["PATH_INFO"] = "/#{Rack::Utils::SYMBOL_TO_STATUS_CODE[_status_in_words]}"
26
26
  end
27
27
  end
28
28
 
@@ -41,20 +41,30 @@ module Rambulance
41
41
  ACTION
42
42
  end
43
43
 
44
+ def process(action, *args)
45
+ 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
49
+ end
50
+
51
+ super
52
+ end
53
+
44
54
  private
45
55
 
46
56
  def process_action(*)
47
57
  begin
48
58
  request.GET
49
59
  rescue BAD_REQUEST_EXCEPTION
50
- env["MALFORMED_QUERY_STRING"], env["QUERY_STRING"] = env["QUERY_STRING"], ""
60
+ request.env["MALFORMED_QUERY_STRING"], request.env["QUERY_STRING"] = request.env["QUERY_STRING"], ""
51
61
  end
52
62
 
53
63
  super
54
64
  end
55
65
 
56
66
  def send_action(name, *args)
57
- @_status = env["PATH_INFO"][1..-1].to_i
67
+ @_status = request.env["PATH_INFO"][1..-1].to_i
58
68
  @_response.status = @_status
59
69
  @_body = { :status => @_status, :error => Rack::Utils::HTTP_STATUS_CODES.fetch(@_status.to_i, Rack::Utils::HTTP_STATUS_CODES[500]) }
60
70
 
@@ -66,7 +76,7 @@ module Rambulance
66
76
  end
67
77
 
68
78
  def exception
69
- env["action_dispatch.exception"]
79
+ request.env["action_dispatch.exception"]
70
80
  end
71
81
 
72
82
  def error_path(status_in_words = status_in_words())
@@ -1,6 +1,6 @@
1
1
  module Rambulance
2
2
  class Railtie < Rails::Railtie
3
- initializer 'rambulance' do |app|
3
+ initializer 'rambulance', after: :prepend_helpers_path do |app|
4
4
  require "rambulance/exceptions_app"
5
5
 
6
6
  app.config.exceptions_app =
@@ -1,3 +1,3 @@
1
1
  module Rambulance
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/rambulance.gemspec CHANGED
@@ -22,12 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "actionpack"
23
23
  spec.add_dependency "railties"
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "bundler"
26
26
  spec.add_development_dependency "rake"
27
27
  spec.add_development_dependency "tzinfo"
28
28
  spec.add_development_dependency "jbuilder"
29
- spec.add_development_dependency "rspec"
30
- spec.add_development_dependency "rspec-rails"
31
29
  spec.add_development_dependency "capybara"
32
30
  spec.add_development_dependency "appraisal"
33
31
  end
@@ -0,0 +1,5 @@
1
+ module ApplicationHelper
2
+ def forbidden
3
+ 'Forbidden.'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ <%= forbidden %>
@@ -0,0 +1,23 @@
1
+ class ExceptionsApp < Rambulance::ExceptionsApp
2
+ def not_found; end
3
+
4
+ def internal_server_error
5
+ render_custom_error_page
6
+ end
7
+
8
+ def not_acceptable
9
+ render_custom_error_page
10
+ end
11
+
12
+ private
13
+ def render_custom_error_page
14
+ render inline: <<-BODY
15
+ <html>
16
+ <body>
17
+ <h1>Custom error page</h1>
18
+ <p>Something went wrong!</p>
19
+ </body>
20
+ </html>
21
+ BODY
22
+ end
23
+ end
@@ -1,5 +1,3 @@
1
- require 'action_controller/railtie'
2
- require 'action_view/railtie'
3
1
  require 'jbuilder'
4
2
 
5
3
  # config
@@ -22,19 +20,25 @@ end
22
20
 
23
21
  # custom exception class
24
22
  class CustomException < StandardError; end
23
+ class ForbiddenException < StandardError; end
25
24
 
26
25
  Rambulance.setup do |config|
27
26
  config.layout_name = "error"
28
27
  config.rescue_responses = {
29
28
  'TypeError' => :bad_request,
30
- 'CustomException' => :not_found
29
+ 'CustomException' => :not_found,
30
+ 'ForbiddenException' => :forbidden
31
31
  }
32
32
  end
33
33
 
34
34
  # controllers
35
35
  class ApplicationController < ActionController::Base
36
36
  append_view_path "spec/fake_app/views"
37
- before_filter :bad_filter
37
+ if self.respond_to? :before_filter
38
+ before_filter :bad_filter
39
+ else
40
+ before_action :bad_filter
41
+ end
38
42
 
39
43
  private
40
44
 
@@ -43,7 +47,11 @@ class ApplicationController < ActionController::Base
43
47
  end
44
48
  end
45
49
  class UsersController < ApplicationController
46
- skip_filter :bad_filter, except: :show
50
+ if self.respond_to? :skip_before_action
51
+ skip_before_action :bad_filter, except: :show
52
+ else
53
+ skip_filter :bad_filter, except: :show
54
+ end
47
55
 
48
56
  def index
49
57
  raise CustomException
@@ -56,7 +64,8 @@ class UsersController < ApplicationController
56
64
  end
57
65
 
58
66
  def create; end
59
- end
60
67
 
61
- # helpers
62
- Object.const_set(:ApplicationHelper, Module.new)
68
+ def edit
69
+ raise ForbiddenException
70
+ end
71
+ end
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+
3
+ class ErrorJsonTest < ActionDispatch::IntegrationTest
4
+ test 'returns the 422 json for ActionController:InvalidAuthenticityToken but without its template' do
5
+ get '/users/new'
6
+
7
+ assert_equal 422, response.status
8
+ assert_equal "Something went wrong", json_response['message']
9
+ end
10
+
11
+ test 'returns the 500 json for RuntimeError' do
12
+ get '/users/1.json'
13
+
14
+ assert_equal 500, response.status
15
+ assert_equal "Something went wrong", json_response['message']
16
+ end
17
+
18
+ test 'returns the 404 json for CustomException' do
19
+ get '/users.json'
20
+
21
+ assert_equal 404, response.status
22
+ assert_equal "Page not found", json_response['message']
23
+ end
24
+
25
+ test 'returns the 404 json for ActinoController::RoutingError' do
26
+ get '/doesnt_exist.json'
27
+
28
+ assert_equal 404, response.status
29
+ assert_equal "Page not found", json_response['message']
30
+ end
31
+
32
+ private
33
+
34
+ def without_layouts
35
+ `mv test/fake_app/app/views/layouts/application.html.erb .`
36
+ `mv test/fake_app/app/views/layouts/error.html.erb .`
37
+
38
+ yield
39
+ ensure
40
+ `mv application.html.erb test/fake_app/app/views/layouts/`
41
+ `mv error.html.erb test/fake_app/app/views/layouts/`
42
+ end
43
+
44
+ def get(path)
45
+ without_layouts do
46
+ if Rails::VERSION::STRING >= '5.1.0'
47
+ super path, headers: { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }
48
+ else
49
+ super path, nil, "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json"
50
+ end
51
+ end
52
+ end
53
+
54
+ def json_response
55
+ JSON.parse(response.body)
56
+ end
57
+ end if !ENV["CUSTOM_EXCEPTIONS_APP"]
@@ -0,0 +1,87 @@
1
+ require 'test_helper'
2
+
3
+ class ErrorPageTest < ActionDispatch::IntegrationTest
4
+ test 'displays the 500 page for RuntimeError' do
5
+ visit '/users/1'
6
+
7
+ assert_equal 500, page.status_code
8
+ assert_includes page.body, "Error page"
9
+ assert_includes page.body, "Something went wrong."
10
+ end
11
+
12
+ test 'displays the 404 page for CustomException' do
13
+ visit '/users'
14
+
15
+ assert_equal 404, page.status_code
16
+ assert_includes page.body, "Error page"
17
+ assert_includes page.body, "Page not found."
18
+ end
19
+
20
+ test 'displays the 404 page for ActionController::RoutingError' do
21
+ visit '/doesnt_exist'
22
+
23
+ assert_equal 404, page.status_code
24
+ assert_includes page.body, "Error page"
25
+ assert_includes page.body, "Page not found."
26
+ end
27
+
28
+ test 'displays the 400 page when malformed parameters' do
29
+ page.driver.post '/users?x[y]=1&x[y][][w]=2'
30
+
31
+ assert_equal 400, page.status_code
32
+ assert_includes page.body, "Error page"
33
+ assert_includes page.body, "Bad request."
34
+ end
35
+
36
+ test 'displays the 404 page for request to non-existing page with malformed parameters' do
37
+ page.driver.post '/doesnt_exist?x[y]=1&x[y][][w]=2'
38
+
39
+ assert_equal 404, page.status_code
40
+ assert_includes page.body, "Error page"
41
+ assert_includes page.body, "Page not found."
42
+ end
43
+
44
+ test 'displays the 403 page for ForbiddenException' do
45
+ visit '/users/1/edit'
46
+
47
+ assert_equal 403, page.status_code
48
+ assert_includes page.body, "Error page"
49
+ assert_includes page.body, "Forbidden."
50
+ end
51
+
52
+ test 'uses the custom layou twith a custom layout name' do
53
+ @org, Rambulance.layout_name = Rambulance.layout_name, "application"
54
+
55
+ begin
56
+ visit '/doesnt_exist'
57
+ assert_includes page.body, "Application page"
58
+ ensure
59
+ Rambulance.layout_name = @org
60
+ end
61
+ end
62
+
63
+ test 'uses the 500 page and returns 422 when the template is missing' do
64
+ visit '/users/new'
65
+
66
+ assert_equal 422, page.status_code
67
+ assert_includes page.body, "Error page"
68
+ assert_includes page.body, "Something went wrong."
69
+ end
70
+ end if !ENV["CUSTOM_EXCEPTIONS_APP"]
71
+
72
+ class ErrorPageWithCustomExceptionsAppTest < ActionDispatch::IntegrationTest
73
+ test 'displays 500 page for RuntimeError' do
74
+ visit '/users/1'
75
+
76
+ assert_equal 500, page.status_code
77
+ assert_includes page.body, "Custom error page"
78
+ end
79
+
80
+ test 'displays 404 page for ActinoController::RoutingError' do
81
+ visit '/doesnt_exist'
82
+
83
+ assert_equal 404, page.status_code
84
+ assert_includes page.body, "Error page"
85
+ assert_includes page.body, "Page not found."
86
+ end
87
+ end if ENV["CUSTOM_EXCEPTIONS_APP"]
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rails'
5
+ require 'minitest/autorun'
6
+ require 'action_controller/railtie'
7
+ require 'action_view/railtie'
8
+ require 'bundler/setup'
9
+ Bundler.require
10
+
11
+ require 'fake_app/rails_app'
12
+ require 'capybara/rails'
13
+
14
+ class ActionDispatch::IntegrationTest
15
+ include Capybara::DSL
16
+
17
+ def teardown
18
+ Capybara.reset_sessions!
19
+ Capybara.use_default_driver
20
+ end
21
+ 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.3.1
4
+ version: 0.4.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: 2015-05-18 00:00:00.000000000 Z
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -54,34 +54,6 @@ dependencies:
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.6'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.6'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: tzinfo
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
59
  - - ">="
@@ -95,7 +67,7 @@ dependencies:
95
67
  - !ruby/object:Gem::Version
96
68
  version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
- name: jbuilder
70
+ name: rake
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
73
  - - ">="
@@ -109,7 +81,7 @@ dependencies:
109
81
  - !ruby/object:Gem::Version
110
82
  version: '0'
111
83
  - !ruby/object:Gem::Dependency
112
- name: rspec
84
+ name: tzinfo
113
85
  requirement: !ruby/object:Gem::Requirement
114
86
  requirements:
115
87
  - - ">="
@@ -123,7 +95,7 @@ dependencies:
123
95
  - !ruby/object:Gem::Version
124
96
  version: '0'
125
97
  - !ruby/object:Gem::Dependency
126
- name: rspec-rails
98
+ name: jbuilder
127
99
  requirement: !ruby/object:Gem::Requirement
128
100
  requirements:
129
101
  - - ">="
@@ -184,6 +156,7 @@ files:
184
156
  - gemfiles/rails_40.gemfile
185
157
  - gemfiles/rails_41.gemfile
186
158
  - gemfiles/rails_42.gemfile
159
+ - gemfiles/rails_50.gemfile
187
160
  - gemfiles/rails_edge.gemfile
188
161
  - lib/generators/rambulance/exceptions_app_generator.rb
189
162
  - lib/generators/rambulance/install_generator.rb
@@ -214,18 +187,20 @@ files:
214
187
  - lib/rambulance/railtie.rb
215
188
  - lib/rambulance/version.rb
216
189
  - rambulance.gemspec
217
- - spec/fake_app/app/views/errors/bad_request.html.erb
218
- - spec/fake_app/app/views/errors/internal_server_error.html.erb
219
- - spec/fake_app/app/views/errors/internal_server_error.json.jbuilder
220
- - spec/fake_app/app/views/errors/not_found.html.erb
221
- - spec/fake_app/app/views/errors/not_found.json.jbuilder
222
- - spec/fake_app/app/views/layouts/application.html.erb
223
- - spec/fake_app/app/views/layouts/error.html.erb
224
- - spec/fake_app/lib/exceptions_app.rb
225
- - spec/fake_app/rails_app.rb
226
- - spec/requests/error_json_spec.rb
227
- - spec/requests/error_page_spec.rb
228
- - spec/spec_helper.rb
190
+ - test/fake_app/app/helpers/application_helper.rb
191
+ - test/fake_app/app/views/errors/bad_request.html.erb
192
+ - test/fake_app/app/views/errors/forbidden.html.erb
193
+ - test/fake_app/app/views/errors/internal_server_error.html.erb
194
+ - test/fake_app/app/views/errors/internal_server_error.json.jbuilder
195
+ - test/fake_app/app/views/errors/not_found.html.erb
196
+ - test/fake_app/app/views/errors/not_found.json.jbuilder
197
+ - test/fake_app/app/views/layouts/application.html.erb
198
+ - test/fake_app/app/views/layouts/error.html.erb
199
+ - test/fake_app/lib/exceptions_app.rb
200
+ - test/fake_app/rails_app.rb
201
+ - test/requests/error_json_test.rb
202
+ - test/requests/error_page_test.rb
203
+ - test/test_helper.rb
229
204
  homepage: http://github.com/yuki24/rambulance
230
205
  licenses:
231
206
  - MIT
@@ -246,20 +221,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
221
  version: '0'
247
222
  requirements: []
248
223
  rubyforge_project:
249
- rubygems_version: 2.4.7
224
+ rubygems_version: 2.5.1
250
225
  signing_key:
251
226
  specification_version: 4
252
227
  summary: Simple and safe way to dynamically generate error pages
253
228
  test_files:
254
- - spec/fake_app/app/views/errors/bad_request.html.erb
255
- - spec/fake_app/app/views/errors/internal_server_error.html.erb
256
- - spec/fake_app/app/views/errors/internal_server_error.json.jbuilder
257
- - spec/fake_app/app/views/errors/not_found.html.erb
258
- - spec/fake_app/app/views/errors/not_found.json.jbuilder
259
- - spec/fake_app/app/views/layouts/application.html.erb
260
- - spec/fake_app/app/views/layouts/error.html.erb
261
- - spec/fake_app/lib/exceptions_app.rb
262
- - spec/fake_app/rails_app.rb
263
- - spec/requests/error_json_spec.rb
264
- - spec/requests/error_page_spec.rb
265
- - spec/spec_helper.rb
229
+ - test/fake_app/app/helpers/application_helper.rb
230
+ - test/fake_app/app/views/errors/bad_request.html.erb
231
+ - test/fake_app/app/views/errors/forbidden.html.erb
232
+ - test/fake_app/app/views/errors/internal_server_error.html.erb
233
+ - test/fake_app/app/views/errors/internal_server_error.json.jbuilder
234
+ - test/fake_app/app/views/errors/not_found.html.erb
235
+ - test/fake_app/app/views/errors/not_found.json.jbuilder
236
+ - test/fake_app/app/views/layouts/application.html.erb
237
+ - test/fake_app/app/views/layouts/error.html.erb
238
+ - test/fake_app/lib/exceptions_app.rb
239
+ - test/fake_app/rails_app.rb
240
+ - test/requests/error_json_test.rb
241
+ - test/requests/error_page_test.rb
242
+ - test/test_helper.rb
@@ -1,14 +0,0 @@
1
- class ExceptionsApp < Rambulance::ExceptionsApp
2
- def not_found; end
3
-
4
- def internal_server_error
5
- render inline: <<-BODY
6
- <html>
7
- <body>
8
- <h1>Custom error page</h1>
9
- <p>Something went wrong!</p>
10
- </body>
11
- </html>
12
- BODY
13
- end
14
- end
@@ -1,52 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
-
4
- feature 'Error json response', if: !ENV["CUSTOM_EXCEPTIONS_APP"], type: :request do
5
- def json_response
6
- JSON.parse(response.body)
7
- end
8
-
9
- def get(path)
10
- without_layouts do
11
- super(path, nil, "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json")
12
- end
13
- end
14
-
15
- def without_layouts
16
- `mv spec/fake_app/app/views/layouts/application.html.erb .`
17
- `mv spec/fake_app/app/views/layouts/error.html.erb .`
18
-
19
- yield
20
- ensure
21
- `mv application.html.erb spec/fake_app/app/views/layouts/`
22
- `mv error.html.erb spec/fake_app/app/views/layouts/`
23
- end
24
-
25
- scenario 'returns 422 json due to ActionController:InvalidAuthenticityToken but without its template' do
26
- get '/users/new'
27
-
28
- expect(response.status).to eq(422)
29
- expect(json_response['message']).to eq("Something went wrong")
30
- end
31
-
32
- scenario 'returns 500 json due to RuntimeError' do
33
- get '/users/1.json'
34
-
35
- expect(response.status).to eq(500)
36
- expect(json_response['message']).to eq("Something went wrong")
37
- end
38
-
39
- scenario 'returns 404 json due to CustomException' do
40
- get '/users.json'
41
-
42
- expect(response.status).to eq(404)
43
- expect(json_response['message']).to eq("Page not found")
44
- end
45
-
46
- scenario 'returns 404 json due to ActinoController::RoutingError' do
47
- get '/doesnt_exist.json'
48
-
49
- expect(response.status).to eq(404)
50
- expect(json_response['message']).to eq("Page not found")
51
- end
52
- end
@@ -1,89 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
-
4
- feature 'Error page' do
5
- shared_examples_for "an action that renders 500 page if the template is missing" do
6
- scenario 'displays 500 page and return 422 Bad Request status' do
7
- visit '/users/new'
8
-
9
- expect(page.status_code).to eq(422)
10
- expect(page.body).to have_content "Error page"
11
- expect(page.body).to have_content "Something went wrong."
12
- end
13
- end
14
-
15
- context 'generated by the default exceptions app', if: !ENV["CUSTOM_EXCEPTIONS_APP"] do
16
- it_behaves_like "an action that renders 500 page if the template is missing"
17
-
18
- scenario 'displays 500 page due to RuntimeError' do
19
- visit '/users/1'
20
-
21
- expect(page.status_code).to eq(500)
22
- expect(page.body).to have_content "Error page"
23
- expect(page.body).to have_content "Something went wrong."
24
- end
25
-
26
- scenario 'displays 404 page due to CustomException' do
27
- visit '/users'
28
-
29
- expect(page.status_code).to eq(404)
30
- expect(page.body).to have_content "Error page"
31
- expect(page.body).to have_content "Page not found."
32
- end
33
-
34
- scenario 'displays 404 page due to ActionController::RoutingError' do
35
- visit '/doesnt_exist'
36
-
37
- expect(page.status_code).to eq(404)
38
- expect(page.body).to have_content "Error page"
39
- expect(page.body).to have_content "Page not found."
40
- end
41
-
42
- scenario 'displays 400 page when malformed parameters' do
43
- page.driver.post '/users?x[y]=1&x[y][][w]=2'
44
-
45
- expect(page.status_code).to eq(400)
46
- expect(page.body).to have_content "Error page"
47
- expect(page.body).to have_content "Bad request."
48
- end
49
-
50
- scenario 'displays 404 page for non-existing page when malformed parameters' do
51
- page.driver.post '/doesnt_exist?x[y]=1&x[y][][w]=2'
52
-
53
- expect(page.status_code).to eq(404)
54
- expect(page.body).to have_content "Error page"
55
- expect(page.body).to have_content "Page not found."
56
- end
57
-
58
- context "with a custom layout name" do
59
- before do
60
- @org, Rambulance.layout_name = Rambulance.layout_name, "application"
61
- end
62
- after { Rambulance.layout_name = @org }
63
-
64
- scenario 'uses the custom layout' do
65
- visit '/doesnt_exist'
66
- expect(page.body).to have_content "Application page"
67
- end
68
- end
69
- end
70
-
71
- context "generated by a custom exception app", if: ENV["CUSTOM_EXCEPTIONS_APP"] do
72
- it_behaves_like "an action that renders 500 page if the template is missing"
73
-
74
- scenario 'displays 404 page due to ActinoController::RoutingError' do
75
- visit '/doesnt_exist'
76
-
77
- expect(page.status_code).to eq(404)
78
- expect(page.body).to have_content "Error page"
79
- expect(page.body).to have_content "Page not found."
80
- end
81
-
82
- scenario 'displays 500 page due to RuntimeError' do
83
- visit '/users/1'
84
-
85
- expect(page.status_code).to eq(500)
86
- expect(page.body).to have_content "Custom error page"
87
- end
88
- end
89
- end
data/spec/spec_helper.rb DELETED
@@ -1,19 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
-
4
- require 'rails'
5
-
6
- require 'bundler/setup'
7
- Bundler.require
8
-
9
- require 'capybara/rspec'
10
- require 'fake_app/rails_app'
11
- require 'rspec/rails'
12
-
13
- # Requires supporting files with custom matchers and macros, etc,
14
- # in ./support/ and its subdirectories.
15
- # Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f }
16
-
17
- # RSpec.configure do |config|
18
- #
19
- # end