deas 0.43.4 → 0.43.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deas/runner.rb +16 -10
- data/lib/deas/version.rb +1 -1
- data/lib/deas/view_handler.rb +21 -0
- data/test/unit/runner_tests.rb +39 -22
- data/test/unit/view_handler_tests.rb +45 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA512:
|
3
|
-
|
4
|
-
|
3
|
+
data.tar.gz: 9e29e2252316b365433cd71f765a48b6166292eccf4687041b8b26c531f35729671a03200427858b2658e085be4eef6f977ab6930c09e60e11e91bd76f949ce4
|
4
|
+
metadata.gz: 3f54a3b2fa607f784af01dd0e0ae399181f627d04f80434cbc19de3f083799b7e5b7868a8a4287e62f259300eebb289d02a029b84d5a9a85599d6318372e6b8e
|
5
5
|
SHA1:
|
6
|
-
|
7
|
-
|
6
|
+
data.tar.gz: dd45e7eb9ef4f0177a34df0f763b3a98b4d2bbbb
|
7
|
+
metadata.gz: b8c0087b1b413fc10120dcc340df5787f5bb6781
|
data/lib/deas/runner.rb
CHANGED
@@ -10,17 +10,23 @@ module Deas
|
|
10
10
|
|
11
11
|
DEFAULT_MIME_TYPE = 'application/octet-stream'.freeze
|
12
12
|
DEFAULT_CHARSET = 'utf-8'.freeze
|
13
|
-
|
14
|
-
|
13
|
+
|
14
|
+
def self.body_value(value)
|
15
|
+
# http://www.rubydoc.info/github/rack/rack/master/file/SPEC#The_Body
|
16
|
+
# "The Body must respond to each and must only yield String values"
|
17
|
+
# String#each is a thing in 1.8.7, so account for it here
|
18
|
+
return nil if value.to_s.empty?
|
19
|
+
!value.respond_to?(:each) || value.kind_of?(String) ? [*value.to_s] : value
|
20
|
+
end
|
15
21
|
|
16
22
|
attr_reader :handler_class, :handler
|
17
23
|
attr_reader :request, :route_path, :params
|
18
24
|
attr_reader :logger, :router, :template_source
|
19
25
|
|
20
26
|
def initialize(handler_class, args = nil)
|
21
|
-
@status, @headers, @body = nil, Rack::Utils::HeaderHash.new, nil
|
22
|
-
|
23
27
|
@handler_class = handler_class
|
28
|
+
@status, @body = nil, nil
|
29
|
+
@headers = Rack::Utils::HeaderHash.new.merge(@handler_class.default_headers)
|
24
30
|
@handler = @handler_class.new(self)
|
25
31
|
|
26
32
|
args ||= {}
|
@@ -41,7 +47,10 @@ module Deas
|
|
41
47
|
end
|
42
48
|
|
43
49
|
def to_rack
|
44
|
-
[self.status ||
|
50
|
+
[ self.status || @handler_class.default_status,
|
51
|
+
self.headers.to_hash,
|
52
|
+
self.body || @handler_class.default_body
|
53
|
+
]
|
45
54
|
end
|
46
55
|
|
47
56
|
def status(value = nil)
|
@@ -56,10 +65,7 @@ module Deas
|
|
56
65
|
|
57
66
|
def body(value = nil)
|
58
67
|
if !value.nil?
|
59
|
-
|
60
|
-
# "The Body must respond to each and must only yield String values"
|
61
|
-
# String#each is a thing in 1.8.7, so account for it here
|
62
|
-
@body = !value.respond_to?(:each) || value.kind_of?(String) ? [*value.to_s] : value
|
68
|
+
@body = self.class.body_value(value)
|
63
69
|
end
|
64
70
|
@body
|
65
71
|
end
|
@@ -79,7 +85,7 @@ module Deas
|
|
79
85
|
def halt(*args)
|
80
86
|
self.status(args.shift) if args.first.instance_of?(::Fixnum)
|
81
87
|
self.headers(args.shift) if args.first.kind_of?(::Hash)
|
82
|
-
self.body(args.shift)
|
88
|
+
self.body(args.shift) if !args.first.to_s.empty?
|
83
89
|
throw :halt
|
84
90
|
end
|
85
91
|
|
data/lib/deas/version.rb
CHANGED
data/lib/deas/view_handler.rb
CHANGED
@@ -11,6 +11,10 @@ module Deas
|
|
11
11
|
include InstanceMethods
|
12
12
|
end
|
13
13
|
|
14
|
+
DEFAULT_STATUS = 200.freeze
|
15
|
+
DEFAULT_HEADERS = {}.freeze
|
16
|
+
DEFAULT_BODY = [''].freeze
|
17
|
+
|
14
18
|
module InstanceMethods
|
15
19
|
|
16
20
|
def initialize(runner)
|
@@ -88,6 +92,23 @@ module Deas
|
|
88
92
|
|
89
93
|
module ClassMethods
|
90
94
|
|
95
|
+
def default_status(value = nil)
|
96
|
+
@default_status = value if !value.nil?
|
97
|
+
@default_status || DEFAULT_STATUS
|
98
|
+
end
|
99
|
+
|
100
|
+
def default_headers(value = nil)
|
101
|
+
@default_headers = value if !value.nil? && value.kind_of?(::Hash)
|
102
|
+
@default_headers || DEFAULT_HEADERS
|
103
|
+
end
|
104
|
+
|
105
|
+
def default_body(value = nil)
|
106
|
+
if !value.nil?
|
107
|
+
@default_body = Deas::Runner.body_value(value)
|
108
|
+
end
|
109
|
+
@default_body || DEFAULT_BODY
|
110
|
+
end
|
111
|
+
|
91
112
|
def layout(path = nil, &block)
|
92
113
|
value = !path.nil? ? Proc.new{ path } : block
|
93
114
|
self.layouts.push(value) if value
|
data/test/unit/runner_tests.rb
CHANGED
@@ -12,11 +12,13 @@ class Deas::Runner
|
|
12
12
|
class UnitTests < Assert::Context
|
13
13
|
desc "Deas::Runner"
|
14
14
|
setup do
|
15
|
-
@handler_class =
|
15
|
+
@handler_class = Class.new{ include Deas::ViewHandler }
|
16
16
|
@runner_class = Deas::Runner
|
17
17
|
end
|
18
18
|
subject{ @runner_class }
|
19
19
|
|
20
|
+
should have_imeth :body_value
|
21
|
+
|
20
22
|
should "know its default mime type" do
|
21
23
|
assert_equal 'application/octet-stream', subject::DEFAULT_MIME_TYPE
|
22
24
|
end
|
@@ -25,12 +27,15 @@ class Deas::Runner
|
|
25
27
|
assert_equal 'utf-8', subject::DEFAULT_CHARSET
|
26
28
|
end
|
27
29
|
|
28
|
-
should "know
|
29
|
-
|
30
|
-
end
|
30
|
+
should "know how to build appropriate body values" do
|
31
|
+
assert_nil subject.body_value([nil, ''].sample)
|
31
32
|
|
32
|
-
|
33
|
-
assert_equal
|
33
|
+
exp = [Factory.string]
|
34
|
+
assert_equal exp, subject.body_value(exp)
|
35
|
+
assert_equal exp, subject.body_value(exp.first)
|
36
|
+
|
37
|
+
exp = [Factory.integer.to_s]
|
38
|
+
assert_equal exp, subject.body_value(exp.first.to_i)
|
34
39
|
end
|
35
40
|
|
36
41
|
end
|
@@ -38,6 +43,10 @@ class Deas::Runner
|
|
38
43
|
class InitTests < UnitTests
|
39
44
|
desc "when init"
|
40
45
|
setup do
|
46
|
+
@handler_class.default_status(Factory.integer)
|
47
|
+
@handler_class.default_headers(Factory.string => Factory.string)
|
48
|
+
@handler_class.default_body(Factory.string)
|
49
|
+
|
41
50
|
@request = Factory.request
|
42
51
|
@runner = @runner_class.new(@handler_class, :request => @request)
|
43
52
|
end
|
@@ -151,9 +160,9 @@ class Deas::Runner
|
|
151
160
|
|
152
161
|
should "know its `to_rack` representation" do
|
153
162
|
exp = [
|
154
|
-
|
163
|
+
@handler_class.default_status,
|
155
164
|
subject.headers.to_hash,
|
156
|
-
|
165
|
+
@handler_class.default_body
|
157
166
|
]
|
158
167
|
assert_equal exp, subject.to_rack
|
159
168
|
|
@@ -180,32 +189,31 @@ class Deas::Runner
|
|
180
189
|
|
181
190
|
should "know and merge values on its response headers" do
|
182
191
|
assert_kind_of Rack::Utils::HeaderHash, subject.headers
|
183
|
-
assert_equal
|
192
|
+
assert_equal @handler_class.default_headers, subject.headers
|
184
193
|
|
185
194
|
new_header_values = { Factory.string => Factory.string }
|
186
195
|
subject.headers(new_header_values)
|
187
196
|
assert_kind_of Rack::Utils::HeaderHash, subject.headers
|
188
|
-
|
197
|
+
exp = @handler_class.default_headers.merge(new_header_values)
|
198
|
+
assert_equal exp, subject.headers
|
189
199
|
|
190
200
|
location = Factory.string
|
191
201
|
subject.headers['Location'] = location
|
192
|
-
exp =
|
202
|
+
exp = @handler_class.default_headers.merge(
|
203
|
+
new_header_values.merge('Location' => location)
|
204
|
+
)
|
193
205
|
assert_equal exp, subject.headers
|
194
206
|
end
|
195
207
|
|
196
208
|
should "know and set its response body" do
|
197
209
|
assert_nil subject.body
|
198
210
|
|
199
|
-
|
200
|
-
subject.body
|
201
|
-
assert_equal exp, subject.body
|
202
|
-
|
203
|
-
subject.body exp.first
|
204
|
-
assert_equal exp, subject.body
|
211
|
+
subject.body(nil)
|
212
|
+
assert_nil subject.body
|
205
213
|
|
206
|
-
|
207
|
-
|
208
|
-
assert_equal exp, subject.body
|
214
|
+
value = ['', [Factory.string], Factory.string, Factory.integer].sample
|
215
|
+
exp = Deas::Runner.body_value(value)
|
216
|
+
assert_equal exp, subject.body(value)
|
209
217
|
end
|
210
218
|
|
211
219
|
should "know and set its response content type header" do
|
@@ -263,7 +271,7 @@ class Deas::Runner
|
|
263
271
|
|
264
272
|
end
|
265
273
|
|
266
|
-
class HaltTests <
|
274
|
+
class HaltTests < UnitTests
|
267
275
|
desc "the `halt` method"
|
268
276
|
setup do
|
269
277
|
@status = Factory.integer
|
@@ -297,6 +305,11 @@ class Deas::Runner
|
|
297
305
|
assert_equal @headers, runner.headers
|
298
306
|
assert_nil runner.body
|
299
307
|
|
308
|
+
runner = runner_halted_with(@status, @headers, '')
|
309
|
+
assert_equal @status, runner.status
|
310
|
+
assert_equal @headers, runner.headers
|
311
|
+
assert_nil runner.body
|
312
|
+
|
300
313
|
runner = runner_halted_with(@status, @body)
|
301
314
|
assert_equal @status, runner.status
|
302
315
|
assert_equal({}, runner.headers)
|
@@ -323,11 +336,15 @@ class Deas::Runner
|
|
323
336
|
|
324
337
|
end
|
325
338
|
|
326
|
-
class HaltCalledWithTests <
|
339
|
+
class HaltCalledWithTests < UnitTests
|
327
340
|
setup do
|
341
|
+
@request = Factory.request
|
342
|
+
@runner = @runner_class.new(@handler_class, :request => @request)
|
343
|
+
|
328
344
|
@halt_called_with = nil
|
329
345
|
Assert.stub(@runner, :halt){ |*args| @halt_called_with = args; throw :halt }
|
330
346
|
end
|
347
|
+
subject{ @runner }
|
331
348
|
|
332
349
|
end
|
333
350
|
|
@@ -18,6 +18,7 @@ module Deas::ViewHandler
|
|
18
18
|
end
|
19
19
|
subject{ @handler_class }
|
20
20
|
|
21
|
+
should have_imeths :default_status, :default_headers, :default_body
|
21
22
|
should have_imeths :layout, :layouts
|
22
23
|
should have_imeths :before_callbacks, :after_callbacks
|
23
24
|
should have_imeths :before_init_callbacks, :after_init_callbacks
|
@@ -33,6 +34,50 @@ module Deas::ViewHandler
|
|
33
34
|
assert_includes MuchPlugin, Deas::ViewHandler
|
34
35
|
end
|
35
36
|
|
37
|
+
should "know its default status" do
|
38
|
+
assert_equal 200, subject::DEFAULT_STATUS
|
39
|
+
end
|
40
|
+
|
41
|
+
should "know its default headers" do
|
42
|
+
assert_equal({}, subject::DEFAULT_HEADERS)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "know its default body" do
|
46
|
+
assert_equal [''], subject::DEFAULT_BODY
|
47
|
+
end
|
48
|
+
|
49
|
+
should "know and set its default status" do
|
50
|
+
assert_equal subject::DEFAULT_STATUS, subject.default_status
|
51
|
+
|
52
|
+
exp = Factory.integer
|
53
|
+
subject.default_status exp
|
54
|
+
assert_equal exp, subject.default_status
|
55
|
+
end
|
56
|
+
|
57
|
+
should "know and merge values on its response headers" do
|
58
|
+
assert_equal subject::DEFAULT_HEADERS, subject.default_headers
|
59
|
+
|
60
|
+
new_header_values = { Factory.string => Factory.string }
|
61
|
+
subject.default_headers(new_header_values)
|
62
|
+
assert_equal new_header_values, subject.default_headers
|
63
|
+
|
64
|
+
location = Factory.string
|
65
|
+
subject.default_headers['Location'] = location
|
66
|
+
exp = new_header_values.merge('Location' => location)
|
67
|
+
assert_equal exp, subject.default_headers
|
68
|
+
end
|
69
|
+
|
70
|
+
should "know and set its response body" do
|
71
|
+
assert_equal subject::DEFAULT_BODY, subject.default_body
|
72
|
+
|
73
|
+
subject.default_body [nil, ''].sample
|
74
|
+
assert_equal subject::DEFAULT_BODY, subject.default_body
|
75
|
+
|
76
|
+
value = [[Factory.string], Factory.string, Factory.integer].sample
|
77
|
+
exp = Deas::Runner.body_value(value)
|
78
|
+
assert_equal exp, subject.default_body(value)
|
79
|
+
end
|
80
|
+
|
36
81
|
should "specify layouts" do
|
37
82
|
subject.layout 'layouts/app'
|
38
83
|
assert_equal ['layouts/app'], subject.layouts.map(&:call)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.43.
|
4
|
+
version: 0.43.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2018-04-
|
13
|
+
date: 2018-04-19 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assert
|