deas 0.42.0 → 0.43.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.
@@ -30,7 +30,7 @@ class Deas::ServerData
30
30
  end
31
31
 
32
32
  should "default its attributes when they aren't provided" do
33
- server_data = Deas::ServerData.new
33
+ server_data = Deas::ServerData.new({})
34
34
 
35
35
  assert_equal [], server_data.error_procs
36
36
  assert_nil server_data.logger
@@ -38,6 +38,19 @@ class Deas::ServerData
38
38
  assert_nil server_data.template_source
39
39
  end
40
40
 
41
+ should "know if it is equal to another server data" do
42
+ server_data = Deas::ServerData.new({
43
+ :error_procs => @error_procs,
44
+ :logger => @logger,
45
+ :router => @router,
46
+ :template_source => @template_source
47
+ })
48
+ assert_equal server_data, subject
49
+
50
+ server_data = Deas::ServerData.new({})
51
+ assert_not_equal server_data, subject
52
+ end
53
+
41
54
  end
42
55
 
43
56
  end
@@ -20,16 +20,12 @@ module Deas::Server
20
20
 
21
21
  should have_imeths :new, :config
22
22
 
23
- should have_imeths :env, :root, :views_path, :views_root
24
- should have_imeths :public_path, :public_root, :default_encoding
25
- should have_imeths :set, :settings, :template_helpers, :template_helper?
26
- should have_imeths :use, :middlewares, :init, :init_procs, :error, :error_procs
23
+ should have_imeths :env, :root
24
+ should have_imeths :method_override, :show_exceptions, :verbose_logging
25
+ should have_imeths :use, :middlewares
26
+ should have_imeths :init, :init_procs, :error, :error_procs
27
27
  should have_imeths :template_source, :logger, :router, :url_for
28
28
 
29
- should have_imeths :dump_errors, :method_override, :reload_templates
30
- should have_imeths :sessions, :show_exceptions, :static_files
31
- should have_imeths :verbose_logging
32
-
33
29
  should "use much-plugin" do
34
30
  assert_includes MuchPlugin, Deas::Server
35
31
  end
@@ -45,21 +41,17 @@ module Deas::Server
45
41
  subject.root exp
46
42
  assert_equal exp, config.root
47
43
 
48
- exp = Factory.path
49
- subject.views_path exp
50
- assert_equal exp, config.views_path
51
-
52
- exp = Factory.path
53
- subject.public_path exp
54
- assert_equal exp, config.public_path
44
+ exp = Factory.boolean
45
+ subject.method_override exp
46
+ assert_equal exp, config.method_override
55
47
 
56
- exp = Factory.string
57
- subject.default_encoding exp
58
- assert_equal exp, config.default_encoding
48
+ exp = Factory.boolean
49
+ subject.show_exceptions exp
50
+ assert_equal exp, config.show_exceptions
59
51
 
60
- exp = { Factory.string.to_sym => Factory.string }
61
- subject.set exp.keys.first, exp.values.first
62
- assert_equal exp, config.settings
52
+ exp = Factory.boolean
53
+ subject.verbose_logging exp
54
+ assert_equal exp, config.verbose_logging
63
55
 
64
56
  exp = ['MyMiddleware', Factory.string]
65
57
  subject.use *exp
@@ -84,50 +76,14 @@ module Deas::Server
84
76
  exp = Logger.new(STDOUT)
85
77
  subject.logger exp
86
78
  assert_equal exp, config.logger
87
-
88
- exp = Factory.boolean
89
- subject.dump_errors exp
90
- assert_equal exp, config.dump_errors
91
-
92
- exp = Factory.boolean
93
- subject.method_override exp
94
- assert_equal exp, config.method_override
95
-
96
- exp = Factory.boolean
97
- subject.reload_templates exp
98
- assert_equal exp, config.reload_templates
99
-
100
- exp = Factory.boolean
101
- subject.sessions exp
102
- assert_equal exp, config.sessions
103
-
104
- exp = Factory.boolean
105
- subject.show_exceptions exp
106
- assert_equal exp, config.show_exceptions
107
-
108
- exp = Factory.boolean
109
- subject.static_files exp
110
- assert_equal exp, config.static_files
111
-
112
- exp = Factory.boolean
113
- subject.verbose_logging exp
114
- assert_equal exp, config.verbose_logging
115
79
  end
