deas 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ require 'deas/redirect_proxy'
2
+ require 'deas/route_proxy'
3
+ require 'deas/route'
4
+ require 'deas/url'
5
+
6
+ module Deas
7
+ class Router
8
+
9
+ attr_accessor :urls, :routes
10
+
11
+ def initialize
12
+ @urls, @routes = {}, []
13
+ end
14
+
15
+ def view_handler_ns(value = nil)
16
+ @view_handler_ns = value if !value.nil?
17
+ @view_handler_ns
18
+ end
19
+
20
+ def url(name, path)
21
+ if !path.kind_of?(::String)
22
+ raise ArgumentError, "invalid path `#{path.inspect}` - "\
23
+ "can only provide a url name with String paths"
24
+ end
25
+ add_url(name.to_sym, path)
26
+ end
27
+
28
+ def url_for(name, *args)
29
+ url = self.urls[name.to_sym]
30
+ raise ArgumentError, "no route named `#{name.to_sym.inspect}`" unless url
31
+
32
+ url.path_for(*args)
33
+ end
34
+
35
+ def get(path, handler_name); self.route(:get, path, handler_name); end
36
+ def post(path, handler_name); self.route(:post, path, handler_name); end
37
+ def put(path, handler_name); self.route(:put, path, handler_name); end
38
+ def patch(path, handler_name); self.route(:patch, path, handler_name); end
39
+ def delete(path, handler_name); self.route(:delete, path, handler_name); end
40
+
41
+ def route(http_method, from_path, handler_class_name)
42
+ if self.view_handler_ns && !(handler_class_name =~ /^::/)
43
+ handler_class_name = "#{self.view_handler_ns}::#{handler_class_name}"
44
+ end
45
+ proxy = Deas::RouteProxy.new(handler_class_name)
46
+
47
+ from_url = self.urls[from_path]
48
+ from_url_path = from_url.path if from_url
49
+ add_route(http_method, from_url_path || from_path, proxy)
50
+ end
51
+
52
+ def redirect(from_path, to_path = nil, &block)
53
+ to_url = self.urls[to_path]
54
+ if to_path.kind_of?(::Symbol) && to_url.nil?
55
+ raise ArgumentError, "no url named `#{to_path.inspect}`"
56
+ end
57
+ proxy = Deas::RedirectProxy.new(to_url || to_path, &block)
58
+
59
+ from_url = self.urls[from_path]
60
+ from_url_path = from_url.path if from_url
61
+ add_route(:get, from_url_path || from_path, proxy)
62
+ end
63
+
64
+ private
65
+
66
+ def add_url(name, path)
67
+ self.urls[name] = Deas::Url.new(name, path)
68
+ end
69
+
70
+ def add_route(http_method, path, proxy)
71
+ Deas::Route.new(http_method, path, proxy).tap{ |r| self.routes.push(r) }
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
data/lib/deas/server.rb CHANGED
@@ -1,15 +1,11 @@
1
1
  require 'pathname'
2
- require 'set'
3
2
  require 'ns-options'
4
3
  require 'ns-options/boolean'
5
4
  require 'deas/exceptions'
6
5
  require 'deas/template'
7
6
  require 'deas/logging'
8
- require 'deas/redirect_proxy'
9
- require 'deas/route_proxy'
10
- require 'deas/route'
11
- require 'deas/url'
12
7
  require 'deas/show_exceptions'
8
+ require 'deas/router'
13
9
  require 'deas/sinatra_app'
14
10
 
15
11
  module Deas; end
@@ -36,12 +32,11 @@ module Deas::Server
36
32
 
37
33
  # server handling options
38
34
 
39
- option :logger, :default => proc{ Deas::NullLogger.new }
40
35
  option :verbose_logging, NsOptions::Boolean, :default => true
41
- option :view_handler_ns, String
36
+ option :logger, :default => proc{ Deas::NullLogger.new }
42
37
 
43
38
  attr_accessor :settings, :error_procs, :init_procs, :template_helpers
44
- attr_accessor :middlewares, :routes, :urls
39
+ attr_accessor :middlewares, :router
45
40
 
