deas 0.43.3 → 0.43.4
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/Gemfile +2 -1
- data/deas.gemspec +2 -2
- data/lib/deas/error_handler.rb +6 -6
- data/lib/deas/handler_proxy.rb +4 -4
- data/lib/deas/logging.rb +4 -4
- data/lib/deas/request_data.rb +4 -4
- data/lib/deas/router.rb +48 -2
- data/lib/deas/runner.rb +18 -8
- data/lib/deas/server.rb +21 -4
- data/lib/deas/sinatra_app.rb +7 -14
- data/lib/deas/test_runner.rb +2 -2
- data/lib/deas/trailing_slashes.rb +85 -0
- data/lib/deas/url.rb +1 -1
- data/lib/deas/version.rb +1 -1
- data/lib/deas/view_handler.rb +1 -0
- data/test/support/factory.rb +2 -2
- data/test/support/fake_sinatra_call.rb +1 -3
- data/test/support/routes.rb +34 -0
- data/test/system/deas_tests.rb +42 -1
- data/test/unit/error_handler_tests.rb +7 -7
- data/test/unit/handler_proxy_tests.rb +7 -7
- data/test/unit/logging_tests.rb +7 -9
- data/test/unit/request_data_tests.rb +8 -8
- data/test/unit/router_tests.rb +104 -2
- data/test/unit/runner_tests.rb +52 -18
- data/test/unit/server_tests.rb +3 -1
- data/test/unit/sinatra_app_tests.rb +0 -10
- data/test/unit/test_runner_tests.rb +2 -2
- data/test/unit/trailing_slashes_tests.rb +151 -0
- data/test/unit/url_tests.rb +6 -3
- data/test/unit/view_handler_tests.rb +9 -0
- metadata +7 -4
data/test/unit/runner_tests.rb
CHANGED
@@ -44,10 +44,10 @@ class Deas::Runner
|
|
44
44
|
subject{ @runner }
|
45
45
|
|
46
46
|
should have_readers :handler_class, :handler
|
47
|
+
should have_readers :request, :params, :route_path
|
47
48
|
should have_readers :logger, :router, :template_source
|
48
|
-
should
|
49
|
-
should have_imeths :
|
50
|
-
should have_imeths :status, :headers, :body, :content_type
|
49
|
+
should have_imeths :splat, :run, :to_rack
|
50
|
+
should have_imeths :status, :headers, :body, :content_type, :set_cookie
|
51
51
|
should have_imeths :halt, :redirect, :send_file
|
52
52
|
should have_imeths :render, :source_render, :partial, :source_partial
|
53
53
|
|
@@ -58,36 +58,37 @@ class Deas::Runner
|
|
58
58
|
|
59
59
|
should "default its attrs" do
|
60
60
|
runner = @runner_class.new(@handler_class)
|
61
|
-
assert_kind_of Deas::NullLogger, runner.logger
|
62
|
-
assert_kind_of Deas::Router, runner.router
|
63
|
-
assert_kind_of Deas::NullTemplateSource, runner.template_source
|
64
61
|
|
65
62
|
assert_nil runner.request
|
66
63
|
|
67
|
-
assert_equal Hash.new, runner.params
|
68
64
|
assert_equal '', runner.route_path
|
65
|
+
assert_equal Hash.new, runner.params
|
66
|
+
|
67
|
+
assert_kind_of Deas::NullLogger, runner.logger
|
68
|
+
assert_kind_of Deas::Router, runner.router
|
69
|
+
assert_kind_of Deas::NullTemplateSource, runner.template_source
|
69
70
|
|
70
71
|
assert_nil runner.splat
|
71
72
|
end
|
72
73
|
|
73
74
|
should "know its attrs" do
|
74
75
|
args = {
|
75
|
-
:logger => Factory.string,
|
76
|
-
:router => Factory.string,
|
77
|
-
:template_source => Factory.string,
|
78
76
|
:request => Factory.request,
|
77
|
+
:route_path => Factory.string,
|
79
78
|
:params => { Factory.string => Factory.string },
|
80
|
-
:
|
79
|
+
:logger => Factory.string,
|
80
|
+
:router => Factory.string,
|
81
|
+
:template_source => Factory.string
|
81
82
|
}
|
82
83
|
|
83
84
|
runner = @runner_class.new(@handler_class, args)
|
84
85
|
|
86
|
+
assert_equal args[:request], runner.request
|
87
|
+
assert_equal args[:route_path], runner.route_path
|
88
|
+
assert_equal args[:params], runner.params
|
85
89
|
assert_equal args[:logger], runner.logger
|
86
90
|
assert_equal args[:router], runner.router
|
87
91
|
assert_equal args[:template_source], runner.template_source
|
88
|
-
assert_equal args[:request], runner.request
|
89
|
-
assert_equal args[:params], runner.params
|
90
|
-
assert_equal args[:route_path], runner.route_path
|
91
92
|
end
|
92
93
|
|
93
94
|
should "know its splat value" do
|
@@ -103,8 +104,8 @@ class Deas::Runner
|
|
103
104
|
|
104
105
|
args = {
|
105
106
|
:request => Factory.request(:env => request_env),
|
106
|
-
:
|
107
|
-
:
|
107
|
+
:route_path => route_path,
|
108
|
+
:params => params
|
108
109
|
}
|
109
110
|
|
110
111
|
runner = @runner_class.new(@handler_class, args)
|
@@ -119,8 +120,8 @@ class Deas::Runner
|
|
119
120
|
|
120
121
|
args = {
|
121
122
|
:request => Factory.request(:env => request_env),
|
123
|
+
:route_path => route_path,
|
122
124
|
:params => params,
|
123
|
-
:route_path => route_path
|
124
125
|
}
|
125
126
|
|
126
127
|
runner = @runner_class.new(@handler_class, args)
|
@@ -136,8 +137,8 @@ class Deas::Runner
|
|
136
137
|
|
137
138
|
args = {
|
138
139
|
:request => Factory.request(:env => request_env),
|
140
|
+
:route_path => route_path,
|
139
141
|
:params => params,
|
140
|
-
:route_path => route_path
|
141
142
|
}
|
142
143
|
|
143
144
|
runner = @runner_class.new(@handler_class, args)
|
@@ -201,6 +202,10 @@ class Deas::Runner
|
|
201
202
|
|
202
203
|
subject.body exp.first
|
203
204
|
assert_equal exp, subject.body
|
205
|
+
|
206
|
+
exp = [Factory.integer.to_s]
|
207
|
+
subject.body exp.first.to_i
|
208
|
+
assert_equal exp, subject.body
|
204
209
|
end
|
205
210
|
|
206
211
|
should "know and set its response content type header" do
|
@@ -227,6 +232,35 @@ class Deas::Runner
|
|
227
232
|
assert_equal exp, subject.headers['Content-Type']
|
228
233
|
end
|
229
234
|
|
235
|
+
should "set a cookie header with `set_cookie`" do
|
236
|
+
name, value = Factory.string, Factory.string
|
237
|
+
opts = { Factory.string => Factory.string }
|
238
|
+
exp_headers = {}
|
239
|
+
Rack::Utils.set_cookie_header!(
|
240
|
+
exp_headers,
|
241
|
+
name,
|
242
|
+
(opts || {}).merge(:value => value)
|
243
|
+
)
|
244
|
+
|
245
|
+
rack_utils_set_cookie_header_called_with = nil
|
246
|
+
Assert.stub(Rack::Utils, :set_cookie_header!) do |*args|
|
247
|
+
rack_utils_set_cookie_header_called_with = args
|
248
|
+
Assert.stub_send(Rack::Utils, :set_cookie_header!, *args)
|
249
|
+
end
|
250
|
+
|
251
|
+
subject.set_cookie(name, value, opts)
|
252
|
+
|
253
|
+
exp = [subject.headers, name, opts.merge(:value => value)]
|
254
|
+
assert_equal exp, rack_utils_set_cookie_header_called_with
|
255
|
+
exp = exp_headers['Set-Cookie']
|
256
|
+
assert_includes exp, @runner.headers['Set-Cookie']
|
257
|
+
|
258
|
+
subject.set_cookie(name, value)
|
259
|
+
|
260
|
+
exp = [subject.headers, name, { :value => value }]
|
261
|
+
assert_equal exp, rack_utils_set_cookie_header_called_with
|
262
|
+
end
|
263
|
+
|
230
264
|
end
|
231
265
|
|
232
266
|
class HaltTests < InitTests
|
data/test/unit/server_tests.rb
CHANGED
@@ -248,7 +248,9 @@ module Deas::Server
|
|
248
248
|
assert_equal (num_middlewares+3), subject.middlewares.size
|
249
249
|
assert_equal [Rack::MethodOverride], subject.middlewares[0]
|
250
250
|
assert_equal [Deas::ShowExceptions], subject.middlewares[-2]
|
251
|
-
|
251
|
+
|
252
|
+
exp = [Deas::VerboseLogging, subject.logger]
|
253
|
+
assert_equal exp, subject.middlewares[-1]
|
252
254
|
|
253
255
|
assert_raises do
|
254
256
|
subject.middlewares << [Factory.string]
|
@@ -64,16 +64,6 @@ module Deas::SinatraApp
|
|
64
64
|
assert_equal @config.env, s.environment
|
65
65
|
assert_equal @config.root, s.root
|
66
66
|
|
67
|
-
exp = Deas::ServerData.new({
|
68
|
-
:error_procs => @config.error_procs,
|
69
|
-
:before_route_run_procs => @config.before_route_run_procs,
|
70
|
-
:after_route_run_procs => @config.after_route_run_procs,
|
71
|
-
:logger => @config.logger,
|
72
|
-
:router => @config.router,
|
73
|
-
:template_source => @config.template_source
|
74
|
-
})
|
75
|
-
assert_equal exp, s.deas_server_data
|
76
|
-
|
77
67
|
assert_equal @config.root, s.views
|
78
68
|
assert_equal @config.root, s.public_folder
|
79
69
|
assert_equal 'utf-8', s.default_encoding
|
@@ -33,8 +33,8 @@ class Deas::TestRunner
|
|
33
33
|
:router => Factory.string,
|
34
34
|
:template_source => Factory.string,
|
35
35
|
:request => @request,
|
36
|
-
:params => @params,
|
37
36
|
:route_path => Factory.string,
|
37
|
+
:params => @params,
|
38
38
|
:splat => Factory.path,
|
39
39
|
:custom_value => Factory.integer
|
40
40
|
}
|
@@ -62,8 +62,8 @@ class Deas::TestRunner
|
|
62
62
|
assert_equal @args[:router], subject.router
|
63
63
|
assert_equal @args[:template_source], subject.template_source
|
64
64
|
assert_equal @args[:request], subject.request
|
65
|
-
assert_equal @args[:params], subject.params
|
66
65
|
assert_equal @args[:route_path], subject.route_path
|
66
|
+
assert_equal @args[:params], subject.params
|
67
67
|
end
|
68
68
|
|
69
69
|
should "know its splat value" do
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'deas/trailing_slashes'
|
3
|
+
|
4
|
+
require 'deas/exceptions'
|
5
|
+
require 'deas/router'
|
6
|
+
require 'rack/utils'
|
7
|
+
|
8
|
+
class Deas::TrailingSlashes
|
9
|
+
|
10
|
+
class UnitTests < Assert::Context
|
11
|
+
desc "Deas::TrailingSlashes"
|
12
|
+
setup do
|
13
|
+
@env = {}
|
14
|
+
|
15
|
+
@middleware_class = Deas::TrailingSlashes
|
16
|
+
end
|
17
|
+
subject{ @middleware_class }
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class InitTests < UnitTests
|
22
|
+
desc "when init"
|
23
|
+
setup do
|
24
|
+
@value = Deas::Router::VALID_TRAILING_SLASHES_VALUES.sample
|
25
|
+
|
26
|
+
@handler_run_args = nil
|
27
|
+
@handler_run_proc = nil
|
28
|
+
Assert.stub(HANDLERS[@value], :run) do |*args, &block|
|
29
|
+
@handler_run_args = args
|
30
|
+
@handler_run_proc = block
|
31
|
+
end
|
32
|
+
|
33
|
+
@app, @router = build_value_app_router(@value)
|
34
|
+
@middleware = @middleware_class.new(@app, @router)
|
35
|
+
end
|
36
|
+
subject{ @middleware }
|
37
|
+
|
38
|
+
should have_imeths :call, :call!
|
39
|
+
|
40
|
+
should "run a handler based on the router's trailing slashes value when called" do
|
41
|
+
subject.call(@env)
|
42
|
+
|
43
|
+
assert_equal [@env], @handler_run_args
|
44
|
+
assert_not_nil @handler_run_proc
|
45
|
+
|
46
|
+
status, headers, body = subject.instance_eval(&@handler_run_proc)
|
47
|
+
assert_equal @app.response.status, status
|
48
|
+
assert_equal @app.response.headers, headers
|
49
|
+
assert_equal [@app.response.body], body
|
50
|
+
end
|
51
|
+
|
52
|
+
should "complain if there is an invalid trailing slashes value set on the router" do
|
53
|
+
app, router = build_value_app_router(nil)
|
54
|
+
|
55
|
+
err = assert_raises(ArgumentError){ @middleware_class.new(app, router) }
|
56
|
+
exp = "TrailingSlashes middleware is in use but there is no "\
|
57
|
+
"trailing slashes router directive set."
|
58
|
+
assert_equal exp, err.message
|
59
|
+
|
60
|
+
invalid_val = ['', 1234, Class.new, Factory.string].sample
|
61
|
+
app, router = build_value_app_router(invalid_val)
|
62
|
+
|
63
|
+
err = assert_raises(ArgumentError){ @middleware_class.new(app, router) }
|
64
|
+
exp = "TrailingSlashes middleware is in use but there is an invalid "\
|
65
|
+
"(`#{invalid_val.inspect}`) trailing slashes router directive set."
|
66
|
+
assert_equal exp, err.message
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def build_value_app_router(value)
|
72
|
+
router = Deas::Router.new
|
73
|
+
router.instance_eval{ @trailing_slashes = value }
|
74
|
+
[Factory.sinatra_call, router]
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
class HandlerSetupTests < UnitTests
|
80
|
+
setup do
|
81
|
+
@no_slash_path = Factory.url
|
82
|
+
@slash_path = @no_slash_path+Deas::Router::SLASH
|
83
|
+
|
84
|
+
@app = Factory.sinatra_call
|
85
|
+
@proc = proc{ @app.call(@env) }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class RequireNoHandlerTests < HandlerSetupTests
|
90
|
+
desc "RequireNoHandler"
|
91
|
+
subject{ RequireNoHandler }
|
92
|
+
|
93
|
+
should have_readers :run
|
94
|
+
|
95
|
+
should "return the apps response if the path info does not end in a slash" do
|
96
|
+
@env['PATH_INFO'] = @no_slash_path
|
97
|
+
|
98
|
+
status, headers, body = subject.run(@env, &@proc)
|
99
|
+
assert_equal @app.response.status, status
|
100
|
+
assert_equal @app.response.headers, headers
|
101
|
+
assert_equal [@app.response.body], body
|
102
|
+
end
|
103
|
+
|
104
|
+
should "redirect without a trailing slash if the path info ends in a slash" do
|
105
|
+
@env['PATH_INFO'] = @slash_path
|
106
|
+
|
107
|
+
status, headers, body = subject.run(@env, &@proc)
|
108
|
+
exp = { 'Location' => @no_slash_path }
|
109
|
+
assert_equal exp, headers
|
110
|
+
assert_equal 302, status
|
111
|
+
assert_equal [''], body
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
class AllowHandlerTests < HandlerSetupTests
|
117
|
+
desc "AllowHandler"
|
118
|
+
subject{ AllowHandler }
|
119
|
+
|
120
|
+
should have_readers :run
|
121
|
+
|
122
|
+
should "return the apps response if no Deas::NotFound error" do
|
123
|
+
paths = [@no_slash_path, @slash_path].shuffle
|
124
|
+
@env['PATH_INFO'] = paths.first
|
125
|
+
|
126
|
+
status, headers, body = subject.run(@env, &@proc)
|
127
|
+
assert_equal @app.response.status, status
|
128
|
+
assert_equal @app.response.headers, headers
|
129
|
+
assert_equal [@app.response.body], body
|
130
|
+
|
131
|
+
# path info not switched and retried b/c there was no Deas::NotFound
|
132
|
+
assert_equal paths.first, @env['PATH_INFO']
|
133
|
+
end
|
134
|
+
|
135
|
+
should "switch the trailing slash and return the apps response if Deas::NotFound error" do
|
136
|
+
paths = [@no_slash_path, @slash_path].shuffle
|
137
|
+
@env['PATH_INFO'] = paths.first
|
138
|
+
@env['deas.error'] = Deas::NotFound.new
|
139
|
+
|
140
|
+
status, headers, body = subject.run(@env, &@proc)
|
141
|
+
assert_equal @app.response.status, status
|
142
|
+
assert_equal @app.response.headers, headers
|
143
|
+
assert_equal [@app.response.body], body
|
144
|
+
|
145
|
+
# path info switched and retried b/c there was no Deas::NotFound
|
146
|
+
assert_equal paths.last, @env['PATH_INFO']
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
data/test/unit/url_tests.rb
CHANGED
@@ -183,12 +183,15 @@ class Deas::Url
|
|
183
183
|
})
|
184
184
|
end
|
185
185
|
|
186
|
-
should "'squash' duplicate forward-slashes" do
|
187
|
-
exp_path = '/a/goose/cooked'
|
186
|
+
should "'squash' duplicate forward-slashes in the path only" do
|
187
|
+
exp_path = '/a/goose/cooked?aye=a&bee=b&u=http://example.com'
|
188
188
|
assert_equal exp_path, subject.path_for({
|
189
189
|
'some' => '/a',
|
190
190
|
:thing => '/goose',
|
191
|
-
'splat' => '///cooked'
|
191
|
+
'splat' => '///cooked',
|
192
|
+
'bee' => 'b',
|
193
|
+
:aye => 'a',
|
194
|
+
'u' => 'http://example.com'
|
192
195
|
})
|
193
196
|
end
|
194
197
|
|
@@ -278,6 +278,15 @@ module Deas::ViewHandler
|
|
278
278
|
assert_nil @meth_block
|
279
279
|
end
|
280
280
|
|
281
|
+
should "call to the runner for its set cookie helper" do
|
282
|
+
capture_runner_meth_args_for(:set_cookie)
|
283
|
+
exp_args = @args
|
284
|
+
subject.instance_eval{ set_cookie(*exp_args) }
|
285
|
+
|
286
|
+
assert_equal exp_args, @meth_args
|
287
|
+
assert_nil @meth_block
|
288
|
+
end
|
289
|
+
|
281
290
|
should "call to the runner for its halt helper" do
|
282
291
|
capture_runner_meth_args_for(:halt)
|
283
292
|
exp_args = @args
|
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.4
|
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-18 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assert
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 2.16.
|
22
|
+
version: 2.16.3
|
23
23
|
type: :development
|
24
24
|
version_requirements: *id001
|
25
25
|
- !ruby/object:Gem::Dependency
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.0.
|
32
|
+
version: 1.0.5
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id002
|
35
35
|
- !ruby/object:Gem::Dependency
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/deas/template_engine.rb
|
101
101
|
- lib/deas/template_source.rb
|
102
102
|
- lib/deas/test_runner.rb
|
103
|
+
- lib/deas/trailing_slashes.rb
|
103
104
|
- lib/deas/url.rb
|
104
105
|
- lib/deas/version.rb
|
105
106
|
- lib/deas/view_handler.rb
|
@@ -145,6 +146,7 @@ files:
|
|
145
146
|
- test/unit/template_engine_tests.rb
|
146
147
|
- test/unit/template_source_tests.rb
|
147
148
|
- test/unit/test_runner_tests.rb
|
149
|
+
- test/unit/trailing_slashes_tests.rb
|
148
150
|
- test/unit/url_tests.rb
|
149
151
|
- test/unit/view_handler_tests.rb
|
150
152
|
- tmp/.gitkeep
|
@@ -216,5 +218,6 @@ test_files:
|
|
216
218
|
- test/unit/template_engine_tests.rb
|
217
219
|
- test/unit/template_source_tests.rb
|
218
220
|
- test/unit/test_runner_tests.rb
|
221
|
+
- test/unit/trailing_slashes_tests.rb
|
219
222
|
- test/unit/url_tests.rb
|
220
223
|
- test/unit/view_handler_tests.rb
|