deas 0.40.0 → 0.41.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.
@@ -19,58 +19,53 @@ module Deas::SinatraApp
19
19
  @router.get('/something', 'EmptyViewHandler')
20
20
  @router.validate!
21
21
 
22
- @configuration = Deas::Server::Configuration.new.tap do |c|
23
- c.env = 'staging'
24
- c.root = 'path/to/somewhere'
25
- c.dump_errors = true
26
- c.method_override = false
27
- c.sessions = false
28
- c.show_exceptions = true
29
- c.static = true
30
- c.reload_templates = true
31
- c.default_encoding = 'latin1'
32
- c.router = @router
33
- end
34
- @sinatra_app = Deas::SinatraApp.new(@configuration)
22
+ @config = Deas::Server::Config.new
23
+ @config.router = @router
24
+
25
+ @sinatra_app = Deas::SinatraApp.new(@config)
35
26
  end
36
27
  subject{ @sinatra_app }
37
28
 
38
29
  should "ensure its config is valid" do
39
- assert @configuration.valid?
30
+ assert @config.valid?
40
31
  end
41
32
 
42
33
  should "be a kind of Sinatra::Base" do
43
34
  assert_equal Sinatra::Base, subject.superclass
44
35
  end
45
36
 
46
- should "have it's configuration set based on the server configuration" do
47
- subject.settings.tap do |settings|
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
58
-
59
- # settings that are set but can't be changed
60
- assert_equal false, settings.logging
61
- assert_equal false, settings.raise_errors
62
- assert_equal false, settings.show_exceptions
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
-
72
- assert_includes "application/json", settings.add_charset
73
- end
37
+ should "have it's configuration set based on the server config" do
38
+ s = subject.settings
39
+
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
54
+
55
+ exp = Deas::ServerData.new({
56
+ :error_procs => @config.error_procs,
57
+ :logger => @config.logger,
58
+ :router => @config.router,
59
+ :template_source => @config.template_source
60
+ })
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
74
69
  end
75
70
 
76
71
  should "define Sinatra routes for every route in the configuration" do
@@ -86,13 +86,13 @@ class Deas::TemplateEngine
86
86
  end
87
87
 
88
88
  should "read and return the given path in its source path on `render`" do
89
- template = ['test/support/template.a', 'test/support/template.a.json'].choice
89
+ template = ['test/support/template.a', 'test/support/template.a.json'].sample
90
90
  exp = File.read(Dir.glob(subject.source_path.join("#{template}*")).first)
91
91
  assert_equal exp, subject.render(template, @v, @l)
92
92
  end
93
93
 
94
94
  should "call `render` to implement its `partial` method" do
95
- template = ['test/support/template.a', 'test/support/template.a.json'].choice
95
+ template = ['test/support/template.a', 'test/support/template.a.json'].sample
96
96
  exp = subject.render(template, nil, @l)
97
97
  assert_equal exp, subject.partial(template, @l)
98
98
  end
@@ -191,6 +191,12 @@ class Deas::TemplateSource
191
191
  assert_equal '', subject.path
192
192
  end
193
193
 
194
+ should "optionally take a root path" do
195
+ exp = Factory.path
196
+ source = Deas::NullTemplateSource.new(exp)
197
+ assert_equal exp, source.path
198
+ end
199
+
194
200
  end
195
201
 
196
202
  class TestEngine < Deas::TemplateEngine
@@ -87,6 +87,32 @@ class Deas::Url
87
87
  })
88
88
  end
89
89
 
90
+ should "complain if given an empty named param value" do
91
+ params = {
92
+ 'some' => 'a',
93
+ :thing => 'goose'
94
+ }
95
+ empty_param_name = params.keys.sample
96
+ empty_param_value = [nil, ''].sample
97
+ params[empty_param_name] = empty_param_value
98
+
99
+ err = assert_raises EmptyNamedValueError do
100
+ subject.path_for(params)
101
+ end
102
+ exp = "an empty value (`#{empty_param_value.inspect}`) "\
103
+ "was given for the `#{empty_param_name}` url param"
104
+ assert_equal exp, err.message
105
+ end
106
+
107
+ should "not complain if given empty splat param values" do
108
+ exp_path = "/a/goose/"
109
+ assert_equal exp_path, subject.path_for({
110
+ 'some' => 'a',
111
+ :thing => 'goose',
112
+ 'splat' => [nil, '']
113
+ })
114
+ end
115
+
90
116
  should "append other (additional) params as query params" do
91
117
  exp_path = "/a/goose/cooked/well?aye=a&bee=b"
92
118
  assert_equal exp_path, subject.path_for({
@@ -154,38 +180,6 @@ class Deas::Url
154
180
  })
155
181
  end
156
182
 