46
41
  def initialize(values=nil)
47
42
  # these are defaulted here because we want to use the Configuration
@@ -52,9 +47,9 @@ module Deas::Server
52
47
  :public_folder => proc{ self.root.join('public') },
53
48
  :views_folder => proc{ self.root.join('views') }
54
49
  }))
55
- @settings, @urls = {}, {}
56
- @error_procs, @init_procs, @template_helpers = [], [], []
57
- @middlewares, @routes = [], []
50
+ @settings = {}
51
+ @error_procs, @init_procs, @template_helpers, @middlewares = [], [], [], []
52
+ @router = Deas::Router.new
58
53
  @valid = nil
59
54
  end
60
55
 
@@ -92,18 +87,18 @@ module Deas::Server
92
87
  @valid = true # if it made it this far, its valid!
93
88
  end
94
89
 
95
- def template_scope
96
- Class.new(Deas::Template::Scope).tap do |klass|
97
- klass.send(:include, *self.template_helpers)
98
- end
90
+ def urls
91
+ self.router.urls
99
92
  end
100
93
 
101
- def add_route(http_method, path, proxy)
102
- Deas::Route.new(http_method, path, proxy).tap{ |r| self.routes.push(r) }
94
+ def routes
95
+ self.router.routes
103
96
  end
104
97
 
105
- def add_url(name, path)
106
- self.urls[name] = Deas::Url.new(name, path)
98
+ def template_scope
99
+ Class.new(Deas::Template::Scope).tap do |klass|
100
+ klass.send(:include, *self.template_helpers)
101
+ end
107
102
  end
108
103
 
109
104
  end
@@ -191,10 +186,6 @@ module Deas::Server
191
186
  self.configuration.settings[name.to_sym] = value
192
187
  end
193
188
 
194
- def view_handler_ns(*args)
195
- self.configuration.view_handler_ns *args
196
- end
197
-
198
189
  def verbose_logging(*args)
199
190
  self.configuration.verbose_logging *args
200
191
  end
@@ -207,59 +198,27 @@ module Deas::Server
207
198
  self.configuration.default_charset *args
208
199
  end
209
200
 
210
- def get(path, handler_class_name, url_name = nil)
211
- self.route(:get, path, handler_class_name, url_name)
212
- end
213
-
214
- def post(path, handler_class_name, url_name = nil)
215
- self.route(:post, path, handler_class_name, url_name)
216
- end
201
+ # router handling
217
202
 
218
- def put(path, handler_class_name, url_name = nil)
219
- self.route(:put, path, handler_class_name, url_name)
203
+ def router(value = nil)
204
+ self.configuration.router = value if !value.nil?
205
+ self.configuration.router
220
206
  end
221
207
 
222
- def patch(path, handler_class_name, url_name = nil)
223
- self.route(:patch, path, handler_class_name, url_name)
224
- end
208
+ def view_handler_ns(*args); self.router.view_handler_ns(*args); end
225
209
 
226
- def delete(path, handler_class_name, url_name = nil)
227
- self.route(:delete, path, handler_class_name, url_name)
228
- end
210
+ def url(*args, &block); self.router.url(*args, &block); end
211
+ def url_for(*args, &block); self.router.url_for(*args, &block); end
229
212
 
230
- def redirect(http_method, path, to_path = nil, &block)
231
- url = self.configuration.urls[to_path]
232
- if to_path.kind_of?(::Symbol) && url.nil?
233
- raise ArgumentError, "no url named `#{to_path.inspect}`"
234
- end
235
- proxy = Deas::RedirectProxy.new(url || to_path, &block)
236
- self.configuration.add_route(http_method, path, proxy)
237
- end
213
+ def get(*args, &block); self.router.get(*args, &block); end
214
+ def post(*args, &block); self.router.post(*args, &block); end
215
+ def put(*args, &block); self.router.put(*args, &block); end
216
+ def patch(*args, &block); self.router.patch(*args, &block); end
217
+ def delete(*args, &block); self.router.delete(*args, &block); end
238
218
 