116
80
 
117
- should "demeter its config values that aren't directly set" do
118
- assert_equal subject.config.views_root, subject.views_root
119
- assert_equal subject.config.public_root, subject.public_root
120
- assert_equal subject.config.settings, subject.settings
81
+ should "demeter its config values that aren't set directly" do
121
82
  assert_equal subject.config.middlewares, subject.middlewares
122
83
  assert_equal subject.config.init_procs, subject.init_procs
123
84
  assert_equal subject.config.error_procs, subject.error_procs
124
85
  end
125
86
 
126
- should "add and query helper modules" do
127
- subject.template_helpers(helper_module = Module.new)
128
- assert_true subject.template_helper?(helper_module)
129
- end
130
-
131
87
  should "have a router by default and allow overriding it" do
132
88
  assert_kind_of Deas::Router, subject.router
133
89
 
@@ -168,22 +124,16 @@ module Deas::Server
168
124
  end
169
125
  subject{ @config }
170
126
 
171
- should have_accessors :env, :root, :views_path, :public_path, :default_encoding
172
- should have_accessors :settings, :template_helpers, :middlewares
173
- should have_accessors :init_procs, :error_procs, :template_source, :logger, :router
127
+ should have_accessors :env, :root
128
+ should have_accessors :method_override, :show_exceptions, :verbose_logging
129
+ should have_accessors :middlewares, :init_procs, :error_procs
130
+ should have_accessors :template_source, :logger, :router
174
131
 
175
- should have_accessors :dump_errors, :method_override, :reload_templates
176
- should have_accessors :sessions, :show_exceptions, :static_files
177
- should have_accessors :verbose_logging
178
-
179
- should have_imeths :views_root, :public_root, :urls, :routes
132
+ should have_imeths :urls, :routes
180
133
  should have_imeths :valid?, :validate!
181
134
 
182
- should "know its default attr values" do
135
+ should "know its default env" do
183
136
  assert_equal 'development', @config_class::DEFAULT_ENV
184
- assert_equal 'views', @config_class::DEFAULT_VIEWS_PATH
185
- assert_equal 'public', @config_class::DEFAULT_PUBLIC_PATH
186
- assert_equal 'utf-8', @config_class::DEFAULT_ENCODING
187
137
  end
188
138
 
189
139
  should "default its attrs" do
@@ -193,42 +143,19 @@ module Deas::Server
193
143
  exp = ENV['PWD']
194
144
  assert_equal exp, subject.root
195
145
 
196
- exp = @config_class::DEFAULT_VIEWS_PATH
197
- assert_equal exp, subject.views_path
198
-
199
- exp = @config_class::DEFAULT_PUBLIC_PATH
200
- assert_equal exp, subject.public_path
201
-
202
- exp = @config_class::DEFAULT_ENCODING
203
- assert_equal exp, subject.default_encoding
146
+ assert_equal true, subject.method_override
147
+ assert_equal false, subject.show_exceptions
148
+ assert_equal true, subject.verbose_logging
204
149
 
205
- assert_equal Hash.new, subject.settings
206
- assert_equal [], subject.template_helpers
207
- assert_equal [], subject.middlewares
208
- assert_equal [], subject.init_procs
209
- assert_equal [], subject.error_procs
150
+ assert_equal [], subject.middlewares
151
+ assert_equal [], subject.init_procs
152
+ assert_equal [], subject.error_procs
210
153
 
211
154
  assert_instance_of Deas::NullTemplateSource, subject.template_source
212
155
  assert_equal subject.root, subject.template_source.path
213
156
 
214
157
  assert_instance_of Deas::NullLogger, subject.logger
215
158
  assert_instance_of Deas::Router, subject.router