157
- should "generate given ordered params only" do
158
- exp_path = "/a/:thing/*/*"
159
- assert_equal exp_path, subject.path_for('a')
160
-
161
- exp_path = "/a/goose/*/*"
162
- assert_equal exp_path, subject.path_for('a', 'goose')
163
-
164
- exp_path = "/a/goose/cooked-well/*"
165
- assert_equal exp_path, subject.path_for('a', 'goose', 'cooked-well')
166
-
167
- exp_path = "/a/goose/cooked/well"
168
- assert_equal exp_path, subject.path_for('a', 'goose', 'cooked', 'well')
169
- end
170
-
171
- should "generate given mixed ordered and named params" do
172
- exp_path = "/:some/:thing/*/*"
173
- assert_equal exp_path, subject.path_for
174
-
175
- exp_path = "/a/goose/*/*"
176
- assert_equal exp_path, subject.path_for('a', 'thing' => 'goose')
177
-
178
- exp_path = "/goose/a/well/*"
179
- assert_equal exp_path, subject.path_for('a', 'well', 'some' => 'goose')
180
-
181
- exp_path = "/a/goose/cooked/well"
182
- assert_equal exp_path, subject.path_for('ignore', 'these', 'params', {
183
- 'some' => 'a',
184
- :thing => 'goose',
185
- 'splat' => ['cooked', 'well']
186
- })
187
- end
188
-
189
183
  should "'squash' duplicate forward-slashes" do
190
184
  exp_path = "/a/goose/cooked/well/"
191
185
  assert_equal exp_path, subject.path_for({
@@ -198,8 +192,8 @@ class Deas::Url
198
192
  should "not alter the given params" do
199
193
  params = {
200
194
  'some' => 'thing',
201
- :captures => 'captures',
202
- :splat => 'splat',
195
+ :captures => ['captures'],
196
+ :splat => ['splat'],
203
197
  '#' => 'anchor'
204
198
  }
205
199
  exp_params = params.dup
@@ -208,6 +202,12 @@ class Deas::Url
208
202
  assert_equal exp_params, params
209
203
  end
210
204
 
205
+ should "complain if given non-hash params" do
206
+ assert_raises NonHashParamsError do
207
+ subject.path_for([Factory.string, Factory.integer, nil].sample)
208
+ end
209
+ end
210
+
211
211
  end
212
212
 
213
213
  end
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.40.0
4
+ version: 0.41.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-04-11 00:00:00 Z
13
+ date: 2016-06-15 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.15.1
22
+ version: 2.16.1
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.3
32
+ version: 1.0.4
33
33
  type: :development
34
34
  version_requirements: *id002
35
35
  - !ruby/object:Gem::Dependency
@@ -39,39 +39,29 @@ dependencies:
39
39
  requirements:
40
40
  - - ~>
41
41
  - !ruby/object:Gem::Version
42
- version: 0.1.0
42
+ version: 0.2.0
43
43
  type: :runtime
44
44
  version_requirements: *id003
45
- - !ruby/object:Gem::Dependency
46
- name: ns-options
47
- prerelease: false
48
- requirement: &id004 !ruby/object:Gem::Requirement
49
- requirements:
50
- - - ~>
51
- - !ruby/object:Gem::Version
52
- version: 1.1.6
53
- type: :runtime
54
- version_requirements: *id004
55
45
  - !ruby/object:Gem::Dependency
56
46
  name: rack
57
47
  prerelease: false
58
- requirement: &id005 !ruby/object:Gem::Requirement
48
+ requirement: &id004 !ruby/object:Gem::Requirement
59
49
  requirements:
60
50
  - - ~>
61
51
  - !ruby/object:Gem::Version
62
52
  version: "1.1"
63
53
  type: :runtime
64
- version_requirements: *id005
54
+ version_requirements: *id004
65
55
  - !ruby/object:Gem::Dependency
66
56
  name: sinatra
67
57
  prerelease: false
68
- requirement: &id006 !ruby/object:Gem::Requirement
58
+ requirement: &id005 !ruby/object:Gem::Requirement
69
59
  requirements:
70
60
  - - ~>
71
61
  - !ruby/object:Gem::Version
72
62
  version: "1.2"
73
63
  type: :runtime
74
- version_requirements: *id006
64
+ version_requirements: *id005
75
65
  description: Handler-based web framework powered by Sinatra
76
66
  email:
77
67
  - kelly@kellyredding.com
@@ -167,17 +157,17 @@ require_paths:
167
157
  - lib
168
158
  required_ruby_version: !ruby/object:Gem::Requirement
169
159
  requirements:
170
- - &id007
160
+ - &id006
171
161
  - ">="
172
162
  - !ruby/object:Gem::Version
173
163
  version: "0"
174
164
  required_rubygems_version: !ruby/object:Gem::Requirement
175
165
  requirements:
176
- - *id007
166
+ - *id006
177
167
  requirements: []
178
168
 
179
169
  rubyforge_project:
180
- rubygems_version: 2.5.1
170
+ rubygems_version: 2.6.4
181
171
  signing_key:
182
172
  specification_version: 4
183
173
  summary: Handler-based web framework powered by Sinatra