rack-jet_router 1.3.0 → 1.4.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.
data/test/router_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  ###
4
- ### $Release: 1.3.0 $
4
+ ### $Release: 1.4.0 $
5
5
  ### $Copyright: copyright(c) 2015 kwatch@gmail.com $
6
6
  ### $License: MIT License $
7
7
  ###
@@ -35,6 +35,8 @@ Oktest.scope do
35
35
  admin_book_delete_app = proc {|env| [200, {}, ["admin_book_delete_app"]]}
36
36
  admin_book_edit_app = proc {|env| [200, {}, ["admin_book_edit_app"]]}
37
37
  #
38
+ staticfile_app = proc {|env| [200, {}, ["staticfile_app"]]}
39
+ #
38
40
  whole_urlpath_mapping = [
39
41
  ['/' , welcome_app],
40
42
  ['/index.html' , welcome_app],
@@ -56,6 +58,7 @@ Oktest.scope do
56
58
  ['/:id' , {:GET=>admin_book_show_app, :PUT=>admin_book_update_app, :DELETE=>admin_book_delete_app}],
57
59
  ]],
58
60
  ]],
61
+ ['/static/*filepath', {:GET=>staticfile_app}],
59
62
  ]
60
63
 
61
64
  def new_env(req_method, req_path, opts={})
@@ -250,6 +253,9 @@ Oktest.scope do
250
253
  "PUT" => admin_book_update_app,
251
254
  "DELETE" => admin_book_delete_app,
252
255
  }],
256
+ ["/static/*filepath", {
257
+ "GET" => staticfile_app,
258
+ }],
253
259
  ]
254
260
  end
255
261
 
@@ -277,10 +283,45 @@ Oktest.scope do
277
283
  end
278
284
  end
279
285
 
286
+ spec "[!ec0av] treats '/foo(.html|.json)' as three fixed urlpaths." do
287
+ mapping = {
288
+ "/api/books(.html|.json)" => book_list_api,
289
+ }
290
+ router = Rack::JetRouter.new(mapping)
291
+ router.instance_exec(self) do |_|
292
+ _.ok {@fixed_endpoints} == {
293
+ "/api/books" => book_list_api,
294
+ "/api/books.html" => book_list_api,
295
+ "/api/books.json" => book_list_api,
296
+ }
297
+ _.ok {@variable_endpoints} == []
298
+ end
299
+ end
300
+
301
+ spec "[!ylyi0] stores '/foo' as fixed path when path pattern is '/foo(.:format)'." do
302
+ mapping = {
303
+ "/api/books(.json|.:format|.html)" => book_list_api,
304
+ }
305
+ router = Rack::JetRouter.new(mapping)
306
+ router.instance_exec(self) do |_|
307
+ _.ok {@fixed_endpoints} == {
308
+ "/api/books" => book_list_api,
309
+ "/api/books.json" => book_list_api,
310
+ "/api/books.html" => book_list_api,
311
+ }
312
+ _.ok {@variable_endpoints} == [
313
+ [%r!\A/api/books(?:\.([^./?]+))?\z!,
314
+ ["format"], book_list_api, nil, nil],
315
+ ]
316
+ end
317
+
318
+ end
319
+
280
320
  spec "[!saa1a] compiles compound urlpath regexp." do
281
321
  id = '[^./?]+'
282
322
  z = '(\z)'
283
- ok {@router.urlpath_rexp} == %r!\A/a(?:pi/books/#{id}(?:#{z}|/(?:edit#{z}|comments(?:#{z}|/#{id}#{z})))|dmin/books/#{id}#{z})\z!
323
+ expected = %r!\A/(?:a(?:pi/books/#{id}(?:#{z}|/(?:edit#{z}|comments(?:#{z}|/#{id}#{z})))|dmin/books/#{id}#{z})|static/.*(\z))\z!
324
+ ok {@router.urlpath_rexp} == expected
284
325
  end
285
326
 
286
327
  spec "[!f1d7s] builds variable endpoint list." do
@@ -292,11 +333,12 @@ Oktest.scope do
292
333
  }
293
334
  @router.instance_exec(self) do |_|
294
335
  _.ok {@variable_endpoints} == [
295
- [%r'\A/api/books/(#{id})\z', ['id'], book_show_api, (11..-1)],
296
- [%r'\A/api/books/(#{id})/edit\z', ['id'], book_edit_api, (11..-6)],
297
- [%r'\A/api/books/(#{id})/comments\z', ['book_id'], comment_create_api, (11..-10)],
298
- [%r'\A/api/books/(#{id})/comments/(#{id})\z', ['book_id', 'comment_id'], comment_update_api, nil],
299
- [%r'\A/admin/books/(#{id})\z', ['id'], map2, (13..-1)],
336
+ [%r'\A/api/books/(#{id})\z', ['id'], book_show_api, (11..-1), nil],
337
+ [%r'\A/api/books/(#{id})/edit\z', ['id'], book_edit_api, (11..-6), nil],
338
+ [%r'\A/api/books/(#{id})/comments\z', ['book_id'], comment_create_api, (11..-10), nil],
339
+ [%r'\A/api/books/(#{id})/comments/(#{id})\z', ['book_id', 'comment_id'], comment_update_api, (11..-1), '/comments/'],
340
+ [%r'\A/admin/books/(#{id})\z', ['id'], map2, (13..-1), nil],
341
+ [%r'\A/static/(.*)\z', ['filepath'], {"GET"=>staticfile_app}, (8..-1), nil],
300
342
  ]
301
343
  end
302
344
  end
data/test/shared.rb CHANGED
@@ -10,6 +10,6 @@ require 'rack/jet_router'
10
10
  class Map < Hash
11
11
  end
12
12
 
13
- def Map(**kwargs)
14
- return Map.new.update(kwargs)
13
+ def Map(dict={}, **kwargs)
14
+ return Map.new.update(dict.merge(kwargs))
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-jet_router
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kwatch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-09 00:00:00.000000000 Z
11
+ date: 2024-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oktest