239
- def route(http_method, path, handler_class_name, url_name = nil)
240
- if self.view_handler_ns && !(handler_class_name =~ /^::/)
241
- handler_class_name = "#{self.view_handler_ns}::#{handler_class_name}"
242
- end
243
- proxy = Deas::RouteProxy.new(handler_class_name)
244
-
245
- if url_name && !url_name.to_s.empty?
246
- if !path.kind_of?(::String)
247
- raise ArgumentError, "invalid path `#{path.inspect}` - "\
248
- "can only provide a url name with String paths"
249
- end
250
- self.configuration.add_url(url_name.to_sym, path)
251
- end
252
- self.configuration.add_route(http_method, path, proxy)
253
- end
254
-
255
- def url(name, *args)
256
- url = self.configuration.urls[name.to_sym]
257
- raise ArgumentError, "no route named `#{name.to_sym.inspect}`" unless url
258
-
259
- url.path_for(*args)
260
- end
219
+ def route(*args, &block); self.router.route(*args, &block); end
220
+ def redirect(*args, &block); self.router.redirect(*args, &block); end
261
221
 
262
222
  end
263
223
 
264
224
  end
265
-
data/lib/deas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Deas
2
- VERSION = "0.18.0"
2
+ VERSION = "0.19.0"
3
3
  end
@@ -40,8 +40,8 @@ class DeasTestServer
40
40
 
41
41
  get '/handler/tests.json', 'HandlerTestsHandler'
42
42
 
43
- redirect :get, '/route_redirect', '/somewhere'
44
- redirect(:get, '/:prefix/redirect'){ "/#{params['prefix']}/somewhere" }
43
+ redirect '/route_redirect', '/somewhere'
44
+ redirect('/:prefix/redirect'){ "/#{params['prefix']}/somewhere" }
45
45
 
46
46
  end
47
47
 
