lotus-controller 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -14
- data/.travis.yml +5 -0
- data/.yardopts +4 -0
- data/Gemfile +13 -2
- data/README.md +627 -6
- data/Rakefile +17 -1
- data/lib/lotus-controller.rb +1 -0
- data/lib/lotus/action.rb +55 -0
- data/lib/lotus/action/callable.rb +93 -0
- data/lib/lotus/action/callbacks.rb +138 -0
- data/lib/lotus/action/cookie_jar.rb +97 -0
- data/lib/lotus/action/cookies.rb +60 -0
- data/lib/lotus/action/exposable.rb +81 -0
- data/lib/lotus/action/mime.rb +190 -0
- data/lib/lotus/action/params.rb +53 -0
- data/lib/lotus/action/rack.rb +97 -0
- data/lib/lotus/action/redirect.rb +34 -0
- data/lib/lotus/action/session.rb +48 -0
- data/lib/lotus/action/throwable.rb +130 -0
- data/lib/lotus/controller.rb +65 -2
- data/lib/lotus/controller/dsl.rb +54 -0
- data/lib/lotus/controller/version.rb +4 -1
- data/lib/lotus/http/status.rb +103 -0
- data/lib/rack-patch.rb +20 -0
- data/lotus-controller.gemspec +16 -11
- data/test/action/callbacks_test.rb +99 -0
- data/test/action/params_test.rb +29 -0
- data/test/action_test.rb +31 -0
- data/test/controller_test.rb +24 -0
- data/test/cookies_test.rb +36 -0
- data/test/fixtures.rb +501 -0
- data/test/integration/mime_type_test.rb +175 -0
- data/test/integration/routing_test.rb +141 -0
- data/test/integration/sessions_test.rb +63 -0
- data/test/redirect_test.rb +20 -0
- data/test/session_test.rb +19 -0
- data/test/test_helper.rb +24 -0
- data/test/throw_test.rb +93 -0
- data/test/version_test.rb +7 -0
- metadata +112 -9
data/test/throw_test.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Lotus::Action do
|
4
|
+
describe '.handle_exception' do
|
5
|
+
it 'handle an exception with the given status' do
|
6
|
+
response = HandledExceptionAction.new.call({})
|
7
|
+
|
8
|
+
response[0].must_equal 404
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns a 500 if an action isn't handled" do
|
12
|
+
response = UnhandledExceptionAction.new.call({})
|
13
|
+
|
14
|
+
response[0].must_equal 500
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'with global handled exceptions' do
|
18
|
+
before do
|
19
|
+
class DomainLogicException < StandardError
|
20
|
+
end
|
21
|
+
|
22
|
+
Lotus::Controller.handled_exceptions = {DomainLogicException => 400}
|
23
|
+
|
24
|
+
class GlobalHandledExceptionAction
|
25
|
+
include Lotus::Action
|
26
|
+
|
27
|
+
def call(params)
|
28
|
+
raise DomainLogicException.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
after do
|
34
|
+
Object.send(:remove_const, :DomainLogicException)
|
35
|
+
Object.send(:remove_const, :GlobalHandledExceptionAction)
|
36
|
+
|
37
|
+
Lotus::Controller.handled_exceptions = {}
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'handles raised exception' do
|
41
|
+
response = GlobalHandledExceptionAction.new.call({})
|
42
|
+
|
43
|
+
response[0].must_equal 400
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#throw' do
|
49
|
+
HTTP_TEST_STATUSES.each do |code, body|
|
50
|
+
it "throws an HTTP status code: #{ code }" do
|
51
|
+
response = ThrowCodeAction.new.call({ status: code })
|
52
|
+
|
53
|
+
response[0].must_equal code
|
54
|
+
response[2].must_equal [body]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'throws the code as it is, when not recognized' do
|
59
|
+
response = ThrowCodeAction.new.call({ status: 2131231 })
|
60
|
+
|
61
|
+
response[0].must_equal 500
|
62
|
+
response[2].must_equal ['Internal Server Error']
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'stops execution of before filters (method)' do
|
66
|
+
response = ThrowBeforeMethodAction.new.call({})
|
67
|
+
|
68
|
+
response[0].must_equal 401
|
69
|
+
response[2].must_equal ['Unauthorized']
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'stops execution of before filters (block)' do
|
73
|
+
response = ThrowBeforeBlockAction.new.call({})
|
74
|
+
|
75
|
+
response[0].must_equal 401
|
76
|
+
response[2].must_equal ['Unauthorized']
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'stops execution of after filters (method)' do
|
80
|
+
response = ThrowAfterMethodAction.new.call({})
|
81
|
+
|
82
|
+
response[0].must_equal 408
|
83
|
+
response[2].must_equal ['Request Timeout']
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'stops execution of after filters (block)' do
|
87
|
+
response = ThrowAfterBlockAction.new.call({})
|
88
|
+
|
89
|
+
response[0].must_equal 408
|
90
|
+
response[2].must_equal ['Request Timeout']
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lotus-controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: lotus-utils
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,20 +52,48 @@ dependencies:
|
|
24
52
|
- - "~>"
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.6'
|
27
83
|
- !ruby/object:Gem::Dependency
|
28
84
|
name: rake
|
29
85
|
requirement: !ruby/object:Gem::Requirement
|
30
86
|
requirements:
|
31
|
-
- - "
|
87
|
+
- - "~>"
|
32
88
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
89
|
+
version: '10'
|
34
90
|
type: :development
|
35
91
|
prerelease: false
|
36
92
|
version_requirements: !ruby/object:Gem::Requirement
|
37
93
|
requirements:
|
38
|
-
- - "
|
94
|
+
- - "~>"
|
39
95
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
96
|
+
version: '10'
|
41
97
|
description: Controller layer for Lotus
|
42
98
|
email:
|
43
99
|
- me@lucaguidi.com
|
@@ -46,14 +102,46 @@ extensions: []
|
|
46
102
|
extra_rdoc_files: []
|
47
103
|
files:
|
48
104
|
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- ".yardopts"
|
49
107
|
- Gemfile
|
50
108
|
- LICENSE.txt
|
51
109
|
- README.md
|
52
110
|
- Rakefile
|
111
|
+
- lib/lotus-controller.rb
|
112
|
+
- lib/lotus/action.rb
|
113
|
+
- lib/lotus/action/callable.rb
|
114
|
+
- lib/lotus/action/callbacks.rb
|
115
|
+
- lib/lotus/action/cookie_jar.rb
|
116
|
+
- lib/lotus/action/cookies.rb
|
117
|
+
- lib/lotus/action/exposable.rb
|
118
|
+
- lib/lotus/action/mime.rb
|
119
|
+
- lib/lotus/action/params.rb
|
120
|
+
- lib/lotus/action/rack.rb
|
121
|
+
- lib/lotus/action/redirect.rb
|
122
|
+
- lib/lotus/action/session.rb
|
123
|
+
- lib/lotus/action/throwable.rb
|
53
124
|
- lib/lotus/controller.rb
|
125
|
+
- lib/lotus/controller/dsl.rb
|
54
126
|
- lib/lotus/controller/version.rb
|
127
|
+
- lib/lotus/http/status.rb
|
128
|
+
- lib/rack-patch.rb
|
55
129
|
- lotus-controller.gemspec
|
56
|
-
|
130
|
+
- test/action/callbacks_test.rb
|
131
|
+
- test/action/params_test.rb
|
132
|
+
- test/action_test.rb
|
133
|
+
- test/controller_test.rb
|
134
|
+
- test/cookies_test.rb
|
135
|
+
- test/fixtures.rb
|
136
|
+
- test/integration/mime_type_test.rb
|
137
|
+
- test/integration/routing_test.rb
|
138
|
+
- test/integration/sessions_test.rb
|
139
|
+
- test/redirect_test.rb
|
140
|
+
- test/session_test.rb
|
141
|
+
- test/test_helper.rb
|
142
|
+
- test/throw_test.rb
|
143
|
+
- test/version_test.rb
|
144
|
+
homepage: http://lotusrb.org
|
57
145
|
licenses:
|
58
146
|
- MIT
|
59
147
|
metadata: {}
|
@@ -76,5 +164,20 @@ rubyforge_project:
|
|
76
164
|
rubygems_version: 2.2.0
|
77
165
|
signing_key:
|
78
166
|
specification_version: 4
|
79
|
-
summary: Controller layer for Lotus
|
80
|
-
test_files:
|
167
|
+
summary: Controller layer for Lotus, compatible with Rack
|
168
|
+
test_files:
|
169
|
+
- test/action/callbacks_test.rb
|
170
|
+
- test/action/params_test.rb
|
171
|
+
- test/action_test.rb
|
172
|
+
- test/controller_test.rb
|
173
|
+
- test/cookies_test.rb
|
174
|
+
- test/fixtures.rb
|
175
|
+
- test/integration/mime_type_test.rb
|
176
|
+
- test/integration/routing_test.rb
|
177
|
+
- test/integration/sessions_test.rb
|
178
|
+
- test/redirect_test.rb
|
179
|
+
- test/session_test.rb
|
180
|
+
- test/test_helper.rb
|
181
|
+
- test/throw_test.rb
|
182
|
+
- test/version_test.rb
|
183
|
+
has_rdoc:
|