rambulance 0.1.2 → 0.2.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 +4 -4
 - data/.travis.yml +1 -0
 - data/Appraisals +8 -1
 - data/README.md +3 -3
 - data/Rakefile +1 -3
 - data/gemfiles/rails_42.gemfile +10 -0
 - data/gemfiles/rails_edge.gemfile +0 -1
 - data/lib/generators/rambulance/install_generator.rb +23 -5
 - data/lib/generators/rambulance/templates/rambulance.rb +7 -16
 - data/lib/rambulance.rb +1 -1
 - data/lib/rambulance/exceptions_app.rb +20 -0
 - data/lib/rambulance/version.rb +1 -1
 - data/rambulance.gemspec +1 -1
 - data/spec/fake_app/app/views/errors/bad_request.html.erb +1 -0
 - data/spec/fake_app/rails_app.rb +4 -0
 - data/spec/requests/error_json_spec.rb +13 -13
 - data/spec/requests/error_page_spec.rb +43 -27
 - metadata +9 -6
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 6b34e6b878ba63db8822a5fc882cfe096e0fa24d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: be1dafb554fdad7ac32ad9c350ebde70dae19b95
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2654f7f3939613f5d17ff0a68b7fc02debc9c23e38b63bd5ce2ebaa6a92fea0184e41a31ec4f82a37a16fce12a4d7d094cb4e8177f0d3bbbf83996582fec3c2c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: f930880f7303f539dc2d740efeac7d5f28929c1b3be4928678b1c4988489f7aa76245eec7faf4bc38d8c4898aa501db404ef4449f726850bc9f61702e1b9cecd
         
     | 
    
        data/.travis.yml
    CHANGED
    
    
    
        data/Appraisals
    CHANGED
    
    | 
         @@ -16,6 +16,14 @@ appraise "rails_41" do 
     | 
|
| 
       16 
16 
     | 
    
         
             
              gem "railties", "~> 4.1.0"
         
     | 
| 
       17 
17 
     | 
    
         
             
            end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
      
 19 
     | 
    
         
            +
            appraise "rails_42" do
         
     | 
| 
      
 20 
     | 
    
         
            +
              gem "activesupport", "~> 4.2.0.beta1"
         
     | 
| 
      
 21 
     | 
    
         
            +
              gem "actionpack", "~> 4.2.0.beta1"
         
     | 
| 
      
 22 
     | 
    
         
            +
              gem "railties", "~> 4.2.0.beta1"
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              gem 'minitest', '~> 5.3.4'
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
       19 
27 
     | 
    
         
             
            appraise "rails_edge" do
         
     | 
| 
       20 
28 
     | 
    
         
             
              git 'git://github.com/rails/rails.git' do
         
     | 
| 
       21 
29 
     | 
    
         
             
                gem "activesupport", require: 'active_support'
         
     | 
| 
         @@ -24,5 +32,4 @@ appraise "rails_edge" do 
     | 
|
| 
       24 
32 
     | 
    
         
             
              end
         
     | 
| 
       25 
33 
     | 
    
         | 
| 
       26 
34 
     | 
    
         
             
              gem 'minitest', '~> 5.3.4'
         
     | 
| 
       27 
     | 
    
         
            -
              gem 'rspec-rails', '2.99.0.beta1'
         
     | 
| 
       28 
35 
     | 
    
         
             
            end
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -30,7 +30,7 @@ And then execute: 
     | 
|
| 
       30 
30 
     | 
    
         
             
            $ rails g rambulance:install
         
     | 
| 
       31 
