deas 0.36.0 → 0.37.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,12 @@
1
1
  require 'assert'
2
2
  require 'deas/logging'
3
3
 
4
- require 'test/support/fake_sinatra_call'
5
-
6
4
  module Deas::Logging
7
5
 
8
6
  class UnitTests < Assert::Context
9
7
  desc "Deas::Logging"
10
8
  setup do
11
- @app = FakeSinatraCall.new
9
+ @app = Factory.sinatra_call
12
10
  end
13
11
  subject{ Deas::Logging }
14
12
 
@@ -3,7 +3,6 @@ require 'deas/route'
3
3
 
4
4
  require 'deas/exceptions'
5
5
  require 'deas/route_proxy'
6
- require 'test/support/fake_sinatra_call'
7
6
  require 'test/support/view_handlers'
8
7
 
9
8
  class Deas::Route
@@ -41,21 +40,22 @@ class Deas::Route
41
40
  class RunTests < UnitTests
42
41
  desc "when run"
43
42
  setup do
44
- @fake_sinatra_call = FakeSinatraCall.new
43
+ @server_data = Factory.server_data
44
+ @fake_sinatra_call = Factory.sinatra_call
45
45
  end
46
46
 
47
47
  should "run the proxy for the given request type name" do
48
- Assert.stub(@fake_sinatra_call.settings.router, :request_type_name).with(
48
+ Assert.stub(@server_data.router, :request_type_name).with(
49
49
  @fake_sinatra_call.request
50
50
  ){ @req_type_name }
51
51
 
52
- @route.run(@fake_sinatra_call)
52
+ @route.run(@server_data, @fake_sinatra_call)
53
53
  assert_true @proxy.run_called
54
54
  end
55
55
 
56
56
  should "halt 404 if it can't find a proxy for the given request type name" do
57
57
  halt_value = catch(:halt) do
58
- @route.run(@fake_sinatra_call)
58
+ @route.run(@server_data, @fake_sinatra_call)
59
59
  end
60
60
  assert_equal [404], halt_value
61
61
  end
@@ -64,11 +64,12 @@ class Deas::Route
64
64
 
65
65
  class HandlerProxySpy
66
66
 
67
- attr_reader :validate_called, :run_called, :sinatra_call
67
+ attr_reader :validate_called, :run_called, :server_data, :sinatra_call
68
68
 
69
69
  def initialize
70
70
  @run_called = false
71
71
  @validate_called = false
72
+ @server_data = nil
72
73
  @sinatra_call = nil
73
74
  end
74
75
 
@@ -76,7 +77,8 @@ class Deas::Route
76
77
  @validate_called = true
77
78
  end
78
79
 
79
- def run(sinatra_call)
80
+ def run(server_data, sinatra_call)
81
+ @server_data = sinatra_call
80
82
  @sinatra_call = sinatra_call
81
83
  @run_called = true
82
84
  end
@@ -0,0 +1,43 @@
1
+ require 'assert'
2
+ require 'deas/server_data'
3
+
4
+ class Deas::ServerData
5
+
6
+ class UnitTests < Assert::Context
7
+ desc "Deas::ServerData"
8
+ setup do
9
+ @error_procs = Factory.integer(3).times.map{ proc{} }
10
+ @logger = Factory.string
11
+ @router = Factory.string
12
+ @template_source = Factory.string
13
+
14
+ @server_data = Deas::ServerData.new({
15
+ :error_procs => @error_procs,
16
+ :logger => @logger,
17
+ :router => @router,
18
+ :template_source => @template_source
19
+ })
20
+ end
21
+ subject{ @server_data }
22
+
23
+ should have_readers :error_procs, :logger, :router, :template_source
24
+
25
+ should "know its attributes" do
26
+ assert_equal @error_procs, subject.error_procs
27
+ assert_equal @logger, subject.logger
28
+ assert_equal @router, subject.router
29
+ assert_equal @template_source, subject.template_source
30
+ end
31
+
32
+ should "default its attributes when they aren't provided" do
33
+ server_data = Deas::ServerData.new
34
+
35
+ assert_equal [], server_data.error_procs
36
+ assert_nil server_data.logger
37
+ assert_nil server_data.router
38
+ assert_nil server_data.template_source
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -2,8 +2,11 @@ require 'assert'
2
2
  require 'deas/server'
3
3
 
4
4
  require 'logger'
5
+ require 'deas/exceptions'
6
+ require 'deas/logger'
5
7
  require 'deas/router'
6
8
  require 'deas/template_source'
9
+ require 'test/support/view_handlers'
7
10
 
8
11
  module Deas::Server
9
12
 
@@ -114,4 +117,145 @@ module Deas::Server
114
117
 
115
118
  end
116
119
 
120
+ class ConfigurationTests < UnitTests
121
+ desc "Configuration"
122
+ setup do
123
+ @configuration = Configuration.new
124
+ @configuration.root = TEST_SUPPORT_ROOT
125
+ end
126
+ subject{ @configuration }
127
+
128
+ # sinatra-based options
129
+
130
+ should have_imeths :env, :root, :public_root, :views_root
131
+ should have_imeths :dump_errors, :method_override, :sessions, :show_exceptions
132
+ should have_imeths :static_files, :reload_templates, :default_encoding
133
+
134
+ # server handling options
135
+
136
+ should have_imeths :verbose_logging, :logger, :template_source
137
+
138
+ should have_accessors :settings, :init_procs, :error_procs, :template_helpers
139
+ should have_accessors :middlewares, :router
140
+ should have_imeths :valid?, :validate!, :urls, :routes
141
+ should have_imeths :to_hash
142
+
143
+ should "default the env to 'development'" do
144
+ assert_equal 'development', subject.env
145
+ end
146
+
147
+ should "default the public and views folders based off the root" do
148
+ assert_equal subject.root.join('public'), subject.public_root
149
+ assert_equal subject.root.join('views'), subject.views_root
150
+ end
151
+
152
+ should "default the Sinatra flags" do
153
+ assert_equal false, subject.dump_errors
154
+ assert_equal true, subject.method_override
155
+ assert_equal false, subject.sessions
156
+ assert_equal false, subject.show_exceptions
157
+ assert_equal true, subject.static_files
158
+ assert_equal false, subject.reload_templates
159
+ end
160
+
161
+ should "default the handling options" do
162
+ assert_equal true, subject.verbose_logging
163
+ assert_instance_of Deas::NullLogger, subject.logger
164
+ assert_instance_of Deas::NullTemplateSource, subject.template_source
165
+ end
166
+
167
+ should "default its stored configuration" do
168
+ assert_empty subject.settings
169
+ assert_empty subject.error_procs
170
+ assert_empty subject.init_procs
171
+ assert_empty subject.template_helpers
172
+ assert_empty subject.middlewares
173
+ assert_empty subject.routes
174
+ assert_empty subject.urls
175
+ assert_kind_of Deas::Router, subject.router
176
+ end
177
+
178
+ should "not be valid until validate! has been run" do
179
+ assert_not subject.valid?
180
+
181
+ subject.validate!
182
+ assert subject.valid?
183
+ end
184
+
185
+ should "complain if validating and `root` isn't set" do
186
+ config = Configuration.new
187
+ assert_raises(Deas::ServerRootError){ config.validate! }
188
+ assert_nothing_raised{ config.root '/path/to/root'; config.validate! }
189
+ end
190
+
191
+ should "use `utf-8` as the default encoding by default" do
192
+ assert_equal 'utf-8', subject.default_encoding
193
+ end
194
+
195
+ should "include its error procs and router in its `to_hash`" do
196
+ config_hash = subject.to_hash
197
+
198
+ assert_equal subject.error_procs, config_hash[:error_procs]
199
+ assert_equal subject.router, config_hash[:router]
200
+ end
201
+
202
+ end
203
+
204
+ class ValidationTests < ConfigurationTests
205
+ desc "when successfully validated"
206
+ setup do
207
+ @initialized = false
208
+ @other_initialized = false
209
+ @router = Deas::Router.new
210
+ @route = @router.get('/something', 'EmptyViewHandler')
211
+ @proxy = @route.handler_proxies[@router.default_request_type_name]
212
+
213
+ @configuration = Configuration.new.tap do |c|
214
+ c.env = 'staging'
215
+ c.root = 'path/to/somewhere'
216
+ c.dump_errors = true
217
+ c.method_override = false
218
+ c.sessions = false
219
+ c.show_exceptions = true
220
+ c.static = true
221
+ c.reload_templates = true
222
+ c.middlewares = [ ['MyMiddleware'] ]
223
+ c.router = @router
224
+ end
225
+ @configuration.init_procs << proc{ @initialized = true }
226
+ @configuration.init_procs << proc{ @other_initialized = true }
227
+ end
228
+
229
+ should "call init procs" do
230
+ assert_equal false, @initialized
231
+ assert_equal false, @other_initialized
232
+
233
+ subject.validate!
234
+
235
+ assert_equal true, @initialized
236
+ assert_equal true, @other_initialized
237
+ end
238
+
239
+ should "call validate! on all routes" do
240
+ assert_nil @proxy.handler_class
241
+
242
+ subject.validate!
243
+ assert_equal EmptyViewHandler, @proxy.handler_class
244
+ end
245
+
246
+ should "add the Logging and ShowExceptions middleware to the end" do
247
+ num_middlewares = subject.middlewares.size
248
+ assert subject.verbose_logging
249
+ assert_not_equal [Deas::ShowExceptions], subject.middlewares[-2]
250
+ assert_not_equal [Deas::VerboseLogging], subject.middlewares[-1]
251
+
252
+ subject.validate!
253
+
254
+ assert_equal (num_middlewares+2), subject.middlewares.size
255
+ assert_equal [Deas::ShowExceptions], subject.middlewares[-2]
256
+ assert_equal [Deas::VerboseLogging], subject.middlewares[-1]
257
+ end
258
+
259
+ end
260
+
117
261
  end
@@ -7,6 +7,7 @@ require 'deas/route_proxy'
7
7
  require 'deas/route'
8
8
  require 'deas/router'
9
9
  require 'deas/server'
10
+ require 'deas/server_data'
10
11
  require 'test/support/view_handlers'
11
12
 
12
13
  module Deas::SinatraApp
@@ -44,25 +45,30 @@ module Deas::SinatraApp
44
45
 
45
46
  should "have it's configuration set based on the server configuration" do
46
47
  subject.settings.tap do |settings|
47
- assert_equal 'staging', settings.environment
48
- assert_equal 'path/to/somewhere', settings.root.to_s
49
- assert_equal 'path/to/somewhere/public', settings.public_folder.to_s
50
- assert_equal 'path/to/somewhere/views', settings.views.to_s
51
- assert_equal true, settings.dump_errors
52
- assert_equal false, settings.method_override
53
- assert_equal false, settings.sessions
54
- assert_equal true, settings.static
55
- assert_equal true, settings.reload_templates
56
- assert_equal 'latin1', settings.default_encoding
57
- assert_instance_of Deas::NullLogger, settings.logger
58
- assert_instance_of Deas::Router, settings.router
59
- assert_instance_of Deas::NullTemplateSource, settings.template_source
48
+ assert_equal 'staging', settings.environment
49
+ assert_equal 'path/to/somewhere', settings.root.to_s
50
+ assert_equal 'path/to/somewhere/public', settings.public_folder.to_s
51
+ assert_equal 'path/to/somewhere/views', settings.views.to_s
52
+ assert_equal true, settings.dump_errors
53
+ assert_equal false, settings.method_override
54
+ assert_equal false, settings.sessions
55
+ assert_equal true, settings.static
56
+ assert_equal true, settings.reload_templates
57
+ assert_equal 'latin1', settings.default_encoding
60
58
 
61
59
  # settings that are set but can't be changed
62
60
  assert_equal false, settings.logging
63
61
  assert_equal false, settings.raise_errors
64
62
  assert_equal false, settings.show_exceptions
65
63
 
64
+ exp = Deas::ServerData.new(@configuration.to_hash)
65
+ sd = settings.deas_server_data
66
+ assert_instance_of Deas::ServerData, sd
67
+ assert_instance_of exp.template_source.class, sd.template_source
68
+ assert_instance_of exp.logger.class, sd.logger
69
+ assert_equal exp.error_procs, sd.error_procs
70
+ assert_equal exp.router, sd.router
71
+
66
72
  assert_includes "application/json", settings.add_charset
67
73
  end
68
74
  end
@@ -2,7 +2,6 @@ require 'assert'
2
2
  require 'deas/sinatra_runner'
3
3
 
4
4
  require 'deas/deas_runner'
5
- require 'test/support/fake_sinatra_call'
6
5
  require 'test/support/view_handlers'
7
6
 
8
7
  class Deas::SinatraRunner
@@ -23,7 +22,7 @@ class Deas::SinatraRunner
23
22
  class InitTests < UnitTests
24
23
  desc "when init"
25
24
  setup do
26
- @fake_sinatra_call = FakeSinatraCall.new
25
+ @fake_sinatra_call = Factory.sinatra_call
27
26
  @runner = @runner_class.new(DeasRunnerViewHandler, {
28
27
  :sinatra_call => @fake_sinatra_call
29
28
  })
metadata CHANGED
@@ -1,101 +1,117 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: deas
3
- version: !ruby/object:Gem::Version
4
- version: 0.36.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 139
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 37
9
+ - 0
10
+ version: 0.37.0
5
11
  platform: ruby
6
- authors:
12
+ authors:
7
13
  - Kelly Redding
8
14
  - Collin Redding
9
15
  autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
- date: 2015-08-19 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: ns-options
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '1.1'
18
+
19
+ date: 2015-09-14 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 13
28
+ segments:
29
+ - 1
30
+ - 1
31
+ version: "1.1"
21
32
  - - ">="
22
- - !ruby/object:Gem::Version
33
+ - !ruby/object:Gem::Version
34
+ hash: 27
35
+ segments:
36
+ - 1
37
+ - 1
38
+ - 4
23
39
  version: 1.1.4
24
40
  type: :runtime
41
+ name: ns-options
42
+ version_requirements: *id001
25
43
  prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- requirements:
28
- - - "~>"
29
- - !ruby/object:Gem::Version
30
- version: '1.1'
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.1.4
34
- - !ruby/object:Gem::Dependency
35
- name: rack
36
- requirement: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.5'
44
+ - !ruby/object:Gem::Dependency
45
+ requirement: &id002 !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ~>
49
+ - !ruby/object:Gem::Version
50
+ hash: 5
51
+ segments:
52
+ - 1
53
+ - 5
54
+ version: "1.5"
41
55
  type: :runtime
56
+ name: rack
57
+ version_requirements: *id002
42
58
  prerelease: false
43
- version_requirements: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.5'
48
- - !ruby/object:Gem::Dependency
49
- name: sinatra
50
- requirement: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.4'
59
+ - !ruby/object:Gem::Dependency
60
+ requirement: &id003 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ hash: 7
66
+ segments:
67
+ - 1
68
+ - 4
69
+ version: "1.4"
55
70
  type: :runtime
71
+ name: sinatra
72
+ version_requirements: *id003
56
73
  prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.4'
62
- - !ruby/object:Gem::Dependency
63
- name: assert
64
- requirement: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.15'
74
+ - !ruby/object:Gem::Dependency
75
+ requirement: &id004 !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ hash: 29
81
+ segments:
82
+ - 2
83
+ - 15
84
+ version: "2.15"
69
85
  type: :development
86
+ name: assert
87
+ version_requirements: *id004
70
88
  prerelease: false
71
- version_requirements: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '2.15'
76
- - !ruby/object:Gem::Dependency
77
- name: assert-rack-test
78
- requirement: !ruby/object:Gem::Requirement
79
- requirements:
89
+ - !ruby/object:Gem::Dependency
90
+ requirement: &id005 !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
80
93
  - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
83
99
  type: :development
100
+ name: assert-rack-test
101
+ version_requirements: *id005
84
102
  prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
103
  description: Handler-based web framework powered by Sinatra
91
- email:
104
+ email:
92
105
  - kelly@kellyredding.com
93
106
  - collin.redding@me.com
94
107
  executables: []
108
+
95
109
  extensions: []
110
+
96
111
  extra_rdoc_files: []
97
- files:
98
- - ".gitignore"
112
+
113
+ files:
114
+ - .gitignore
99
115
  - Gemfile
100
116
  - LICENSE.txt
101
117
  - README.md
@@ -115,6 +131,7 @@ files:
115
131
  - lib/deas/router.rb
116
132
  - lib/deas/runner.rb
117
133
  - lib/deas/server.rb
134
+ - lib/deas/server_data.rb
118
135
  - lib/deas/show_exceptions.rb
119
136
  - lib/deas/sinatra_app.rb
120
137
  - lib/deas/sinatra_runner.rb
@@ -148,7 +165,7 @@ files:
148
165
  - test/unit/route_tests.rb
149
166
  - test/unit/router_tests.rb
150
167
  - test/unit/runner_tests.rb
151
- - test/unit/server_configuration_tests.rb
168
+ - test/unit/server_data_tests.rb
152
169
  - test/unit/server_tests.rb
153
170
  - test/unit/show_exceptions_tests.rb
154
171
  - test/unit/sinatra_app_tests.rb
@@ -161,30 +178,39 @@ files:
161
178
  - test/unit/view_handler_tests.rb
162
179
  - tmp/.gitkeep
163
180
  homepage: http://github.com/redding/deas
164
- licenses:
181
+ licenses:
165
182
  - MIT
166
- metadata: {}
167
183
  post_install_message:
168
184
  rdoc_options: []
169
- require_paths:
185
+
186
+ require_paths:
170
187
  - lib
171
- required_ruby_version: !ruby/object:Gem::Requirement
172
- requirements:
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
173
191
  - - ">="
174
- - !ruby/object:Gem::Version
175
- version: '0'
176
- required_rubygems_version: !ruby/object:Gem::Requirement
177
- requirements:
192
+ - !ruby/object:Gem::Version
193
+ hash: 3
194
+ segments:
195
+ - 0
196
+ version: "0"
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ none: false
199
+ requirements:
178
200
  - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
201
+ - !ruby/object:Gem::Version
202
+ hash: 3
203
+ segments:
204
+ - 0
205
+ version: "0"
181
206
  requirements: []
207
+
182
208
  rubyforge_project:
183
- rubygems_version: 2.4.5
209
+ rubygems_version: 1.8.29
184
210
  signing_key:
185
- specification_version: 4
211
+ specification_version: 3
186
212
  summary: Handler-based web framework powered by Sinatra
187
- test_files:
213
+ test_files:
188
214
  - test/helper.rb
189
215
  - test/support/factory.rb
190
216
  - test/support/fake_sinatra_call.rb
@@ -207,7 +233,7 @@ test_files:
207
233
  - test/unit/route_tests.rb
208
234
  - test/unit/router_tests.rb
209
235
  - test/unit/runner_tests.rb
210
- - test/unit/server_configuration_tests.rb
236
+ - test/unit/server_data_tests.rb
211
237
  - test/unit/server_tests.rb
212
238
  - test/unit/show_exceptions_tests.rb
213
239
  - test/unit/sinatra_app_tests.rb