lotus-router 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -0
- data/{LICENSE.txt → LICENSE.md} +0 -0
- data/README.md +33 -9
- data/lib/lotus/router.rb +98 -0
- data/lib/lotus/router/version.rb +1 -1
- data/lib/lotus/routing/endpoint.rb +1 -1
- data/lib/lotus/routing/endpoint_resolver.rb +23 -3
- data/lib/lotus/routing/http_router.rb +12 -0
- data/lib/lotus/routing/resource/options.rb +27 -2
- data/lotus-router.gemspec +1 -1
- metadata +6 -46
- data/.coveralls.yml +0 -2
- data/.gitignore +0 -9
- data/.travis.yml +0 -5
- data/.yardopts +0 -3
- data/Gemfile +0 -11
- data/Rakefile +0 -10
- data/benchmarks/callable +0 -23
- data/benchmarks/named_routes +0 -72
- data/benchmarks/resource +0 -44
- data/benchmarks/resources +0 -58
- data/benchmarks/routes +0 -67
- data/benchmarks/run.sh +0 -11
- data/benchmarks/utils.rb +0 -56
- data/test/fixtures.rb +0 -193
- data/test/integration/client_error_test.rb +0 -16
- data/test/integration/pass_on_response_test.rb +0 -13
- data/test/named_routes_test.rb +0 -123
- data/test/namespace_test.rb +0 -289
- data/test/new_test.rb +0 -67
- data/test/redirect_test.rb +0 -33
- data/test/resource_test.rb +0 -128
- data/test/resources_test.rb +0 -136
- data/test/routing/endpoint_resolver_test.rb +0 -110
- data/test/routing/resource/options_test.rb +0 -36
- data/test/routing_test.rb +0 -99
- data/test/test_helper.rb +0 -32
- data/test/version_test.rb +0 -7
data/test/routing_test.rb
DELETED
@@ -1,99 +0,0 @@
|
|
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
|
data/test/test_helper.rb
DELETED
@@ -1,32 +0,0 @@
|
|
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
|