31 
     | 
    
         
             
            ```
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
            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/ 
     | 
| 
      
 33 
     | 
    
         
            +
            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)!
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
            ## Setting Pairs of Exceptions and HTTP Statuses
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
         @@ -67,8 +67,8 @@ This page tells all the error pages as well as all the pairs of exceptions/corre 
     | 
|
| 
       67 
67 
     | 
    
         
             
            ### Open `localhost:3000/rambulance/***` in Your Browser
         
     | 
| 
       68 
68 
     | 
    
         | 
| 
       69 
69 
     | 
    
         
             
            Just go to one of the error pages via Rambulance:
         
     | 
| 
       70 
     | 
    
         
            -
             * [`localhost:3000/rambulance/not_found`](http://localhost:3000/rambulance/ 
     | 
| 
       71 
     | 
    
         
            -
             * [`localhost:3000/rambulance/internal_server_error`](http://localhost:3000/rambulance/ 
     | 
| 
      
 70 
     | 
    
         
            +
             * [`localhost:3000/rambulance/not_found`](http://localhost:3000/rambulance/not_found) or
         
     | 
| 
      
 71 
     | 
    
         
            +
             * [`localhost:3000/rambulance/internal_server_error`](http://localhost:3000/rambulance/internal_server_error)
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
            This is useful when you want to edit templates without changing Rails configuration.
         
     | 
| 
       74 
74 
     | 
    
         | 
    
        data/Rakefile
    CHANGED
    
    
    
        data/gemfiles/rails_edge.gemfile
    CHANGED
    
    
| 
         @@ -3,7 +3,15 @@ module Rambulance 
     | 
|
| 
       3 
3 
     | 
    
         
             
                class InstallGenerator < Rails::Generators::Base
         
     | 
| 
       4 
4 
     | 
    
         
             
                  source_root File.expand_path('../templates', __FILE__)
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
                  class_option :template_engine, 
     | 
| 
      
 6 
     | 
    
         
            +
                  class_option :template_engine,
         
     | 
| 
      
 7 
     | 
    
         
            +
                    type: :string,
         
     | 
| 
      
 8 
     | 
    
         
            +
                    aliases: '-e',
         
     | 
| 
      
 9 
     | 
    
         
            +
                    desc: 'Template engine for the views. Available options are "erb" and "haml".'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  class_option :error_layout,
         
     | 
| 
      
 12 
     | 
    
         
            +
                    type: :string,
         
     | 
| 
      
 13 
     | 
    
         
            +
                    aliases: '-l',
         
     | 
| 
      
 14 
     | 
    
         
            +
                    desc: 'Copies app/views/layout/application.html.erb to the specified layout name'
         
     | 
| 
       7 
15 
     | 
    
         | 
| 
       8 
16 
     | 
    
         
             
                  def self.banner #:nodoc:
         
     | 
| 
       9 
17 
     | 
    
         
             
                    <<-BANNER.chomp
         
     | 
| 
         @@ -28,13 +36,15 @@ BANNER 
     | 
|
| 
       28 
36 
     | 
    
         
             
                  end
         
     | 
| 
       29 
37 
     | 
    
         | 
| 
       30 
38 
     | 
    
         
             
                  def copy_layout #:nodoc:
         
     | 
| 
       31 
     | 
    
         
            -
                     
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
                    return if layout_name == "application"
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                    say "\n" "copying app/views/layouts/application.html.#{template_engine} to app/views/layouts/#{layout_name}.html.#{template_engine}:"
         
     | 
| 
      
 42 
     | 
    
         
            +
                    copy_file Rails.root.join("app/views/layouts/application.html.#{template_engine}"), "app/views/layouts/#{layout_name}.html.#{template_engine}"
         
     | 
| 
       33 
43 
     | 
    
         
             
                  end
         
     | 
| 
       34 
44 
     | 
    
         | 
| 
       35 
45 
     | 
    
         
             
                  def copy_initializer #:nodoc:
         
     | 
| 
       36 
     | 
    
         
            -
                    say "\ 
     | 
| 
       37 
     | 
    
         
            -
                     
     | 
| 
      
 46 
     | 
    
         
            +
                    say "\n" "generating initializer:"
         
     | 
| 
      
 47 
     | 
    
         
            +
                    template "rambulance.rb", "config/initializers/rambulance.rb"
         
     | 
| 
       38 
48 
     | 
    
         
             
                  end
         
     | 
| 
       39 
49 
     | 
    
         | 
| 
       40 
50 
     | 
    
         
             
                  private
         
     | 
| 
         @@ -42,6 +52,14 @@ BANNER 
     | 
|
| 
       42 
52 
     | 
    
         
             
                  def template_engine
         
     | 
| 
       43 
53 
     | 
    
         
             
                    options[:template_engine].try(:to_s).try(:downcase) || 'erb'
         
     | 
| 
       44 
54 
     | 
    
         
             
                  end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                  def layout_name
         
     | 
| 
      
 57 
     | 
    
         
            +
                    options[:error_layout].try(:to_s).try(:downcase) || "application"
         
     | 
| 
      
 58 
     | 
    
         
            +
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  def longest_error_name_size
         
     | 
| 
      
 61 
     | 
    
         
            +
                    ActionDispatch::ExceptionWrapper.rescue_responses.keys.sort_by(&:size).last.size
         
     | 
| 
      
 62 
     | 
    
         
            +
                  end
         
     | 
| 
       45 
63 
     | 
    
         
             
                end
         
     | 
| 
       46 
64 
     | 
    
         
             
              end
         
     | 
| 
       47 
65 
     | 
    
         
             
            end
         
     | 
| 
         @@ -3,20 +3,11 @@ Rambulance.setup do |config| 
     | 
|
| 
       3 
3 
     | 
    
         
             
              # List of pairs of exception/corresponding http status. In Rails, the default
         
     | 
| 
       4 
4 
     | 
    
         
             
              # mappings are below:
         
     | 
| 
       5 
5 
     | 
    
         
             
              #
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
               
     | 
| 
       8 
     | 
    
         
            -
              #    
     | 
| 
       9 
     | 
    
         
            -
               
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
              #   "ActionController::UnknownFormat"            => :not_acceptable,
         
     | 
| 
       12 
     | 
    
         
            -
              #   "ActionController::InvalidAuthenticityToken" => :unprocessable_entity,
         
     | 
| 
       13 
     | 
    
         
            -
              #   "ActionDispatch::ParamsParser::ParseError"   => :bad_request,
         
     | 
| 
       14 
     | 
    
         
            -
              #   "ActionController::BadRequest"               => :bad_request,
         
     | 
| 
       15 
     | 
    
         
            -
              #   "ActionController::ParameterMissing"         => :bad_request,
         
     | 
| 
       16 
     | 
    
         
            -
              #   "ActiveRecord::RecordNotFound"               => :not_found,
         
     | 
| 
       17 
     | 
    
         
            -
              #   "ActiveRecord::StaleObjectError"             => :conflict,
         
     | 
| 
       18 
     | 
    
         
            -
              #   "ActiveRecord::RecordInvalid"                => :unprocessable_entity,
         
     | 
| 
       19 
     | 
    
         
            -
              #   "ActiveRecord::RecordNotSaved"               => :unprocessable_entity
         
     | 
| 
      
 6 
     | 
    
         
            +
            <%=
         
     | 
| 
      
 7 
     | 
    
         
            +
              ActionDispatch::ExceptionWrapper.rescue_responses.map do |error_class, status|
         
     | 
| 
      
 8 
     | 
    
         
            +
                "  #   #{error_class.ljust(longest_error_name_size)} => :#{status}"
         
     | 
| 
      
 9 
     | 
    
         
            +
              end.join(",\n")
         
     | 
| 
      
 10 
     | 
    
         
            +
            %>
         
     | 
| 
       20 
11 
     | 
    
         
             
              #
         
     | 
| 
       21 
12 
     | 
    
         
             
              # If you add exceptions in this config, Rambulance uses the pairs you defined
         
     | 
| 
       22 
13 
     | 
    
         
             
              # here *in addition* to the default maddings. You can also override the default
         
     | 
| 
         @@ -31,9 +22,9 @@ Rambulance.setup do |config| 
     | 
|
| 
       31 
22 
     | 
    
         
             
              }
         
     | 
| 
       32 
23 
     | 
    
         | 
| 
       33 
24 
     | 
    
         
             
              # The template name for the layout of the error pages. The default value is
         
     | 
| 
       34 
     | 
    
         
            -
              # ' 
     | 
| 
      
 25 
     | 
    
         
            +
              # 'application'. For exmaple, if this value is set to "error_page", Rambulance uses
         
     | 
| 
       35 
26 
     | 
    
         
             
              # 'app/views/layout/error_page.html.erb' as a layout for all the error pages.
         
     | 
| 
       36 
     | 
    
         
            -
              config.layout_name = " 
     | 
| 
      
 27 
     | 
    
         
            +
              config.layout_name = "<%= layout_name %>"
         
     | 
| 
       37 
28 
     | 
    
         | 
| 
       38 
29 
     | 
    
         
             
              # The directry name to organize error page templates. The default value is
         
     | 
| 
       39 
30 
     | 
    
         
             
              # 'errors'. For exmaple, if this value is set to "error_pages", Rambulance
         
     | 
    
        data/lib/rambulance.rb
    CHANGED
    
    
| 
         @@ -23,6 +23,10 @@ module Rambulance 
     | 
|
| 
       23 
23 
     | 
    
         
             
                  action(status_in_words).call(env)
         
     | 
| 
       24 
24 
     | 
    
         
             
                end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
      
 26 
     | 
    
         
            +
                def self.local_prefixes
         
     | 
| 
      
 27 
     | 
    
         
            +
                  [Rambulance.view_path]
         
     | 
| 
      
 28 
     | 
    
         
            +
                end if ActionPack::VERSION::STRING >= "4.2.0"
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
       26 
30 
     | 
    
         
             
                ERROR_HTTP_STATUSES.values.each do |status_in_words|
         
     | 
| 
       27 
31 
     | 
    
         
             
                  eval <<-ACTION
         
     | 
| 
       28 
32 
     | 
    
         
             
                    def #{status_in_words}
         
     | 
| 
         @@ -33,6 +37,16 @@ module Rambulance 
     | 
|
| 
       33 
37 
     | 
    
         | 
| 
       34 
38 
     | 
    
         
             
                private
         
     | 
| 
       35 
39 
     | 
    
         | 
| 
      
 40 
     | 
    
         
            +
                def process_action(*)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 42 
     | 
    
         
            +
                    request.GET
         
     | 
| 
      
 43 
     | 
    
         
            +
                  rescue bad_request_exception
         
     | 
| 
      
 44 
     | 
    
         
            +
                    env["MALFORMED_QUERY_STRING"], env["QUERY_STRING"] = env["QUERY_STRING"], ""
         
     | 
| 
      
 45 
     | 
    
         
            +
                  end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                  super
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
       36 
50 
     | 
    
         
             
                def send_action(name, *args)
         
     | 
| 
       37 
51 
     | 
    
         
             
                  @_status          = env["PATH_INFO"][1..-1].to_i
         
     | 
| 
       38 
52 
     | 
    
         
             
                  @_response.status = @_status
         
     | 
| 
         @@ -60,5 +74,11 @@ module Rambulance 
     | 
|
| 
       60 
74 
     | 
    
         
             
                def controller_path
         
     | 
| 
       61 
75 
     | 
    
         
             
                  Rambulance.view_path
         
     | 
| 
       62 
76 
     | 
    
         
             
                end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                def bad_request_exception
         
     | 
| 
      
 79 
     | 
    
         
            +
                  ActionController::BadRequest
         
     | 
| 
      
 80 
     | 
    
         
            +
                rescue NameError
         
     | 
| 
      
 81 
     | 
    
         
            +
                  TypeError # Rails 3.2 doesn't know about ActionController::BadRequest
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
       63 
83 
     | 
    
         
             
              end
         
     | 
| 
       64 
84 
     | 
    
         
             
            end
         
     | 
    
        data/lib/rambulance/version.rb
    CHANGED
    
    
    
        data/rambulance.gemspec
    CHANGED
    
    | 
         @@ -27,7 +27,7 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       27 
27 
     | 
    
         
             
              spec.add_development_dependency "tzinfo"
         
     | 
| 
       28 
28 
     | 
    
         
             
              spec.add_development_dependency "jbuilder"
         
     | 
| 
       29 
29 
     | 
    
         
             
              spec.add_development_dependency "rspec"
         
     | 
| 
       30 
     | 
    
         
            -
              spec.add_development_dependency "rspec-rails" 
     | 
| 
      
 30 
     | 
    
         
            +
              spec.add_development_dependency "rspec-rails"
         
     | 
| 
       31 
31 
     | 
    
         
             
              spec.add_development_dependency "capybara"
         
     | 
| 
       32 
32 
     | 
    
         
             
              spec.add_development_dependency "appraisal"
         
     | 
| 
       33 
33 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Bad request.
         
     | 
    
        data/spec/fake_app/rails_app.rb
    CHANGED
    
    | 
         @@ -25,7 +25,9 @@ end 
     | 
|
| 
       25 
25 
     | 
    
         
             
            class CustomException < StandardError; end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
            Rambulance.setup do |config|
         
     | 
| 
      
 28 
     | 
    
         
            +
              config.layout_name = "error"
         
     | 
| 
       28 
29 
     | 
    
         
             
              config.rescue_responses = {
         
     | 
| 
      
 30 
     | 
    
         
            +
                'TypeError'       => :bad_request,
         
     | 
| 
       29 
31 
     | 
    
         
             
                'CustomException' => :not_found
         
     | 
| 
       30 
32 
     | 
    
         
             
              }
         
     | 
| 
       31 
33 
     | 
    
         
             
            end
         
     | 
| 
         @@ -53,6 +55,8 @@ class UsersController < ApplicationController 
     | 
|
| 
       53 
55 
     | 
    
         
             
              def new
         
     | 
| 
       54 
56 
     | 
    
         
             
                raise ActionController::InvalidAuthenticityToken
         
     | 
| 
       55 
57 
     | 
    
         
             
              end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
              def create; end
         
     | 
| 
       56 
60 
     | 
    
         
             
            end
         
     | 
| 
       57 
61 
     | 
    
         | 
| 
       58 
62 
     | 
    
         
             
            # helpers
         
     | 
| 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: UTF-8
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            feature 'Error json  
     | 
| 
      
 4 
     | 
    
         
            +
            feature 'Error json response', if: !ENV["CUSTOM_EXCEPTIONS_APP"], type: :request do
         
     | 
| 
       5 
5 
     | 
    
         
             
              def json_response
         
     | 
| 
       6 
6 
     | 
    
         
             
                JSON.parse(response.body)
         
     | 
| 
       7 
7 
     | 
    
         
             
              end
         
     | 
| 
         @@ -10,31 +10,31 @@ feature 'Error json responses', if: !ENV["CUSTOM_EXCEPTIONS_APP"] do 
     | 
|
| 
       10 
10 
     | 
    
         
             
                super(path, nil, "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json")
         
     | 
| 
       11 
11 
     | 
    
         
             
              end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
              scenario ' 
     | 
| 
      
 13 
     | 
    
         
            +
              scenario 'returns 422 json due to ActionController:InvalidAuthenticityToken but without its template' do
         
     | 
| 
       14 
14 
     | 
    
         
             
                get '/users/new'
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                response.status. 
     | 
| 
       17 
     | 
    
         
            -
                json_response['message']. 
     | 
| 
      
 16 
     | 
    
         
            +
                expect(response.status).to eq(422)
         
     | 
| 
      
 17 
     | 
    
         
            +
                expect(json_response['message']).to eq("Something went wrong")
         
     | 
| 
       18 
18 
     | 
    
         
             
              end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
              scenario ' 
     | 
| 
      
 20 
     | 
    
         
            +
              scenario 'returns 500 json due to RuntimeError' do
         
     | 
| 
       21 
21 
     | 
    
         
             
                get '/users/1.json'
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                response.status. 
     | 
| 
       24 
     | 
    
         
            -
                json_response['message']. 
     | 
| 
      
 23 
     | 
    
         
            +
                expect(response.status).to eq(500)
         
     | 
| 
      
 24 
     | 
    
         
            +
                expect(json_response['message']).to eq("Something went wrong")
         
     | 
| 
       25 
25 
     | 
    
         
             
              end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
              scenario ' 
     | 
| 
      
 27 
     | 
    
         
            +
              scenario 'returns 404 json due to CustomException' do
         
     | 
| 
       28 
28 
     | 
    
         
             
                get '/users.json'
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
                response.status. 
     | 
| 
       31 
     | 
    
         
            -
                json_response['message']. 
     | 
| 
      
 30 
     | 
    
         
            +
                expect(response.status).to eq(404)
         
     | 
| 
      
 31 
     | 
    
         
            +
                expect(json_response['message']).to eq("Page not found")
         
     | 
| 
       32 
32 
     | 
    
         
             
              end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
              scenario ' 
     | 
| 
      
 34 
     | 
    
         
            +
              scenario 'returns 404 json due to ActinoController::RoutingError' do
         
     | 
| 
       35 
35 
     | 
    
         
             
                get '/doesnt_exist.json'
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
                response.status. 
     | 
| 
       38 
     | 
    
         
            -
                json_response['message']. 
     | 
| 
      
 37 
     | 
    
         
            +
                expect(response.status).to eq(404)
         
     | 
| 
      
 38 
     | 
    
         
            +
                expect(json_response['message']).to eq("Page not found")
         
     | 
| 
       39 
39 
     | 
    
         
             
              end
         
     | 
| 
       40 
40 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,42 +1,58 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: UTF-8
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            feature 'Error  
     | 
| 
      
 4 
     | 
    
         
            +
            feature 'Error page' do
         
     | 
| 
       5 
5 
     | 
    
         
             
              shared_examples_for "an action that renders 500 page if the template is missing" do
         
     | 
| 
       6 
     | 
    
         
            -
                scenario ' 
     | 
| 
      
 6 
     | 
    
         
            +
                scenario 'displays 500 page and return 422 Bad Request status' do
         
     | 
| 
       7 
7 
     | 
    
         
             
                  visit '/users/new'
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
                  page.status_code. 
     | 
| 
       10 
     | 
    
         
            -
                  page.body. 
     | 
| 
       11 
     | 
    
         
            -
                  page.body. 
     | 
| 
      
 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 
12 
     | 
    
         
             
                end
         
     | 
| 
       13 
13 
     | 
    
         
             
              end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
              context ' 
     | 
| 
      
 15 
     | 
    
         
            +
              context 'generated by the default exceptions app', if: !ENV["CUSTOM_EXCEPTIONS_APP"] do
         
     | 
| 
       16 
16 
     | 
    
         
             
                it_behaves_like "an action that renders 500 page if the template is missing"
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
                scenario ' 
     | 
| 
      
 18 
     | 
    
         
            +
                scenario 'displays 500 page due to RuntimeError' do
         
     | 
| 
       19 
19 
     | 
    
         
             
                  visit '/users/1'
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                  page.status_code. 
     | 
| 
       22 
     | 
    
         
            -
                  page.body. 
     | 
| 
       23 
     | 
    
         
            -
                  page.body. 
     | 
| 
      
 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 
24 
     | 
    
         
             
                end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                scenario ' 
     | 
| 
      
 26 
     | 
    
         
            +
                scenario 'displays 404 page due to CustomException' do
         
     | 
| 
       27 
27 
     | 
    
         
             
                  visit '/users'
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
                  page.status_code. 
     | 
| 
       30 
     | 
    
         
            -
                  page.body. 
     | 
| 
       31 
     | 
    
         
            -
                  page.body. 
     | 
| 
      
 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 
32 
     | 
    
         
             
                end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                scenario ' 
     | 
| 
      
 34 
     | 
    
         
            +
                scenario 'displays 404 page due to ActionController::RoutingError' do
         
     | 
| 
       35 
35 
     | 
    
         
             
                  visit '/doesnt_exist'
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
                  page.status_code. 
     | 
| 
       38 
     | 
    
         
            -
                  page.body. 
     | 
| 
       39 
     | 
    
         
            -
                  page.body. 
     | 
| 
      
 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."
         
     | 
| 
       40 
56 
     | 
    
         
             
                end
         
     | 
| 
       41 
57 
     | 
    
         | 
| 
       42 
58 
     | 
    
         
             
                context "with a custom layout name" do
         
     | 
| 
         @@ -47,27 +63,27 @@ feature 'Error pages' do 
     | 
|
| 
       47 
63 
     | 
    
         | 
| 
       48 
64 
     | 
    
         
             
                  scenario 'uses the custom layout' do
         
     | 
| 
       49 
65 
     | 
    
         
             
                    visit '/doesnt_exist'
         
     | 
| 
       50 
     | 
    
         
            -
                    page.body. 
     | 
| 
      
 66 
     | 
    
         
            +
                    expect(page.body).to have_content "Application page"
         
     | 
| 
       51 
67 
     | 
    
         
             
                  end
         
     | 
| 
       52 
68 
     | 
    
         
             
                end
         
     | 
| 
       53 
69 
     | 
    
         
             
              end
         
     | 
| 
       54 
70 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
              context " 
     | 
| 
      
 71 
     | 
    
         
            +
              context "generated by a custom exception app", if: ENV["CUSTOM_EXCEPTIONS_APP"] do
         
     | 
| 
       56 
72 
     | 
    
         
             
                it_behaves_like "an action that renders 500 page if the template is missing"
         
     | 
| 
       57 
73 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
                scenario ' 
     | 
| 
      
 74 
     | 
    
         
            +
                scenario 'displays 404 page due to ActinoController::RoutingError' do
         
     | 
| 
       59 
75 
     | 
    
         
             
                  visit '/doesnt_exist'
         
     | 
| 
       60 
76 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
                  page.status_code. 
     | 
| 
       62 
     | 
    
         
            -
                  page.body. 
     | 
| 
       63 
     | 
    
         
            -
                  page.body. 
     | 
| 
      
 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."
         
     | 
| 
       64 
80 
     | 
    
         
             
                end
         
     | 
| 
       65 
81 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
                scenario ' 
     | 
| 
      
 82 
     | 
    
         
            +
                scenario 'displays 500 page due to RuntimeError' do
         
     | 
| 
       67 
83 
     | 
    
         
             
                  visit '/users/1'
         
     | 
| 
       68 
84 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
                  page.status_code. 
     | 
| 
       70 
     | 
    
         
            -
                  page.body. 
     | 
| 
      
 85 
     | 
    
         
            +
                  expect(page.status_code).to eq(500)
         
     | 
| 
      
 86 
     | 
    
         
            +
                  expect(page.body).to have_content "Custom error page"
         
     | 
| 
       71 
87 
     | 
    
         
             
                end
         
     | 
| 
       72 
88 
     | 
    
         
             
              end
         
     | 
| 
       73 
89 
     | 
    
         
             
            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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.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: 2014-09- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-09-18 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activesupport
         
     | 
| 
         @@ -126,16 +126,16 @@ dependencies: 
     | 
|
| 
       126 
126 
     | 
    
         
             
              name: rspec-rails
         
     | 
| 
       127 
127 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       128 
128 
     | 
    
         
             
                requirements:
         
     | 
| 
       129 
     | 
    
         
            -
                - - " 
     | 
| 
      
 129 
     | 
    
         
            +
                - - ">="
         
     | 
| 
       130 
130 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       131 
     | 
    
         
            -
                    version:  
     | 
| 
      
 131 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       132 
132 
     | 
    
         
             
              type: :development
         
     | 
| 
       133 
133 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       134 
134 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       135 
135 
     | 
    
         
             
                requirements:
         
     | 
| 
       136 
     | 
    
         
            -
                - - " 
     | 
| 
      
 136 
     | 
    
         
            +
                - - ">="
         
     | 
| 
       137 
137 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       138 
     | 
    
         
            -
                    version:  
     | 
| 
      
 138 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       139 
139 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       140 
140 
     | 
    
         
             
              name: capybara
         
     | 
| 
       141 
141 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -183,6 +183,7 @@ files: 
     | 
|
| 
       183 
183 
     | 
    
         
             
            - gemfiles/rails_32.gemfile
         
     | 
| 
       184 
184 
     | 
    
         
             
            - gemfiles/rails_40.gemfile
         
     | 
| 
       185 
185 
     | 
    
         
             
            - gemfiles/rails_41.gemfile
         
     | 
| 
      
 186 
     | 
    
         
            +
            - gemfiles/rails_42.gemfile
         
     | 
| 
       186 
187 
     | 
    
         
             
            - gemfiles/rails_edge.gemfile
         
     | 
| 
       187 
188 
     | 
    
         
             
            - lib/generators/rambulance/exceptions_app_generator.rb
         
     | 
| 
       188 
189 
     | 
    
         
             
            - lib/generators/rambulance/install_generator.rb
         
     | 
| 
         @@ -208,6 +209,7 @@ files: 
     | 
|
| 
       208 
209 
     | 
    
         
             
            - lib/rambulance/railtie.rb
         
     | 
| 
       209 
210 
     | 
    
         
             
            - lib/rambulance/version.rb
         
     | 
| 
       210 
211 
     | 
    
         
             
            - rambulance.gemspec
         
     | 
| 
      
 212 
     | 
    
         
            +
            - spec/fake_app/app/views/errors/bad_request.html.erb
         
     | 
| 
       211 
213 
     | 
    
         
             
            - spec/fake_app/app/views/errors/internal_server_error.html.erb
         
     | 
| 
       212 
214 
     | 
    
         
             
            - spec/fake_app/app/views/errors/internal_server_error.json.jbuilder
         
     | 
| 
       213 
215 
     | 
    
         
             
            - spec/fake_app/app/views/errors/not_found.html.erb
         
     | 
| 
         @@ -244,6 +246,7 @@ signing_key: 
     | 
|
| 
       244 
246 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       245 
247 
     | 
    
         
             
            summary: Simple and safe way to dynamically generate error pages
         
     | 
| 
       246 
248 
     | 
    
         
             
            test_files:
         
     | 
| 
      
 249 
     | 
    
         
            +
            - spec/fake_app/app/views/errors/bad_request.html.erb
         
     | 
| 
       247 
250 
     | 
    
         
             
            - spec/fake_app/app/views/errors/internal_server_error.html.erb
         
     | 
| 
       248 
251 
     | 
    
         
             
            - spec/fake_app/app/views/errors/internal_server_error.json.jbuilder
         
     | 
| 
       249 
252 
     | 
    
         
             
            - spec/fake_app/app/views/errors/not_found.html.erb
         
     |