@@ -0,0 +1,170 @@
1
+ require 'assert'
2
+ require 'deas/router'
3
+
4
+ class Deas::Router
5
+
6
+ class BaseTests < Assert::Context
7
+ desc "Deas::Router"
8
+ setup do
9
+ @router = Deas::Router.new
10
+ end
11
+ subject{ @router }
12
+
13
+ should have_accessors :urls, :routes
14
+ should have_imeths :view_handler_ns
15
+ should have_imeths :url, :url_for
16
+ should have_imeths :get, :post, :put, :patch, :delete
17
+ should have_imeths :route, :redirect
18
+
19
+ should "have no view_handler_ns, urls, or routes by default" do
20
+ assert_nil subject.view_handler_ns
21
+ assert_empty subject.urls
22
+ assert_empty subject.routes
23
+ end
24
+
25
+ should "add a GET route using #get" do
26
+ subject.get('/things', 'ListThings')
27
+
28
+ route = subject.routes[0]
29
+ assert_instance_of Deas::Route, route
30
+ assert_equal :get, route.method
31
+ assert_equal '/things', route.path
32
+ assert_equal 'ListThings', route.handler_proxy.handler_class_name
33
+ end
34
+
35
+ should "add a POST route using #post" do
36
+ subject.post('/things', 'CreateThing')
37
+
38
+ route = subject.routes[0]
39
+ assert_instance_of Deas::Route, route
40
+ assert_equal :post, route.method
41
+ assert_equal '/things', route.path
42
+ assert_equal 'CreateThing', route.handler_proxy.handler_class_name
43
+ end
44
+
45
+ should "add a PUT route using #put" do
46
+ subject.put('/things/:id', 'UpdateThing')
47
+
48
+ route = subject.routes[0]
49
+ assert_instance_of Deas::Route, route
50
+ assert_equal :put, route.method
51
+ assert_equal '/things/:id', route.path
52
+ assert_equal 'UpdateThing', route.handler_proxy.handler_class_name
53
+ end
54
+
55
+ should "add a PATCH route using #patch" do
56
+ subject.patch('/things/:id', 'UpdateThing')
57
+
58
+ route = subject.routes[0]
59
+ assert_instance_of Deas::Route, route
60
+ assert_equal :patch, route.method
61
+ assert_equal '/things/:id', route.path
62
+ assert_equal 'UpdateThing', route.handler_proxy.handler_class_name
63
+ end
64
+
65
+ should "add a DELETE route using #delete" do
66
+ subject.delete('/things/:id', 'DeleteThing')
67
+
68
+ route = subject.routes[0]
69
+ assert_instance_of Deas::Route, route
70
+ assert_equal :delete, route.method
71
+ assert_equal '/things/:id', route.path
72
+ assert_equal 'DeleteThing', route.handler_proxy.handler_class_name
73
+ end
74
+
75
+ should "allow defining any kind of route using #route" do
76
+ subject.route(:options, '/get_info', 'GetInfo')
77
+
78
+ route = subject.routes[0]
79
+ assert_instance_of Deas::Route, route
80
+ assert_equal :options, route.method
81
+ assert_equal '/get_info', route.path
82
+ assert_equal 'GetInfo', route.handler_proxy.handler_class_name
83
+ end
84
+
85
+ should "set a view handler namespace and use it when defining routes" do
86
+ subject.view_handler_ns 'MyStuff'
87
+ assert_equal 'MyStuff', subject.view_handler_ns
88
+
89
+ # should use the ns
90
+ route = subject.route(:get, '/ns_test', 'NsTest')
91
+ assert_equal 'MyStuff::NsTest', route.handler_proxy.handler_class_name
92
+
93
+ # should ignore the ns when the leading colons are present
94
+ route = subject.route(:post, '/no_ns_test', '::NoNsTest')
95
+ assert_equal '::NoNsTest', route.handler_proxy.handler_class_name
96
+ end
97
+
98
+ should "add a redirect route using #redirect" do
99
+ subject.redirect('/invalid', '/assets')
100
+
101
+ route = subject.routes[0]
102
+ assert_instance_of Deas::Route, route
103
+ assert_equal :get, route.method
104
+ assert_equal '/invalid', route.path
105
+ assert_equal 'Deas::RedirectHandler', route.handler_proxy.handler_class_name
106
+
107
+ route.validate!
108
+ assert_not_nil route.handler_class
109
+ end
110
+
111
+ end
112
+
113
+ class NamedUrlTests < BaseTests
114
+ desc "when using named urls"
115
+ setup do
116
+ @router.url('get_info', '/info/:for')
117
+ end
118
+
119
+ should "define a url given a name and a path" do
120
+ url = subject.urls[:get_info]
121
+
122
+ assert_not_nil url
123
+ assert_kind_of Deas::Url, url
124
+ assert_equal :get_info, url.name
125
+ assert_equal '/info/:for', url.path
126
+ end
127
+
128
+ should "complain if defining a url with a non-string path" do
129
+ assert_raises ArgumentError do
130
+ subject.url(:get_info, /^\/info/)
131
+ end
132
+ end
133
+
134
+ should "build a path for a url given params" do
135
+ exp_path = "/info/now"
136
+ assert_equal exp_path, subject.url_for(:get_info, :for => 'now')
137
+ assert_equal exp_path, subject.url_for(:get_info, 'now')
138
+ end
139
+
140
+ should "complain if building a named url that hasn't been defined" do
141
+ assert_raises ArgumentError do
142
+ subject.url_for(:get_all_info, 'now')
143
+ end
144
+ end
145
+
146
+ should "complain if redirecting to a named url that hasn't been defined" do
147
+ assert_raises ArgumentError do
148
+ subject.redirect('/somewhere', :not_defined_url)
149
+ end
150
+ end
151
+
152
+ should "redirect using a url name instead of a path" do
153
+ subject.redirect(:get_info, '/somewhere')
154
+ url = subject.urls[:get_info]
155
+ route = subject.routes.last
156
+
157
+ assert_equal url.path, route.path
158
+ end
159
+
160
+ should "route using a url name instead of a path" do
161
+ subject.route(:get, :get_info, 'GetInfo')
162
+ url = subject.urls[:get_info]
163
+ route = subject.routes.last
164
+
165
+ assert_equal url.path, route.path
166
+ end
167
+
168
+ end
169
+
170
+ end
@@ -1,10 +1,10 @@
1
1
  require 'assert'