216
-
217
- assert_equal false, subject.dump_errors
218
- assert_equal true, subject.method_override
219
- assert_equal false, subject.reload_templates
220
- assert_equal false, subject.sessions
221
- assert_equal false, subject.show_exceptions
222
- assert_equal true, subject.static_files
223
- assert_equal true, subject.verbose_logging
224
- end
225
-
226
- should "know its views root and public root" do
227
- exp = File.expand_path(subject.views_path.to_s, subject.root.to_s)
228
- assert_equal exp, subject.views_root
229
-
230
- exp = File.expand_path(subject.public_path.to_s, subject.root.to_s)
231
- assert_equal exp, subject.public_root
232
159
  end
233
160
 
234
161
  should "demeter its router" do
@@ -259,11 +186,12 @@ module Deas::Server
259
186
  Assert.stub(@router, :validate!){ @router_validate_called = true }
260
187
 
261
188
  @config = Config.new.tap do |c|
262
- c.root = Factory.path
263
- c.show_exceptions = true
264
- c.verbose_logging = true
265
- c.middlewares = Factory.integer(3).times.map{ [Factory.string] }
266
- c.router = @router
189
+ c.root = Factory.path
190
+ c.method_override = true
191
+ c.show_exceptions = true
192
+ c.verbose_logging = true
193
+ c.middlewares = Factory.integer(3).times.map{ [Factory.string] }
194
+ c.router = @router
267
195
  end
268
196
 
269
197
  @initialized = false
@@ -290,19 +218,26 @@ module Deas::Server
290
218
  assert_true @router_validate_called
291
219
  end
292
220
 
293
- should "add the Logging and ShowExceptions middleware to the end" do
221
+ should "prepend and append middleware based" do
222
+ assert_true subject.method_override
294
223
  assert_true subject.show_exceptions
295
224
  assert_true subject.verbose_logging
296
225
 
297
226
  num_middlewares = subject.middlewares.size
227
+ assert_not_equal [Rack::MethodOverride], subject.middlewares[0]
298
228
  assert_not_equal [Deas::ShowExceptions], subject.middlewares[-2]
299
229
  assert_not_equal [Deas::VerboseLogging], subject.middlewares[-1]
300
230
 
301
231
  subject.validate!
302
232
 
303
- assert_equal (num_middlewares+2), subject.middlewares.size
233
+ assert_equal (num_middlewares+3), subject.middlewares.size
234
+ assert_equal [Rack::MethodOverride], subject.middlewares[0]
304
235
  assert_equal [Deas::ShowExceptions], subject.middlewares[-2]
305
236
  assert_equal [Deas::VerboseLogging], subject.middlewares[-1]
237
+
238
+ assert_raises do
239
+ subject.middlewares << [Factory.string]
240
+ end
306
241
  end
307
242
 
308
243
  should "only be able to be validated once" do
@@ -14,6 +14,23 @@ module Deas::SinatraApp
14
14
 
15
15
  class UnitTests < Assert::Context
16
16
  desc "Deas::SinatraApp"
17
+ subject{ Deas::SinatraApp }
18
+
19
+ should have_imeths :new
20
+
21
+ should "know its default error response status" do
22
+ assert_equal 500, subject::DEFAULT_ERROR_RESPONSE_STATUS
23
+ end
24
+
25
+ should "know its standard error classes" do
26
+ exp = [StandardError, LoadError, NotImplementedError, Timeout::Error]
27
+ assert_equal exp, subject::STANDARD_ERROR_CLASSES
28
+ end
29
+
30
+ end
31
+
32
+ class InitTests < UnitTests
33
+ desc "when init"
17
34
  setup do
18
35
  @router = Deas::Router.new
19
36
  @router.get('/something', 'EmptyViewHandler')
@@ -30,27 +47,15 @@ module Deas::SinatraApp
30
47
  assert @config.valid?
31
48
  end
32
49
 
33
- should "be a kind of Sinatra::Base" do
50
+ should "be a kind of Sinatra::Base app" do
34
51
  assert_equal Sinatra::Base, subject.superclass
35
52
  end
36
53
 
37
- should "have it's configuration set based on the server config" do
54
+ should "have it's configuration set based on the server config or defaults" do
38
55
  s = subject.settings
39
56
 
