lotus-router 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +5 -13
  4. data/.travis.yml +5 -0
  5. data/.yardopts +3 -0
  6. data/Gemfile +10 -3
  7. data/README.md +470 -6
  8. data/Rakefile +10 -1
  9. data/benchmarks/callable +23 -0
  10. data/benchmarks/named_routes +72 -0
  11. data/benchmarks/resource +44 -0
  12. data/benchmarks/resources +58 -0
  13. data/benchmarks/routes +67 -0
  14. data/benchmarks/run.sh +11 -0
  15. data/benchmarks/utils.rb +56 -0
  16. data/lib/lotus-router.rb +1 -0
  17. data/lib/lotus/router.rb +752 -3
  18. data/lib/lotus/router/version.rb +2 -2
  19. data/lib/lotus/routing/endpoint.rb +114 -0
  20. data/lib/lotus/routing/endpoint_resolver.rb +251 -0
  21. data/lib/lotus/routing/http_router.rb +130 -0
  22. data/lib/lotus/routing/namespace.rb +86 -0
  23. data/lib/lotus/routing/resource.rb +73 -0
  24. data/lib/lotus/routing/resource/action.rb +340 -0
  25. data/lib/lotus/routing/resource/options.rb +48 -0
  26. data/lib/lotus/routing/resources.rb +40 -0
  27. data/lib/lotus/routing/resources/action.rb +123 -0
  28. data/lib/lotus/routing/route.rb +53 -0
  29. data/lotus-router.gemspec +16 -12
  30. data/test/fixtures.rb +193 -0
  31. data/test/integration/client_error_test.rb +16 -0
  32. data/test/integration/pass_on_response_test.rb +13 -0
  33. data/test/named_routes_test.rb +123 -0
  34. data/test/namespace_test.rb +289 -0
  35. data/test/new_test.rb +67 -0
  36. data/test/redirect_test.rb +33 -0
  37. data/test/resource_test.rb +128 -0
  38. data/test/resources_test.rb +136 -0
  39. data/test/routing/endpoint_resolver_test.rb +110 -0
  40. data/test/routing/resource/options_test.rb +36 -0
  41. data/test/routing_test.rb +99 -0
  42. data/test/test_helper.rb +32 -0
  43. data/test/version_test.rb +7 -0
  44. metadata +102 -10
@@ -0,0 +1,99 @@
1
+ require 'test_helper'
2
+
3
+ describe Lotus::Router do
4
+ before do
5
+ @router = Lotus::Router.new
6
+ @app = Rack::MockRequest.new(@router)
7
+ end
8
+
9
+ after do
10
+ @router.reset!
11
+ end
12
+
13
+ def endpoint(response)
14
+ ->(env) { response }
15
+ end
16
+
17
+ [ 'get', 'post', 'delete', 'put', 'patch', 'trace', 'options' ].each do |verb|
18
+
19
+ describe "##{ verb }" do
20
+ describe 'path recognition' do
21
+ it 'recognize fixed string' do
22
+ response = [200, {}, ['Fixed!']]
23
+ @router.send(verb, '/lotus', to: endpoint(response))
24
+
25
+ response.must_be_same_as @app.request(verb.upcase, '/lotus')
26
+ end
27
+
28
+ it 'recognize moving parts string' do
29
+ response = [200, {}, ['Moving!']]
30
+ @router.send(verb, '/lotus/:id', to: endpoint(response))
31
+
32
+ response.must_be_same_as @app.request(verb.upcase, '/lotus/23')
33
+ end
34
+
35
+ it 'recognize globbing string' do
36
+ response = [200, {}, ['Globbing!']]
37
+ @router.send(verb, '/lotus/*', to: endpoint(response))
38
+
39
+ response.must_be_same_as @app.request(verb.upcase, '/lotus/all')
40
+ end
41
+
42
+ it 'recognize format string' do
43
+ response = [200, {}, ['Format!']]
44
+ @router.send(verb, '/lotus/:id(.:format)', to: endpoint(response))
45
+
46
+ response.must_be_same_as @app.request(verb.upcase, '/lotus/all.json')
47
+ end
48
+
49
+ it 'accepts a block' do
50
+ response = [200, {}, ['Block!']]
51
+ @router.send(verb, '/block') {|e| response }
52
+
53
+ response.must_be_same_as @app.request(verb.upcase, '/block')
54
+ end
55
+ end
56
+
57
+ describe 'named routes' do
58
+ it 'recognizes by the given symbol' do
59
+ response = [200, {}, ['Named route!']]
60
+
61
+ @router.send(verb, '/named_route', to: endpoint(response), as: :"#{ verb }_named_route")
62
+
63
+ @router.path(:"#{ verb }_named_route").must_equal '/named_route'
64
+ @router.url(:"#{ verb }_named_route").must_equal 'http://localhost/named_route'
65
+ end
66
+
67
+ it 'compiles variables' do
68
+ response = [200, {}, ['Named %route!']]
69
+
70
+ @router.send(verb, '/named_:var', to: endpoint(response), as: :"#{ verb }_named_route_var")
71
+
72
+ @router.path(:"#{ verb }_named_route_var", var: 'route').must_equal '/named_route'
73
+ @router.url(:"#{ verb }_named_route_var", var: 'route').must_equal 'http://localhost/named_route'
74
+ end
75
+
76
+ it 'allows custom url parts' do
77
+ response = [200, {}, ['Named route with custom parts!']]
78
+
79
+ router = Lotus::Router.new(scheme: 'https', host: 'lotusrb.org', port: 443)
80
+ router.send(verb, '/custom_named_route', to: endpoint(response), as: :"#{ verb }_custom_named_route")
81
+
82
+ router.url(:"#{ verb }_custom_named_route").must_equal 'https://lotusrb.org/custom_named_route'
83
+ end
84
+ end
85
+
86
+ describe 'constraints' do
87
+ it 'recognize when called with matching constraints' do
88
+ response = [200, {}, ['Moving with constraints!']]
89
+
90
+ @router.send(verb, '/lotus/:id', to: endpoint(response), id: /\d+/)
91
+ response.must_be_same_as @app.request(verb.upcase, '/lotus/23')
92
+
93
+ @app.request(verb.upcase, '/lotus/flower').status.must_equal 404
94
+ end
95
+ end
96
+
97
+ end # main each
98
+ end
99
+ end
@@ -0,0 +1,32 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter 'test'
5
+ command_name 'Mintest'
6
+ end
7
+ end
8
+
9
+ require 'rubygems'
10
+ require 'bundler/setup'
11
+ require 'coveralls'
12
+ Coveralls.wear!
13
+ require 'minitest/autorun'
14
+ require 'fixtures'
15
+ $:.unshift 'lib'
16
+ require 'lotus-router'
17
+
18
+ Rack::MockResponse.class_eval do
19
+ def equal?(other)
20
+ other = Rack::MockResponse.new(*other)
21
+
22
+ status == other.status &&
23
+ headers == other.headers &&
24
+ body == other.body
25
+ end
26
+ end
27
+
28
+ Lotus::Router.class_eval do
29
+ def reset!
30
+ @router.reset!
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ describe Lotus::Router::VERSION do
4
+ it 'exposes version' do
5
+ Lotus::Router::VERSION.must_equal '0.1.0'
6
+ end
7
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lotus-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-01 00:00:00.000000000 Z
11
+ date: 2014-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http_router
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: lotus-utils
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -24,36 +52,85 @@ dependencies:
24
52
  - - "~>"