2
- require 'set'
2
+ require 'deas/server'
3
+
3
4
  require 'test/support/view_handlers'
4
5
  require 'deas/exceptions'
5
6
  require 'deas/template'
6
- require 'deas/route_proxy'
7
- require 'deas/server'
7
+ require 'deas/router'
8
8
 
9
9
  class Deas::Server::Configuration
10
10
 
@@ -24,11 +24,11 @@ class Deas::Server::Configuration
24
24
 
25
25
  # server handling options
26
26
 
27
- should have_imeths :logger, :verbose_logging, :view_handler_ns
27
+ should have_imeths :verbose_logging, :logger
28
28
 
29
29
  should have_accessors :settings, :error_procs, :init_procs, :template_helpers
30
- should have_accessors :middlewares, :routes, :urls
31
- should have_imeths :valid?, :validate!, :template_scope, :add_route
30
+ should have_accessors :middlewares, :router
31
+ should have_imeths :valid?, :validate!, :urls, :routes, :template_scope
32
32
 
33
33
  should "default the env to 'development'" do
34
34
  assert_equal 'development', subject.env
@@ -51,7 +51,6 @@ class Deas::Server::Configuration
51
51
  should "default the handling options" do
52
52
  assert_instance_of Deas::NullLogger, subject.logger
53
53
  assert_equal true, subject.verbose_logging
54
- assert_nil subject.view_handler_ns
55
54
  end
56
55
 
57
56
  should "default its stored configuration" do
@@ -62,6 +61,7 @@ class Deas::Server::Configuration
62
61
  assert_empty subject.middlewares
63
62
  assert_empty subject.routes
64
63
  assert_empty subject.urls
64
+ assert_kind_of Deas::Router, subject.router
65
65
  end
66
66
 
67
67
  should "build a template scope including its template helpers" do
@@ -98,6 +98,8 @@ class Deas::Server::Configuration
98
98
  @other_initialized = false
99
99
  proxy = Deas::RouteProxy.new('TestViewHandler')
100
100
  @route = Deas::Route.new(:get, '/something', proxy)
101
+ @router = Deas::Router.new
102
+ @router.routes = [ @route ]
101
103
 
102
104
  @configuration = Deas::Server::Configuration.new.tap do |c|
103
105
  c.env = 'staging'
@@ -109,7 +111,7 @@ class Deas::Server::Configuration
109
111
  c.static = true
110
112
  c.reload_templates = true
111
113
  c.middlewares = [ ['MyMiddleware'] ]
112
- c.routes = [ @route ]
114
+ c.router = @router
113
115
  end
114
116
  @configuration.init_procs << proc{ @initialized = true }
115
117
  @configuration.init_procs << proc{ @other_initialized = true }
@@ -1,9 +1,9 @@
1
1
  require 'assert'
2
- require 'set'
3
- require 'logger'
4
- require 'deas/route'
5
2
  require 'deas/server'
6
3
 
4
+ require 'logger'
5
+ require 'deas/router'
6
+
7
7
  module Deas::Server
8
8
 
9
9
  class BaseTests < Assert::Context
@@ -24,7 +24,13 @@ module Deas::Server
24
24
  should have_imeths :init, :error, :template_helpers, :template_helper?
25
25
  should have_imeths :use, :set, :view_handler_ns, :verbose_logging, :logger
26
26
  should have_imeths :get, :post, :put, :patch, :delete
27
- should have_imeths :redirect, :route, :url
27
+ should have_imeths :redirect, :route, :url, :url_for
28
+
29
+ # DSL for server routing settings
30
+ should have_imeths :router, :view_handler_ns
31
+ should have_imeths :url, :url_for
32
+ should have_imeths :get, :post, :put, :patch, :delete
33
+ should have_imeths :route, :redirect
28
34
 
29
35
  should "allow setting it's configuration options" do
30
36
  config = subject.configuration
@@ -90,148 +96,12 @@ module Deas::Server
90
96
  assert subject.template_helper?(helper_module)
91
97
  end
92
98
 
93
- should "set a namespace and use it when defining routes" do
94
- subject.view_handler_ns 'MyStuff'
95
- assert_equal 'MyStuff', subject.configuration.view_handler_ns
96
-
97
- # should use the ns
98
- route = subject.route(:get, '/ns_test', 'NsTest')
99
- assert_equal 'MyStuff::NsTest', route.handler_proxy.handler_class_name
100
-
101
- # should ignore the ns when the leading colons are present
102
- route = subject.route(:post, '/no_ns_test', '::NoNsTest')
103
- assert_equal '::NoNsTest', route.handler_proxy.handler_class_name
104
- end
105
-
106
- should "add a GET route using #get" do
107
- subject.get('/things', 'ListThings')
108
-
109
- route = subject.configuration.routes[0]
110
- assert_instance_of Deas::Route, route
111
- assert_equal :get, route.method
112
- assert_equal '/things', route.path
113
- assert_equal 'ListThings', route.handler_proxy.handler_class_name
114
- end
115
-
116
- should "add a POST route using #post" do
117
- subject.post('/things', 'CreateThing')
118
-
119
- route = subject.configuration.routes[0]
120
- assert_instance_of Deas::Route, route
121
- assert_equal :post, route.method
122
- assert_equal '/things', route.path
123
- assert_equal 'CreateThing', route.handler_proxy.handler_class_name
124
- end
125
-
126
- should "add a PUT route using #put" do
127
- subject.put('/things/:id', 'UpdateThing')
128
-
129
- route = subject.configuration.routes[0]
130
- assert_instance_of Deas::Route, route
131
- assert_equal :put, route.method
132
- assert_equal '/things/:id', route.path
133
- assert_equal 'UpdateThing', route.handler_proxy.handler_class_name
134
- end
135
-
136
- should "add a PATCH route using #patch" do
137
- subject.patch('/things/:id', 'UpdateThing')
138
-
139
- route = subject.configuration.routes[0]
140
- assert_instance_of Deas::Route, route
141
- assert_equal :patch, route.method
142
- assert_equal '/things/:id', route.path
143
- assert_equal 'UpdateThing', route.handler_proxy.handler_class_name
144
- end
145
-
146
- should "add a DELETE route using #delete" do
147
- subject.delete('/things/:id', 'DeleteThing')
148
-
149
- route = subject.configuration.routes[0]
150
- assert_instance_of Deas::Route, route
151
- assert_equal :delete, route.method
152
- assert_equal '/things/:id', route.path
153
- assert_equal 'DeleteThing', route.handler_proxy.handler_class_name
154
- end
155
-
156
- should "add a redirect route using #redirect" do
157
- subject.redirect(:get, '/invalid', '/assets')
158
-
159
- route = subject.configuration.routes[0]
160
- assert_instance_of Deas::Route, route
161
- assert_equal :get, route.method
162
- assert_equal '/invalid', route.path
163
- assert_equal 'Deas::RedirectHandler', route.handler_proxy.handler_class_name
164
-
165
- route.validate!
166
- assert_not_nil route.handler_class
167
- end
168
-
169
- should "allow defining any kind of route using #route" do
170
- subject.route(:options, '/get_info', 'GetInfo')
171
-
172
- route = subject.configuration.routes[0]
173
- assert_instance_of Deas::Route, route
174
- assert_equal :options, route.method
175
- assert_equal '/get_info', route.path
176
- assert_equal 'GetInfo', route.handler_proxy.handler_class_name
177
- end
178
-
179
- should "not define urls for routes created with no url name" do
180
- assert_empty subject.configuration.urls
181
-
182
- @server_class.route(:get, '/info', 'GetInfo')
183
- assert_empty subject.configuration.urls
184
-
185
- @server_class.route(:get, '/info', 'GetInfo', nil)
186
- assert_empty subject.configuration.urls
187
-
188
- @server_class.route(:get, '/info', 'GetInfo', '')
189
- assert_empty subject.configuration.urls
190
-
191
- @server_class.route(:get, '/info', 'GetInfo', 'get_info')
192
- assert_not_empty subject.configuration.urls
193
- end
194
-
195
- end
196
-
197
- class NamedUrlTests < BaseTests
198
- desc "when defining a route with a url name"
199
- setup do
200
- @server_class.route(:get, '/info/:for', 'GetInfo', 'get_info')
201
- end
202
-
203
- should "define a url for the route on the server" do
204
- url = subject.configuration.urls[:get_info]
205
-
206
- assert_not_nil url
207
- assert_kind_of Deas::Url, url
208
- assert_equal :get_info, url.name
209
- assert_equal '/info/:for', url.path
210
- end
211
-
212
- should "complain if given a non-string path" do
213
- assert_raises ArgumentError do
214
- subject.route(:get, /^\/info/, 'GetInfo', 'get_info')
215
- end
216
- end
217
-
218
- should "build a path for a url given params" do
219
- exp_path = "/info/now"
220
-
221
- assert_equal exp_path, subject.url(:get_info, :for => 'now')
222
- assert_equal exp_path, subject.url(:get_info, 'now')
223
- end
224
-
225
- should "complain if building a named url that hasn't been defined" do
226
- assert_raises ArgumentError do
227
- subject.url(:get_all_info, 'now')
228
- end
229
- end
99
+ should "have a router by default and allow overriding it" do
100
+ assert_kind_of Deas::Router, subject.router
230
101
 
231
- should "complain if redirecting to a named url that hasn't been defined" do
232
- assert_raises ArgumentError do
233
- subject.redirect(:get, '/somewhere', :not_defined_url)
234
- end
102
+ new_router = Deas::Router.new
103
+ subject.router new_router
104
+ assert_same new_router, subject.router
235
105
  end
236
106
 
237
107
  end
@@ -13,6 +13,9 @@ module Deas::SinatraApp
13
13
  setup do
14
14
  proxy = Deas::RouteProxy.new('TestViewHandler')
15
15
  @route = Deas::Route.new(:get, '/something', proxy)
16
+ @router = Deas::Router.new
17
+ @router.routes = [ @route ]
18
+
16
19
  @configuration = Deas::Server::Configuration.new.tap do |c|
17
20
  c.env = 'staging'
18
21
  c.root = 'path/to/somewhere'
@@ -22,7 +25,7 @@ module Deas::SinatraApp
22
25
  c.show_exceptions = true
23
26
  c.static = true
24
27
  c.reload_templates = true
25
- c.routes = [ @route ]
28
+ c.router = @router
26
29
  end
27
30
  @sinatra_app = Deas::SinatraApp.new(@configuration)
28
31
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deas
3
3
  version: !ruby/object:Gem::Version
4
- hash: 87
4
+ hash: 83
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 18
8
+ - 19
9
9
  - 0
10
- version: 0.18.0
10
+ version: 0.19.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-07-10 00:00:00 Z
19
+ date: 2013-07-11 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: ns-options
@@ -153,6 +153,7 @@ files:
153
153
  - lib/deas/redirect_proxy.rb
154
154
  - lib/deas/route.rb
155
155
  - lib/deas/route_proxy.rb
156
+ - lib/deas/router.rb
156
157
  - lib/deas/runner.rb
157
158
  - lib/deas/server.rb
158
159
  - lib/deas/show_exceptions.rb
@@ -191,6 +192,7 @@ files:
191
192
  - test/unit/redirect_proxy_tests.rb
192
193
  - test/unit/route_proxy_tests.rb
193
194
  - test/unit/route_tests.rb
195
+ - test/unit/router_tests.rb
194
196
  - test/unit/runner_tests.rb
195
197
  - test/unit/server_configuration_tests.rb
196
198
  - test/unit/server_tests.rb
@@ -261,6 +263,7 @@ test_files:
261
263
  - test/unit/redirect_proxy_tests.rb
262
264
  - test/unit/route_proxy_tests.rb
263
265
  - test/unit/route_tests.rb
266
+ - test/unit/router_tests.rb
264
267
  - test/unit/runner_tests.rb
265
268
  - test/unit/server_configuration_tests.rb
266
269
  - test/unit/server_tests.rb