40
- assert_equal @config.env, s.environment
41
- assert_equal @config.root, s.root
42
- assert_equal @config.views_root, s.views
43
- assert_equal @config.public_root, s.public_folder
44
- assert_equal @config.default_encoding, s.default_encoding
45
- assert_equal @config.dump_errors, s.dump_errors
46
- assert_equal @config.method_override, s.method_override
47
- assert_equal @config.reload_templates, s.reload_templates
48
- assert_equal @config.sessions, s.sessions
49
- assert_equal @config.static_files, s.static
50
-
51
- assert_equal false, s.raise_errors
52
- assert_equal false, s.show_exceptions
53
- assert_equal false, s.logging
57
+ assert_equal @config.env, s.environment
58
+ assert_equal @config.root, s.root
54
59
 
55
60
  exp = Deas::ServerData.new({
56
61
  :error_procs => @config.error_procs,
@@ -58,14 +63,21 @@ module Deas::SinatraApp
58
63
  :router => @config.router,
59
64
  :template_source => @config.template_source
60
65
  })
61
- sd = s.deas_server_data
62
- assert_instance_of Deas::ServerData, sd
63
- assert_instance_of exp.template_source.class, sd.template_source
64
- assert_instance_of exp.logger.class, sd.logger
65
- assert_equal exp.error_procs, sd.error_procs
66
- assert_equal exp.router, sd.router
67
-
68
- assert_includes "application/json", s.add_charset
66
+ assert_equal exp, s.deas_server_data
67
+
68
+ assert_equal @config.root, s.views
69
+ assert_equal @config.root, s.public_folder
70
+ assert_equal 'utf-8', s.default_encoding
71
+
72
+ assert_false s.method_override
73
+ assert_false s.reload_templates
74
+ assert_false s.static
75
+ assert_false s.sessions
76
+ assert_false s.protection
77
+ assert_false s.raise_errors
78
+ assert_false s.show_exceptions
79
+ assert_false s.dump_errors
80
+ assert_false s.logging
69
81
  end
70
82
 
71
83
  should "define Sinatra routes for every route in the configuration" do
@@ -75,6 +87,8 @@ module Deas::SinatraApp
75
87
  assert_not_nil sinatra_routes.detect{ |r| r[0].match(router_route.path) }
76
88
  end
77
89
 
90
+ # System tests ensure that routes get applied to the sinatra app correctly.
91
+
78
92
  end
79
93
 
80
94
  end
@@ -33,8 +33,8 @@ class Deas::TestRunner
33
33
  :router => Factory.string,
34
34
  :template_source => Factory.string,
35
35
  :request => @request,
36
- :session => Factory.string,
37
36
  :params => @params,
37
+ :route_path => Factory.string,
38
38
  :splat => Factory.path,
39
39
  :custom_value => Factory.integer
40
40
  }
@@ -49,7 +49,7 @@ class Deas::TestRunner
49
49
  subject{ @runner }
50
50
 
51
51
  should have_readers :content_type_args
52
- should have_imeths :halted?, :run
52
+ should have_imeths :splat, :halted?, :run
53
53
 
54
54
  should "raise an invalid error when passed a non view handler" do
55
55
  assert_raises(Deas::InvalidViewHandlerError) do
@@ -62,9 +62,12 @@ 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[:session], subject.session
66
65
  assert_equal @args[:params], subject.params
67
- assert_equal @args[:splat], subject.splat
66
+ assert_equal @args[:route_path], subject.route_path
67
+ end
68
+
69
+ should "know its splat value" do
70
+ assert_equal @args[:splat], subject.splat
68
71
  end
69
72
 
70
73
  should "call to normalize its params" do
@@ -87,6 +87,17 @@ class Deas::Url
87
87
  })
88
88
  end
89
89
 
90
+ should "apply composed named params" do
91
+ url = Deas::Url.new(:some_thing, '/:some/:something/:something_else')
92
+
93
+ exp_path = '/a/goose/cooked'
94
+ assert_equal exp_path, url.path_for({
95
+ 'some' => 'a',
96
+ :something => 'goose',
97
+ 'something_else' => 'cooked'
98
+ })
99
+ end
100
+
90
101
  should "complain if given an empty named param value" do
91
102
  params = {
92
103
  'some' => 'a',
@@ -99,8 +110,8 @@ class Deas::Url
99
110
  err = assert_raises EmptyNamedValueError do
100
111
  subject.path_for(params)
101
112
  end
102
- exp = "an empty value (`#{empty_param_value.inspect}`) "\
103
- "was given for the `#{empty_param_name}` url param"
113
+ exp = "an empty value, `#{empty_param_value.inspect}`, "\
114
+ "was given for the `#{empty_param_name.inspect}` url param"
104
115
  assert_equal exp, err.message
105
116
  end
106
117
 
@@ -232,11 +232,6 @@ module Deas::ViewHandler
232
232
  assert_equal @runner.request, subject.instance_eval{ request }
233
233
  end
234
234
 
235
- should "call to the runner for its session" do
236
- stub_runner_with_something_for(:session)
237
- assert_equal @runner.session, subject.instance_eval{ session }
238
- end
239
-
240
235
  should "call to the runner for its params" do
241
236
  stub_runner_with_something_for(:params)
242
237
  assert_equal @runner.params, subject.instance_eval{ params }
@@ -391,8 +386,7 @@ module Deas::ViewHandler
391
386
  runner = subject.test_runner(@handler_class)
392
387
 
393
388
  assert_kind_of ::Deas::TestRunner, runner
394
- assert_kind_of Rack::Request, runner.request
395
- assert_equal runner.request.session, runner.session
389
+ assert_kind_of ::Rack::Request, runner.request
396
390
  end
397
391
 
398
392
  should "return an initialized handler instance" do
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.42.0
4
+ version: 0.43.0
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: 2016-09-01 00:00:00 Z
13
+ date: 2016-09-14 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: assert
@@ -49,7 +49,7 @@ dependencies:
49
49
  requirements:
50
50
  - - ~>
51
51
  - !ruby/object:Gem::Version
52
- version: "1.1"
52
+ version: 1.6.4
53
53
  type: :runtime
54
54
  version_requirements: *id004
55
55
  - !ruby/object:Gem::Dependency
@@ -87,6 +87,7 @@ files:
87
87
  - lib/deas/logging.rb
88
88
  - lib/deas/rack_request_fix.rb
89
89
  - lib/deas/redirect_proxy.rb
90
+ - lib/deas/request_data.rb
90
91
  - lib/deas/respond_with_proxy.rb
91
92
  - lib/deas/route.rb
92
93
  - lib/deas/route_proxy.rb
@@ -107,6 +108,7 @@ files:
107
108
  - test/support/empty_view_handler.rb
108
109
  - test/support/factory.rb
109
110
  - test/support/fake_request.rb
111
+ - test/support/fake_response.rb
110
112
  - test/support/fake_sinatra_call.rb
111
113
  - test/support/file1.txt
112
114
  - test/support/file2.txt
@@ -130,6 +132,7 @@ files:
130
132
  - test/unit/handler_proxy_tests.rb
131
133
  - test/unit/logging_tests.rb
132
134
  - test/unit/redirect_proxy_tests.rb
135
+ - test/unit/request_data_tests.rb
133
136
  - test/unit/respond_with_proxy_tests.rb
134
137
  - test/unit/route_proxy_tests.rb
135
138
  - test/unit/route_tests.rb
@@ -176,6 +179,7 @@ test_files:
176
179
  - test/support/empty_view_handler.rb
177
180
  - test/support/factory.rb
178
181
  - test/support/fake_request.rb
182
+ - test/support/fake_response.rb
179
183
  - test/support/fake_sinatra_call.rb
180
184
  - test/support/file1.txt
181
185
  - test/support/file2.txt
@@ -199,6 +203,7 @@ test_files:
199
203
  - test/unit/handler_proxy_tests.rb
200
204
  - test/unit/logging_tests.rb
201
205
  - test/unit/redirect_proxy_tests.rb
206
+ - test/unit/request_data_tests.rb
202
207
  - test/unit/respond_with_proxy_tests.rb
203
208
  - test/unit/route_proxy_tests.rb
204
209
  - test/unit/route_tests.rb