25
53
  - !ruby/object:Gem::Version
26
54
  version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rake
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
- - - ">="
73
+ - - "~>"
32
74
  - !ruby/object:Gem::Version
33
- version: '0'
75
+ version: '10'
34
76
  type: :development
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
- - - ">="
80
+ - - "~>"
39
81
  - !ruby/object:Gem::Version
40
- version: '0'
41
- description: HTTP router for Lotus
82
+ version: '10'
83
+ description: HTTP Router for Lotus
42
84
  email:
43
85
  - me@lucaguidi.com
44
86
  executables: []
45
87
  extensions: []
46
88
  extra_rdoc_files: []
47
89
  files:
90
+ - ".coveralls.yml"
48
91
  - ".gitignore"
92
+ - ".travis.yml"
93
+ - ".yardopts"
49
94
  - Gemfile
50
95
  - LICENSE.txt
51
96
  - README.md
52
97
  - Rakefile
98
+ - benchmarks/callable
99
+ - benchmarks/named_routes
100
+ - benchmarks/resource
101
+ - benchmarks/resources
102
+ - benchmarks/routes
103
+ - benchmarks/run.sh
104
+ - benchmarks/utils.rb
105
+ - lib/lotus-router.rb
53
106
  - lib/lotus/router.rb
54
107
  - lib/lotus/router/version.rb
108
+ - lib/lotus/routing/endpoint.rb
109
+ - lib/lotus/routing/endpoint_resolver.rb
110
+ - lib/lotus/routing/http_router.rb
111
+ - lib/lotus/routing/namespace.rb
112
+ - lib/lotus/routing/resource.rb
113
+ - lib/lotus/routing/resource/action.rb
114
+ - lib/lotus/routing/resource/options.rb
115
+ - lib/lotus/routing/resources.rb
116
+ - lib/lotus/routing/resources/action.rb
117
+ - lib/lotus/routing/route.rb
55
118
  - lotus-router.gemspec
56
- homepage: ''
119
+ - test/fixtures.rb
120
+ - test/integration/client_error_test.rb
121
+ - test/integration/pass_on_response_test.rb
122
+ - test/named_routes_test.rb
123
+ - test/namespace_test.rb
124
+ - test/new_test.rb
125
+ - test/redirect_test.rb
126
+ - test/resource_test.rb
127
+ - test/resources_test.rb
128
+ - test/routing/endpoint_resolver_test.rb
129
+ - test/routing/resource/options_test.rb
130
+ - test/routing_test.rb
131
+ - test/test_helper.rb
132
+ - test/version_test.rb
133
+ homepage: http://lotusrb.org
57
134
  licenses:
58
135
  - MIT
59
136
  metadata: {}
@@ -76,5 +153,20 @@ rubyforge_project:
76
153
  rubygems_version: 2.2.0
77
154
  signing_key:
78
155
  specification_version: 4
79
- summary: HTTP router for Lotus
80
- test_files: []
156
+ summary: Ruby HTTP Router for Lotus
157
+ test_files:
158
+ - test/fixtures.rb
159
+ - test/integration/client_error_test.rb
160
+ - test/integration/pass_on_response_test.rb
161
+ - test/named_routes_test.rb
162
+ - test/namespace_test.rb
163
+ - test/new_test.rb
164
+ - test/redirect_test.rb
165
+ - test/resource_test.rb
166
+ - test/resources_test.rb
167
+ - test/routing/endpoint_resolver_test.rb
168
+ - test/routing/resource/options_test.rb
169
+ - test/routing_test.rb
170
+ - test/test_helper.rb
171
+ - test/version_test.rb
172
+ has_rdoc: