rescue-dog 0.3.8 → 0.3.9
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/.gitignore +1 -0
- data/.travis.yml +5 -6
- data/Gemfile +0 -6
- data/lib/rescue/version.rb +1 -1
- data/rescue-dog.gemspec +21 -15
- metadata +64 -29
- data/spec/fake_rails.rb +0 -98
- data/spec/rescue/controller_spec.rb +0 -166
- data/spec/rescue/controllers/action_spec.rb +0 -129
- data/spec/rescue/controllers/dynamic_spec.rb +0 -31
- data/spec/rescue/controllers/flash_spec.rb +0 -27
- data/spec/rescue/controllers/static_spec.rb +0 -30
- data/spec/rescue/exceptions/respond_error_spec.rb +0 -36
- data/spec/rescue_spec.rb +0 -32
- data/spec/spec_helper.rb +0 -19
- data/spec/test_case.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8699864729a39a021ec3035fedb01dd3d30b3aef
|
4
|
+
data.tar.gz: fac329c748d23e371ae9de1af58b12eacb10d9ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c8916cc3bfd63a39ab04f2d94abf813b0a482a6b325132174958643c2c52e7ee57fb2b8981206c72fa7b9085d4cbcd1d41119c26b0aa44d1f3a883999286b49
|
7
|
+
data.tar.gz: 1afce3a4df831f416e8cfbb2b5505094f9f717c528d03e17ec2771e5767d8e519280a6f41d57620ee3ecc3aabb582e42b345801059edd8b8d8135e558aa3776b
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,23 +1,22 @@
|
|
1
1
|
language: ruby
|
2
|
-
bundler_args: --without development
|
3
2
|
rvm:
|
4
3
|
- 1.9.3
|
5
4
|
- 2.0.0
|
5
|
+
- 2.1
|
6
|
+
- 2.2.2
|
6
7
|
- ruby-head
|
7
8
|
- jruby-19mode
|
8
9
|
- jruby-20mode
|
9
10
|
- jruby-head
|
10
|
-
- rbx-
|
11
|
+
- rbx-2
|
11
12
|
matrix:
|
12
13
|
allow_failures:
|
13
14
|
- rvm: ruby-head
|
14
15
|
- rvm: jruby-head
|
16
|
+
- rvm: rbx-2
|
17
|
+
before_install: gem install bundler -v 1.10.5
|
15
18
|
branches:
|
16
19
|
only:
|
17
20
|
- master
|
18
21
|
after_success:
|
19
22
|
- cover -report coveralls
|
20
|
-
notifications:
|
21
|
-
recipients:
|
22
|
-
- yuliinfo@gmail.com
|
23
|
-
|
data/Gemfile
CHANGED
data/lib/rescue/version.rb
CHANGED
data/rescue-dog.gemspec
CHANGED
@@ -1,22 +1,28 @@
|
|
1
|
-
#
|
1
|
+
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'rescue/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
gem.description = %q{Responds status and error handling for Rails}
|
12
|
-
gem.summary = %q{Declare simple CRUD and respond error methods}
|
13
|
-
gem.homepage = "https://github.com/yulii/rescue-dog"
|
14
|
-
gem.license = 'MIT'
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rescue-dog'
|
8
|
+
spec.version = Rescue::VERSION
|
9
|
+
spec.authors = ['yulii']
|
10
|
+
spec.email = ['yone.info@gmail.com']
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
spec.summary = 'Responds status and error handling for Rails.'
|
13
|
+
spec.description = 'Declare simple CRUD and respond error methods.'
|
14
|
+
spec.homepage = 'https://github.com/yulii/rescue-dog'
|
15
|
+
spec.license = 'MIT'
|
20
16
|
|
21
|
-
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'rails', '>= 4.0.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'capybara'
|
27
|
+
spec.add_development_dependency 'coveralls'
|
22
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rescue-dog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yulii
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,9 +24,65 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.0.0
|
27
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: capybara
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
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
|
+
description: Declare simple CRUD and respond error methods.
|
28
84
|
email:
|
29
|
-
-
|
85
|
+
- yone.info@gmail.com
|
30
86
|
executables: []
|
31
87
|
extensions: []
|
32
88
|
extra_rdoc_files: []
|
@@ -65,16 +121,6 @@ files:
|
|
65
121
|
- public/500.html
|
66
122
|
- public/500.json
|
67
123
|
- rescue-dog.gemspec
|
68
|
-
- spec/fake_rails.rb
|
69
|
-
- spec/rescue/controller_spec.rb
|
70
|
-
- spec/rescue/controllers/action_spec.rb
|
71
|
-
- spec/rescue/controllers/dynamic_spec.rb
|
72
|
-
- spec/rescue/controllers/flash_spec.rb
|
73
|
-
- spec/rescue/controllers/static_spec.rb
|
74
|
-
- spec/rescue/exceptions/respond_error_spec.rb
|
75
|
-
- spec/rescue_spec.rb
|
76
|
-
- spec/spec_helper.rb
|
77
|
-
- spec/test_case.rb
|
78
124
|
homepage: https://github.com/yulii/rescue-dog
|
79
125
|
licenses:
|
80
126
|
- MIT
|
@@ -95,19 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
141
|
version: '0'
|
96
142
|
requirements: []
|
97
143
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
144
|
+
rubygems_version: 2.4.5
|
99
145
|
signing_key:
|
100
146
|
specification_version: 4
|
101
|
-
summary:
|
102
|
-
test_files:
|
103
|
-
- spec/fake_rails.rb
|
104
|
-
- spec/rescue/controller_spec.rb
|
105
|
-
- spec/rescue/controllers/action_spec.rb
|
106
|
-
- spec/rescue/controllers/dynamic_spec.rb
|
107
|
-
- spec/rescue/controllers/flash_spec.rb
|
108
|
-
- spec/rescue/controllers/static_spec.rb
|
109
|
-
- spec/rescue/exceptions/respond_error_spec.rb
|
110
|
-
- spec/rescue_spec.rb
|
111
|
-
- spec/spec_helper.rb
|
112
|
-
- spec/test_case.rb
|
113
|
-
has_rdoc:
|
147
|
+
summary: Responds status and error handling for Rails.
|
148
|
+
test_files: []
|
data/spec/fake_rails.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'action_controller/railtie'
|
2
|
-
require 'action_view/railtie'
|
3
|
-
|
4
|
-
# const
|
5
|
-
STATUSES = {
|
6
|
-
:bad_request => 400,
|
7
|
-
:unauthorized => 401,
|
8
|
-
:not_found => 404,
|
9
|
-
:server_error => 500,
|
10
|
-
}
|
11
|
-
|
12
|
-
# dummy module
|
13
|
-
module ActiveRecord
|
14
|
-
class RecordNotFound < StandardError ; end
|
15
|
-
end
|
16
|
-
module Mongoid
|
17
|
-
module Errors
|
18
|
-
class DocumentNotFound < StandardError ; end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
module BSON
|
22
|
-
class InvalidObjectId < RuntimeError ; end
|
23
|
-
end
|
24
|
-
|
25
|
-
# config
|
26
|
-
Rescue.configure do |config|
|
27
|
-
config.suppress_response_codes = true
|
28
|
-
end
|
29
|
-
|
30
|
-
app = Class.new Rails::Application
|
31
|
-
app.config.active_support.deprecation = :log
|
32
|
-
app.config.secret_token = 'ccedfce890492dd9fe2908a69a8732104ae133f1e2488bf6a1e96685b05a96d7e11aeaa3da5ade27604a50c3b2c7cc8323dd03ad11bb2e52e95256fb67ef9c8a'
|
33
|
-
app.config.generators do |g|
|
34
|
-
g.template_engine :haml
|
35
|
-
end
|
36
|
-
app.initialize!
|
37
|
-
|
38
|
-
# routing
|
39
|
-
app.routes.draw do
|
40
|
-
STATUSES.each do |name, code|
|
41
|
-
get "/static/#{name}" =>"static##{name}" ,as: "static_#{name}"
|
42
|
-
get "/dynamic/#{name}" =>"dynamic##{name}" ,as: "dynamic_#{name}"
|
43
|
-
end
|
44
|
-
|
45
|
-
Rescue::ApplicationError::STATUS_CODES.each do |code, e|
|
46
|
-
get "/status/#{code}" =>"status#error_#{code}" ,as: "status_#{code}"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# controllers
|
51
|
-
class ApplicationController < ActionController::Base ; end
|
52
|
-
|
53
|
-
class StaticController < ApplicationController
|
54
|
-
include Rescue::Controller::Static
|
55
|
-
rescue_associate :BadRequest ,with: 400
|
56
|
-
rescue_associate :Unauthorized ,with: 401
|
57
|
-
rescue_associate :NotFound, Mongoid::Errors::DocumentNotFound, BSON::InvalidObjectId, with: 404
|
58
|
-
rescue_associate :ServerError ,with: 500
|
59
|
-
|
60
|
-
STATUSES.each do |name, code|
|
61
|
-
class_name = "#{name}".classify
|
62
|
-
define_method name do
|
63
|
-
raise class_name.constantize
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class DynamicController < ApplicationController
|
69
|
-
include Rescue::Controller::Dynamic
|
70
|
-
rescue_associate :BadRequest ,with: 400
|
71
|
-
rescue_associate :Unauthorized ,with: 401
|
72
|
-
rescue_associate :NotFound, ActiveRecord::RecordNotFound, with: 404
|
73
|
-
rescue_associate :ServerError ,with: 500
|
74
|
-
|
75
|
-
STATUSES.each do |name, code|
|
76
|
-
class_name = "#{name}".classify
|
77
|
-
define_method name do
|
78
|
-
raise class_name.constantize.new "This is an explanation of what caused the error."
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
class StatusController < ApplicationController
|
84
|
-
include Rescue::Controller::Dynamic
|
85
|
-
include Rescue::RespondError
|
86
|
-
|
87
|
-
Rescue::ApplicationError::STATUS_CODES.each do |code, e|
|
88
|
-
define_method "error_#{code}" do
|
89
|
-
raise e[:status].gsub(' ', '').constantize.new "This is an explanation of what caused the error."
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
# models
|
95
|
-
class RescueModel
|
96
|
-
end
|
97
|
-
|
98
|
-
Object.const_set(:ApplicationHelper,Module.new)
|
@@ -1,166 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Rescue::Controller do
|
5
|
-
|
6
|
-
let(:controller) do
|
7
|
-
Class.new ApplicationController do
|
8
|
-
include Rescue::Controller
|
9
|
-
rescue_controller RescueModel,
|
10
|
-
show: [:show_action],
|
11
|
-
edit: [:edit_action],
|
12
|
-
new: [:new_action],
|
13
|
-
create: { render: lambda { } ,rescue: lambda { raise $! } },
|
14
|
-
update: { render: lambda { } ,rescue: lambda { raise $! } },
|
15
|
-
destroy: { render: lambda { } ,rescue: lambda { raise $! } },
|
16
|
-
create_action: { type: :create ,render: lambda { } ,rescue: lambda { raise $! } ,params: :customized_params },
|
17
|
-
update_action: { type: :update ,render: lambda { } ,rescue: lambda { raise $! } ,params: :customized_params },
|
18
|
-
destroy_action: { type: :destroy ,render: lambda { } ,rescue: lambda { raise $! } ,params: :customized_params }
|
19
|
-
|
20
|
-
def customized_create_action
|
21
|
-
rescue_respond(:create_call, create_params,
|
22
|
-
render: lambda { },
|
23
|
-
rescue: lambda { }
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
def customized_update_action
|
28
|
-
rescue_respond(:update_call, update_params,
|
29
|
-
render: lambda { },
|
30
|
-
rescue: lambda { }
|
31
|
-
)
|
32
|
-
end
|
33
|
-
|
34
|
-
def customized_destroy_action
|
35
|
-
rescue_respond(:destroy_call, destroy_params,
|
36
|
-
render: lambda { },
|
37
|
-
rescue: lambda { }
|
38
|
-
)
|
39
|
-
end
|
40
|
-
|
41
|
-
def execute
|
42
|
-
rescue_respond(:execute_call, execute_params,
|
43
|
-
render: lambda { },
|
44
|
-
rescue: lambda { }
|
45
|
-
)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Stub: flash object
|
51
|
-
let(:flash) do
|
52
|
-
flash = Hash.new
|
53
|
-
flash.stub(:now).and_return({})
|
54
|
-
flash
|
55
|
-
end
|
56
|
-
|
57
|
-
[:rescue_associate, :rescue_controller].each do |name|
|
58
|
-
it "should declare `#{name}` method" do
|
59
|
-
expect(controller.public_methods.include? name).to be_true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
[ :rescue_respond,
|
64
|
-
:find_call, :new_call, :create_call, :update_call, :destroy_call].each do |name|
|
65
|
-
it "should declare `#{name}` method as private" do
|
66
|
-
expect(controller.private_instance_methods.include? name).to be_true
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
[ :new, :edit, :show, :create, :update, :destroy,
|
71
|
-
:show_action, :edit_action, :new_action,
|
72
|
-
:create_action, :update_action, :destroy_action ].each do |name|
|
73
|
-
it "should declare `#{name}` method as public" do
|
74
|
-
expect(controller.public_instance_methods.include? name).to be_true
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "when action is executed" do
|
79
|
-
let(:object) do
|
80
|
-
object = controller.new
|
81
|
-
# Stub: flash message
|
82
|
-
object.stub(:flash).and_return(flash)
|
83
|
-
# Stub: controller/action name for flash messages
|
84
|
-
object.stub(:controller_path).and_return('')
|
85
|
-
object.stub(:controller_name).and_return('')
|
86
|
-
object.stub(:action_name).and_return('')
|
87
|
-
|
88
|
-
# Stub: parameter methods
|
89
|
-
object.stub(:create_params).and_return({})
|
90
|
-
object.stub(:update_params).and_return({})
|
91
|
-
object.stub(:destroy_params).and_return({})
|
92
|
-
object.stub(:execute_params).and_return({})
|
93
|
-
object.stub(:customized_params).and_return({})
|
94
|
-
|
95
|
-
# Stub: call methods
|
96
|
-
object.stub(:find_call).with(any_args()).and_raise('find_call execute')
|
97
|
-
object.stub(:new_call).and_raise('new_call execute')
|
98
|
-
object.stub(:create_call).and_raise('create_call execute')
|
99
|
-
object.stub(:update_call).and_raise('update_call execute')
|
100
|
-
object.stub(:destroy_call).and_raise('destroy_call execute')
|
101
|
-
object.stub(:execute_call).and_raise()
|
102
|
-
object
|
103
|
-
end
|
104
|
-
|
105
|
-
# Action Type Relation
|
106
|
-
{ find: [:show, :edit, :show_action, :edit_action],
|
107
|
-
new: [:new, :new_action],
|
108
|
-
create: [:create, :create_action],
|
109
|
-
update: [:update, :update_action],
|
110
|
-
destroy: [:destroy, :destroy_action]
|
111
|
-
}.each do |type, names|
|
112
|
-
names.each do |name|
|
113
|
-
it "should run `#{type}_call` when `#{name}` is executed" do
|
114
|
-
expect { object.send(name) }.to raise_error(RuntimeError, "#{type}_call execute")
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
#it "should be performed within 500 microseconds" do
|
120
|
-
# n = 10000
|
121
|
-
# measure = Benchmark.measure do
|
122
|
-
# n.times { object.execute }
|
123
|
-
# end
|
124
|
-
# expect(measure.total).to be < (500 * 1.0e-06 * n)
|
125
|
-
#end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "#rescue_respond" do
|
129
|
-
let(:object) do
|
130
|
-
clazz = Class.new ApplicationController do
|
131
|
-
include Rescue::Controller
|
132
|
-
|
133
|
-
# Subjects
|
134
|
-
def render_execute
|
135
|
-
rescue_respond(:stub_call, {},
|
136
|
-
render: lambda { 'render' },
|
137
|
-
rescue: lambda { 'rescue' }
|
138
|
-
)
|
139
|
-
end
|
140
|
-
|
141
|
-
def rescue_execute
|
142
|
-
rescue_respond(:stub_call, {},
|
143
|
-
render: lambda { raise RuntimeError },
|
144
|
-
rescue: lambda { 'rescue' }
|
145
|
-
)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
object = clazz.new
|
150
|
-
object.stub(:flash).and_return(flash)
|
151
|
-
object.stub(:controller_path).and_return('rescue')
|
152
|
-
object.stub(:action_name).and_return('action')
|
153
|
-
object.stub(:stub_call).with({},{}).and_return(nil)
|
154
|
-
object
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should render with no error" do
|
158
|
-
expect(object.render_execute).to eq('render')
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should render by the rescue block" do
|
162
|
-
expect(object.rescue_execute).to eq('rescue')
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Rescue::Controller::Action do
|
5
|
-
|
6
|
-
let(:model) do # Stub of Model Class
|
7
|
-
clazz = Class.new
|
8
|
-
clazz.stub(:new).with(any_args()) do
|
9
|
-
object = Object.new
|
10
|
-
object.stub(:attributes=).and_return(true)
|
11
|
-
object.stub(:save!).and_return(true)
|
12
|
-
object.stub(:destroy).and_return(true)
|
13
|
-
object
|
14
|
-
end
|
15
|
-
clazz.stub(:where).and_return(clazz)
|
16
|
-
clazz.stub(:find).and_return(clazz.new)
|
17
|
-
clazz
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#define_call" do
|
21
|
-
let(:controller) do # Fake Controller
|
22
|
-
clazz = model
|
23
|
-
Class.new do
|
24
|
-
Rescue::Controller::Action.define_call self, clazz, :@rescue
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:object) do
|
29
|
-
object = controller.new
|
30
|
-
object.stub(:params).and_return({})
|
31
|
-
object
|
32
|
-
end
|
33
|
-
|
34
|
-
let(:params) { {} }
|
35
|
-
|
36
|
-
[:find_call, :new_call, :create_call, :update_call, :destroy_call].each do |name|
|
37
|
-
it "should declare `#{name}` method as private" do
|
38
|
-
expect(controller.private_instance_methods.include? name).to be_true
|
39
|
-
end
|
40
|
-
it "should not raise error" do
|
41
|
-
expect { object.send(name, params) }.not_to raise_error
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#define" do
|
47
|
-
let(:controller) do # Fake Controller
|
48
|
-
clazz = model
|
49
|
-
Class.new do
|
50
|
-
Rescue::Controller::Action.define_call self, clazz, :@rescue
|
51
|
-
Rescue::Controller::Action.define self,
|
52
|
-
[:show, :edit, :new, :create, :update, :destroy],
|
53
|
-
show: { render: lambda { 'show' } },
|
54
|
-
edit: { render: lambda { 'edit' } },
|
55
|
-
new: { render: lambda { 'new' } },
|
56
|
-
create: { render: lambda { 'create' } },
|
57
|
-
update: { render: lambda { 'update' } },
|
58
|
-
destroy: { render: lambda { 'destroy' } }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
let(:object) do
|
63
|
-
object = controller.new
|
64
|
-
object.stub(:params).and_return({})
|
65
|
-
object.stub(:create_params).and_return({})
|
66
|
-
object.stub(:update_params).and_return({})
|
67
|
-
object.stub(:destroy_params).and_return({})
|
68
|
-
|
69
|
-
# Stub: rescue_respond
|
70
|
-
object.stub(:rescue_respond) do |call, params, options|
|
71
|
-
options[:render].call
|
72
|
-
end
|
73
|
-
object
|
74
|
-
end
|
75
|
-
|
76
|
-
[:show, :edit, :new, :create, :update, :destroy].each do |name|
|
77
|
-
it "should declare `#{name}` method" do
|
78
|
-
expect(controller.public_instance_methods.include? name).to be_true
|
79
|
-
end
|
80
|
-
it "should render" do
|
81
|
-
expect(object.send(name)).to eq(name.to_s)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "when unknown types are specified" do
|
86
|
-
it do
|
87
|
-
expect {
|
88
|
-
Class.new do
|
89
|
-
Rescue::Controller::Action.define self, [:action],
|
90
|
-
action: { type: :undefined ,render: lambda { 'render' } ,rescue: lambda { 'rescue' } }
|
91
|
-
end
|
92
|
-
}.to raise_error(Rescue::NoActionError, Rescue::NoActionError.new(:undefined).message)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "when an action name is duplicated" do
|
97
|
-
it "should not raise error for the first time" do
|
98
|
-
expect {
|
99
|
-
Class.new do
|
100
|
-
Rescue::Controller::Action.define self, [:action],
|
101
|
-
action: { type: :show ,render: lambda { 'render' } ,rescue: lambda { 'rescue' } }
|
102
|
-
end
|
103
|
-
}.not_to raise_error
|
104
|
-
end
|
105
|
-
it "should raise RuntimeError with \"`action` is already defined.\"" do
|
106
|
-
expect {
|
107
|
-
Class.new do
|
108
|
-
def action ; end
|
109
|
-
Rescue::Controller::Action.define self, [:action],
|
110
|
-
action: { type: :show ,render: lambda { 'render' } ,rescue: lambda { 'rescue' } }
|
111
|
-
end
|
112
|
-
}.to raise_error(RuntimeError, "`action` is already defined.")
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "when an parameter method is undefined" do
|
117
|
-
{ create: :create_params,
|
118
|
-
update: :update_params,
|
119
|
-
destroy: :destroy_params }.each do |name, params|
|
120
|
-
it do
|
121
|
-
expect {
|
122
|
-
controller.new.send(name)
|
123
|
-
}.to raise_error(Rescue::NoParameterMethodError, Rescue::NoParameterMethodError.new(controller, params).message)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Rescue::Controller::Dynamic do
|
5
|
-
|
6
|
-
let(:object) { DynamicController.new }
|
7
|
-
|
8
|
-
describe "respond method" do
|
9
|
-
it "expects to be called in a subclass of ApplicationController" do
|
10
|
-
expect(object.methods.include? Rescue.config.respond_name).to be_true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
TestCase::Controller::ERRORS.each do |name, code|
|
15
|
-
|
16
|
-
describe "response when raise #{name}" do
|
17
|
-
TestCase::Controller::FORMATS.each do |format|
|
18
|
-
context "request format => #{format}" do
|
19
|
-
before do
|
20
|
-
visit "/dynamic/#{name.to_s.underscore}.#{format.to_sym}"
|
21
|
-
end
|
22
|
-
|
23
|
-
it { expect(page).to have_content name.to_s.gsub(/([A-Z]+)([A-Z][a-z])/,'\1 \2').gsub(/([a-z\d])([A-Z])/,'\1 \2') }
|
24
|
-
it { expect(page).to have_content "This is an explanation of what caused the error." } unless format.to_sym == :html
|
25
|
-
it { expect(response_headers["Content-Type"]).to include(format.to_s) }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end ## end each
|
30
|
-
|
31
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Rescue::Controller::Flash do
|
5
|
-
|
6
|
-
describe "#message" do
|
7
|
-
['default', 'rescue', 'rescue/dog'].each do |name|
|
8
|
-
context "when #{{ controller: name, action: :action }}" do
|
9
|
-
|
10
|
-
let(:controller) do
|
11
|
-
clazz = Class.new
|
12
|
-
clazz.stub(:controller_path).and_return(name)
|
13
|
-
clazz.stub(:controller_name).and_return(name)
|
14
|
-
clazz.stub(:action_name).and_return(:action)
|
15
|
-
clazz
|
16
|
-
end
|
17
|
-
|
18
|
-
[:success, :error].each do |status|
|
19
|
-
it do
|
20
|
-
expect(Rescue::Controller::Flash.message(controller, status)).to eq("#{name} #{status}")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Rescue::Controller::Static do
|
5
|
-
|
6
|
-
let(:object) { StaticController.new }
|
7
|
-
|
8
|
-
describe "respond method" do
|
9
|
-
it "expects to be called in a subclass of ApplicationController" do
|
10
|
-
expect(object.methods.include? Rescue.config.respond_name).to be_true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
TestCase::Controller::ERRORS.each do |name, code|
|
15
|
-
|
16
|
-
describe "response when raise #{name}" do
|
17
|
-
TestCase::Controller::FORMATS.each do |format|
|
18
|
-
context "request format => #{format}" do
|
19
|
-
before do
|
20
|
-
visit "/static/#{name.to_s.underscore}.#{format.to_sym}"
|
21
|
-
end
|
22
|
-
|
23
|
-
it { expect(page).to have_content name.to_s.gsub(/([A-Z]+)([A-Z][a-z])/,'\1 \2').gsub(/([a-z\d])([A-Z])/,'\1 \2') }
|
24
|
-
it { expect(response_headers["Content-Type"]).to include(format.to_s) }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end ## end each
|
29
|
-
|
30
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Rescue::RespondError do
|
5
|
-
|
6
|
-
Rescue::ApplicationError::STATUS_CODES.each do |code, e|
|
7
|
-
describe "#{code} #{e[:status]}" do
|
8
|
-
let(:name) { e[:status].gsub(' ', '') }
|
9
|
-
|
10
|
-
it "expects to define an exception class of #{e[:status]}" do
|
11
|
-
expect(Object.const_defined? name).to be_true
|
12
|
-
end
|
13
|
-
|
14
|
-
it "expects to define an exception class that is a kind of Rescue::ApplicationError" do
|
15
|
-
expect(Object.const_get(name).new).to be_a_kind_of Rescue::ApplicationError
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "HTTP Status Code" do
|
21
|
-
context "Suppress Response code is #{Rescue.config.suppress_response_codes}" do
|
22
|
-
Rescue::ApplicationError::STATUS_CODES.each do |code, e|
|
23
|
-
describe "#{code} #{e[:status]}" do
|
24
|
-
before do
|
25
|
-
visit "/status//#{code}.json"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "expects to return #{Rescue.config.suppress_response_codes ? 200 : e[:http]}" do
|
29
|
-
expect(page.status_code).to eq (Rescue.config.suppress_response_codes ? 200 : e[:http])
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
data/spec/rescue_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Rescue do
|
5
|
-
|
6
|
-
describe "define_error_class :RescueStandardError" do
|
7
|
-
let(:name) { :RescueStandardError }
|
8
|
-
before { Rescue::Bind.define_error_class name }
|
9
|
-
|
10
|
-
it "expects to define an exception class" do
|
11
|
-
expect(Object.const_defined? name).to be_true
|
12
|
-
end
|
13
|
-
|
14
|
-
it "expects to define an exception class that is a kind of StandardError" do
|
15
|
-
expect(Object.const_get(name).new).to be_a_kind_of StandardError
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "define_error_class :RescueScriptError, ScriptError" do
|
20
|
-
let(:name) { :RescueScriptError }
|
21
|
-
before { Rescue::Bind.define_error_class name, ScriptError }
|
22
|
-
|
23
|
-
it "expects to define an exception class" do
|
24
|
-
expect(Object.const_defined? name).to be_true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "expects to define an exception class that is a kind of StandardError" do
|
28
|
-
expect(Object.const_get(name).new).to be_a_kind_of ScriptError
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'rubygems'
|
3
|
-
require 'rescue-dog'
|
4
|
-
require 'coveralls'
|
5
|
-
|
6
|
-
require File.join(File.dirname(__FILE__), 'fake_rails')
|
7
|
-
require File.join(File.dirname(__FILE__), 'test_case')
|
8
|
-
require 'capybara/rails'
|
9
|
-
|
10
|
-
#require 'benchmark'
|
11
|
-
|
12
|
-
Coveralls.wear!('rails')
|
13
|
-
RSpec.configure do |config|
|
14
|
-
config.mock_with :rspec
|
15
|
-
config.expect_with :rspec do |c|
|
16
|
-
c.syntax = :expect # disables `should`
|
17
|
-
end
|
18
|
-
config.include Capybara::DSL
|
19
|
-
end
|
data/spec/test_case.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
class TestCase
|
2
|
-
|
3
|
-
class Controller
|
4
|
-
ERRORS = { BadRequest: 400, Unauthorized: 401, NotFound: 404, ServerError: 500 }
|
5
|
-
FORMATS = [Mime::Type.new("text/html", :html), Mime::Type.new("application/json", :json)]
|
6
|
-
|
7
|
-
FLASHS = [:DefaultController, :RescueController, :RescueDogController]
|
8
|
-
end
|
9
|
-
|
10
|
-
end
|