andyjeffries-journey 1.0.0 → 1.0.0.20111022124133
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -5
- data/Gemfile +5 -2
- data/Manifest.txt +2 -0
- data/README.rdoc +1 -1
- data/Rakefile +1 -0
- data/journey.gemspec +9 -6
- data/lib/journey/gtg/builder.rb +1 -1
- data/lib/journey/gtg/transition_table.rb +2 -2
- data/lib/journey/nfa/transition_table.rb +1 -1
- data/lib/journey/nodes/node.rb +19 -1
- data/lib/journey/path/pattern.rb +4 -4
- data/lib/journey/route.rb +3 -0
- data/lib/journey/router.rb +15 -8
- data/lib/journey/routes.rb +1 -0
- data/lib/journey/visitors.rb +3 -3
- data/test/nfa/test_transition_table.rb +1 -1
- data/test/path/test_pattern.rb +45 -23
- data/test/test_route.rb +14 -0
- data/test/test_router.rb +47 -0
- data/test/test_routes.rb +13 -0
- metadata +14 -26
data/CHANGELOG.rdoc
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* 1 major enhancement
|
4
|
-
|
5
|
-
* Birthday!
|
1
|
+
Mon Jan 23 17:07:53 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
6
2
|
|
3
|
+
* Added symbol? and literal? predicate methods to the ast nodes for
|
4
|
+
easier AST traversal.
|
5
|
+
* Made the dummy node a real class.
|
data/Gemfile
CHANGED
@@ -5,7 +5,10 @@
|
|
5
5
|
source :gemcutter
|
6
6
|
|
7
7
|
|
8
|
-
gem "minitest", "~>2.
|
9
|
-
gem "
|
8
|
+
gem "minitest", "~>2.3", :group => [:development, :test]
|
9
|
+
gem "racc", ">=1.4.6", :group => [:development, :test]
|
10
|
+
gem "rdoc", "~>3.11", :group => [:development, :test]
|
11
|
+
gem "json", ">=0", :group => [:development, :test]
|
12
|
+
gem "hoe", "~>2.12", :group => [:development, :test]
|
10
13
|
|
11
14
|
# vim: syntax=ruby
|
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
data/journey.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "andyjeffries-journey"
|
5
|
-
s.version = "1.0.0.
|
5
|
+
s.version = "1.0.0.20120112115843"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Aaron Patterson", "Andy Jeffries"]
|
9
|
-
s.date = "
|
9
|
+
s.date = "2012-01-24"
|
10
10
|
s.description = "Journey is a router. It routes requests."
|
11
11
|
s.email = ["aaron@tenderlovemaking.com"]
|
12
12
|
s.extra_rdoc_files = ["Manifest.txt", "CHANGELOG.rdoc", "README.rdoc"]
|
13
|
-
s.files = [".autotest", "CHANGELOG.rdoc", "Gemfile", "Manifest.txt", "README.rdoc", "Rakefile", "journey.gemspec", "lib/journey.rb", "lib/journey/backwards.rb", "lib/journey/core-ext/hash.rb", "lib/journey/formatter.rb", "lib/journey/gtg/builder.rb", "lib/journey/gtg/simulator.rb", "lib/journey/gtg/transition_table.rb", "lib/journey/nfa/builder.rb", "lib/journey/nfa/dot.rb", "lib/journey/nfa/simulator.rb", "lib/journey/nfa/transition_table.rb", "lib/journey/nodes/node.rb", "lib/journey/parser.rb", "lib/journey/parser.y", "lib/journey/parser_extras.rb", "lib/journey/path/pattern.rb", "lib/journey/route.rb", "lib/journey/router.rb", "lib/journey/router/strexp.rb", "lib/journey/router/utils.rb", "lib/journey/routes.rb", "lib/journey/scanner.rb", "lib/journey/visitors.rb", "lib/journey/visualizer/d3.min.js", "lib/journey/visualizer/fsm.css", "lib/journey/visualizer/fsm.js", "lib/journey/visualizer/index.html.erb", "lib/journey/visualizer/reset.css", "test/gtg/test_builder.rb", "test/gtg/test_transition_table.rb", "test/helper.rb", "test/nfa/test_simulator.rb", "test/nfa/test_transition_table.rb", "test/nodes/test_symbol.rb", "test/path/test_pattern.rb", "test/route/definition/test_parser.rb", "test/route/definition/test_scanner.rb", "test/router/test_strexp.rb", "test/router/test_utils.rb", "test/test_route.rb", "test/test_router.rb", "test/test_routes.rb"
|
13
|
+
s.files = [".autotest", ".gemtest", ".travis.yml", "CHANGELOG.rdoc", "Gemfile", "Manifest.txt", "README.rdoc", "Rakefile", "journey.gemspec", "lib/journey.rb", "lib/journey/backwards.rb", "lib/journey/core-ext/hash.rb", "lib/journey/formatter.rb", "lib/journey/gtg/builder.rb", "lib/journey/gtg/simulator.rb", "lib/journey/gtg/transition_table.rb", "lib/journey/nfa/builder.rb", "lib/journey/nfa/dot.rb", "lib/journey/nfa/simulator.rb", "lib/journey/nfa/transition_table.rb", "lib/journey/nodes/node.rb", "lib/journey/parser.rb", "lib/journey/parser.y", "lib/journey/parser_extras.rb", "lib/journey/path/pattern.rb", "lib/journey/route.rb", "lib/journey/router.rb", "lib/journey/router/strexp.rb", "lib/journey/router/utils.rb", "lib/journey/routes.rb", "lib/journey/scanner.rb", "lib/journey/visitors.rb", "lib/journey/visualizer/d3.min.js", "lib/journey/visualizer/fsm.css", "lib/journey/visualizer/fsm.js", "lib/journey/visualizer/index.html.erb", "lib/journey/visualizer/reset.css", "test/gtg/test_builder.rb", "test/gtg/test_transition_table.rb", "test/helper.rb", "test/nfa/test_simulator.rb", "test/nfa/test_transition_table.rb", "test/nodes/test_symbol.rb", "test/path/test_pattern.rb", "test/route/definition/test_parser.rb", "test/route/definition/test_scanner.rb", "test/router/test_strexp.rb", "test/router/test_utils.rb", "test/test_route.rb", "test/test_router.rb", "test/test_routes.rb"]
|
14
14
|
s.homepage = "http://github.com/tenderlove/journey"
|
15
15
|
s.rdoc_options = ["--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
@@ -23,20 +23,23 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.specification_version = 3
|
24
24
|
|
25
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
s.add_development_dependency(%q<minitest>, ["~> 2.6"])
|
27
26
|
s.add_development_dependency(%q<racc>, [">= 1.4.6"])
|
27
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.11"])
|
28
28
|
s.add_development_dependency(%q<json>, [">= 0"])
|
29
29
|
s.add_development_dependency(%q<hoe>, ["~> 2.12"])
|
30
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
|
30
31
|
else
|
31
|
-
s.add_dependency(%q<minitest>, ["~> 2.6"])
|
32
32
|
s.add_dependency(%q<racc>, [">= 1.4.6"])
|
33
|
+
s.add_dependency(%q<rdoc>, ["~> 3.11"])
|
33
34
|
s.add_dependency(%q<json>, [">= 0"])
|
34
35
|
s.add_dependency(%q<hoe>, ["~> 2.12"])
|
36
|
+
s.add_dependency(%q<rdoc>, ["~> 3.10"])
|
35
37
|
end
|
36
38
|
else
|
37
|
-
s.add_dependency(%q<minitest>, ["~> 2.6"])
|
38
39
|
s.add_dependency(%q<racc>, [">= 1.4.6"])
|
40
|
+
s.add_dependency(%q<rdoc>, ["~> 3.11"])
|
39
41
|
s.add_dependency(%q<json>, [">= 0"])
|
40
42
|
s.add_dependency(%q<hoe>, ["~> 2.12"])
|
43
|
+
s.add_dependency(%q<rdoc>, ["~> 3.10"])
|
41
44
|
end
|
42
45
|
end
|
data/lib/journey/gtg/builder.rb
CHANGED
@@ -10,8 +10,8 @@ module Journey
|
|
10
10
|
def initialize
|
11
11
|
@regexp_states = Hash.new { |h,k| h[k] = {} }
|
12
12
|
@string_states = Hash.new { |h,k| h[k] = {} }
|
13
|
-
@accepting
|
14
|
-
@memos
|
13
|
+
@accepting = {}
|
14
|
+
@memos = Hash.new { |h,k| h[k] = [] }
|
15
15
|
end
|
16
16
|
|
17
17
|
def add_accepting state
|
data/lib/journey/nodes/node.rb
CHANGED
@@ -35,13 +35,29 @@ module Journey
|
|
35
35
|
def type
|
36
36
|
raise NotImplementedError
|
37
37
|
end
|
38
|
+
|
39
|
+
def symbol?; false; end
|
40
|
+
def literal?; false; end
|
38
41
|
end
|
39
42
|
|
40
43
|
class Terminal < Node
|
41
44
|
alias :symbol :left
|
42
45
|
end
|
43
46
|
|
44
|
-
|
47
|
+
class Literal < Terminal
|
48
|
+
def literal?; true; end
|
49
|
+
def type; :LITERAL; end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Dummy < Literal
|
53
|
+
def initialize x = Object.new
|
54
|
+
super
|
55
|
+
end
|
56
|
+
|
57
|
+
def literal?; false; end
|
58
|
+
end
|
59
|
+
|
60
|
+
%w{ Symbol Slash Dot }.each do |t|
|
45
61
|
class_eval %{
|
46
62
|
class #{t} < Terminal
|
47
63
|
def type; :#{t.upcase}; end
|
@@ -62,6 +78,8 @@ module Journey
|
|
62
78
|
def default_regexp?
|
63
79
|
regexp == DEFAULT_EXP
|
64
80
|
end
|
81
|
+
|
82
|
+
def symbol?; true; end
|
65
83
|
end
|
66
84
|
|
67
85
|
class Unary < Node
|
data/lib/journey/path/pattern.rb
CHANGED
@@ -103,8 +103,7 @@ module Journey
|
|
103
103
|
return @separator_re unless @matchers.key? node
|
104
104
|
|
105
105
|
re = @matchers[node]
|
106
|
-
#
|
107
|
-
"(#{re}?)"
|
106
|
+
"(#{re})"
|
108
107
|
end
|
109
108
|
|
110
109
|
def visit_GROUP node
|
@@ -121,7 +120,8 @@ module Journey
|
|
121
120
|
end
|
122
121
|
|
123
122
|
def visit_STAR node
|
124
|
-
|
123
|
+
re = @matchers[node.left.to_sym] || '.+'
|
124
|
+
"(#{re})"
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -172,11 +172,11 @@ module Journey
|
|
172
172
|
to_regexp.source
|
173
173
|
end
|
174
174
|
|
175
|
-
private
|
176
175
|
def to_regexp
|
177
176
|
@re ||= regexp_visitor.new(@separators, @requirements).accept spec
|
178
177
|
end
|
179
178
|
|
179
|
+
private
|
180
180
|
def regexp_visitor
|
181
181
|
@anchored ? AnchoredRegexp : UnanchoredRegexp
|
182
182
|
end
|
data/lib/journey/route.rb
CHANGED
@@ -5,6 +5,8 @@ module Journey
|
|
5
5
|
attr_reader :constraints
|
6
6
|
alias :conditions :constraints
|
7
7
|
|
8
|
+
attr_accessor :precedence
|
9
|
+
|
8
10
|
##
|
9
11
|
# +path+ is a path constraint.
|
10
12
|
# +constraints+ is a hash of constraints to be applied to this route.
|
@@ -23,6 +25,7 @@ module Journey
|
|
23
25
|
@required_parts = nil
|
24
26
|
@parts = nil
|
25
27
|
@decorated_ast = nil
|
28
|
+
@precedence = 0
|
26
29
|
end
|
27
30
|
|
28
31
|
def ast
|
data/lib/journey/router.rb
CHANGED
@@ -29,6 +29,14 @@ module Journey
|
|
29
29
|
env['REQUEST_METHOD']
|
30
30
|
end
|
31
31
|
|
32
|
+
def path_info
|
33
|
+
env['PATH_INFO']
|
34
|
+
end
|
35
|
+
|
36
|
+
def ip
|
37
|
+
env['REMOTE_ADDR']
|
38
|
+
end
|
39
|
+
|
32
40
|
def [](k); env[k]; end
|
33
41
|
end
|
34
42
|
|
@@ -115,18 +123,17 @@ module Journey
|
|
115
123
|
end
|
116
124
|
|
117
125
|
def find_routes env
|
118
|
-
|
119
|
-
req = request_class.new env
|
126
|
+
req = request_class.new env
|
120
127
|
|
121
|
-
routes = filter_routes(
|
122
|
-
r.path.match(
|
128
|
+
routes = filter_routes(req.path_info) + custom_routes.find_all { |r|
|
129
|
+
r.path.match(req.path_info)
|
123
130
|
}
|
124
131
|
|
125
|
-
routes.find_all { |r|
|
132
|
+
routes.sort_by(&:precedence).find_all { |r|
|
126
133
|
r.constraints.all? { |k,v| v === req.send(k) } &&
|
127
|
-
r.verb ===
|
128
|
-
}.reject { |r|
|
129
|
-
match_data = r.path.match(
|
134
|
+
r.verb === req.request_method
|
135
|
+
}.reject { |r| req.ip && !(r.ip === req.ip) }.map { |r|
|
136
|
+
match_data = r.path.match(req.path_info)
|
130
137
|
match_names = match_data.names.map { |n| n.to_sym }
|
131
138
|
match_values = match_data.captures.map { |v| v && Utils.unescape_uri(v) }
|
132
139
|
info = Hash[match_names.zip(match_values).find_all { |_,y| y }]
|
data/lib/journey/routes.rb
CHANGED
@@ -58,6 +58,7 @@ module Journey
|
|
58
58
|
def add_route app, path, conditions, defaults, name = nil
|
59
59
|
route = Route.new(name, app, path, conditions, defaults)
|
60
60
|
|
61
|
+
route.precedence = routes.length
|
61
62
|
routes << route
|
62
63
|
named_routes[name] = route if name && !named_routes[name]
|
63
64
|
clear_cache!
|
data/lib/journey/visitors.rb
CHANGED
@@ -88,7 +88,8 @@ module Journey
|
|
88
88
|
if consumed == options
|
89
89
|
nil
|
90
90
|
else
|
91
|
-
visit node.left
|
91
|
+
route = visit node.left
|
92
|
+
route.include?("\0") ? nil : route
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
@@ -107,8 +108,7 @@ module Journey
|
|
107
108
|
def visit_SYMBOL node
|
108
109
|
key = node.to_sym
|
109
110
|
|
110
|
-
if options
|
111
|
-
value = options[key]
|
111
|
+
if value = options[key]
|
112
112
|
consumed[key] = value
|
113
113
|
Router::Utils.escape_path(value)
|
114
114
|
else
|
data/test/path/test_pattern.rb
CHANGED
@@ -5,16 +5,16 @@ module Journey
|
|
5
5
|
class TestPattern < MiniTest::Unit::TestCase
|
6
6
|
x = /.+/
|
7
7
|
{
|
8
|
-
'/:controller(/:action)' => %r{\A/(#{x}
|
9
|
-
'/:controller/foo' => %r{\A/(#{x}
|
10
|
-
'/:controller/:action' => %r{\A/(#{x}
|
11
|
-
'/:controller' => %r{\A/(#{x}
|
12
|
-
'/:controller(/:action(/:id))' => %r{\A/(#{x}
|
13
|
-
'/:controller/:action.xml' => %r{\A/(#{x}
|
14
|
-
'/:controller.:format' => %r{\A/(#{x}
|
15
|
-
'/:controller(.:format)' => %r{\A/(#{x}
|
16
|
-
'/:controller/*foo' => %r{\A/(#{x}
|
17
|
-
'/:controller/*foo/bar' => %r{\A/(#{x}
|
8
|
+
'/:controller(/:action)' => %r{\A/(#{x})(?:/([^/.?]+))?\Z},
|
9
|
+
'/:controller/foo' => %r{\A/(#{x})/foo\Z},
|
10
|
+
'/:controller/:action' => %r{\A/(#{x})/([^/.?]+)\Z},
|
11
|
+
'/:controller' => %r{\A/(#{x})\Z},
|
12
|
+
'/:controller(/:action(/:id))' => %r{\A/(#{x})(?:/([^/.?]+)(?:/([^/.?]+))?)?\Z},
|
13
|
+
'/:controller/:action.xml' => %r{\A/(#{x})/([^/.?]+)\.xml\Z},
|
14
|
+
'/:controller.:format' => %r{\A/(#{x})\.([^/.?]+)\Z},
|
15
|
+
'/:controller(.:format)' => %r{\A/(#{x})(?:\.([^/.?]+))?\Z},
|
16
|
+
'/:controller/*foo' => %r{\A/(#{x})/(.+)\Z},
|
17
|
+
'/:controller/*foo/bar' => %r{\A/(#{x})/(.+)/bar\Z},
|
18
18
|
}.each do |path, expected|
|
19
19
|
define_method(:"test_to_regexp_#{path}") do
|
20
20
|
strexp = Router::Strexp.new(
|
@@ -23,21 +23,21 @@ module Journey
|
|
23
23
|
["/", ".", "?"]
|
24
24
|
)
|
25
25
|
path = Pattern.new strexp
|
26
|
-
assert_equal(expected, path.
|
26
|
+
assert_equal(expected, path.to_regexp)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
{
|
31
|
-
'/:controller(/:action)' => %r{\A/(#{x}
|
32
|
-
'/:controller/foo' => %r{\A/(#{x}
|
33
|
-
'/:controller/:action' => %r{\A/(#{x}
|
34
|
-
'/:controller' => %r{\A/(#{x}
|
35
|
-
'/:controller(/:action(/:id))' => %r{\A/(#{x}
|
36
|
-
'/:controller/:action.xml' => %r{\A/(#{x}
|
37
|
-
'/:controller.:format' => %r{\A/(#{x}
|
38
|
-
'/:controller(.:format)' => %r{\A/(#{x}
|
39
|
-
'/:controller/*foo' => %r{\A/(#{x}
|
40
|
-
'/:controller/*foo/bar' => %r{\A/(#{x}
|
31
|
+
'/:controller(/:action)' => %r{\A/(#{x})(?:/([^/.?]+))?},
|
32
|
+
'/:controller/foo' => %r{\A/(#{x})/foo},
|
33
|
+
'/:controller/:action' => %r{\A/(#{x})/([^/.?]+)},
|
34
|
+
'/:controller' => %r{\A/(#{x})},
|
35
|
+
'/:controller(/:action(/:id))' => %r{\A/(#{x})(?:/([^/.?]+)(?:/([^/.?]+))?)?},
|
36
|
+
'/:controller/:action.xml' => %r{\A/(#{x})/([^/.?]+)\.xml},
|
37
|
+
'/:controller.:format' => %r{\A/(#{x})\.([^/.?]+)},
|
38
|
+
'/:controller(.:format)' => %r{\A/(#{x})(?:\.([^/.?]+))?},
|
39
|
+
'/:controller/*foo' => %r{\A/(#{x})/(.+)},
|
40
|
+
'/:controller/*foo/bar' => %r{\A/(#{x})/(.+)/bar},
|
41
41
|
}.each do |path, expected|
|
42
42
|
define_method(:"test_to_non_anchored_regexp_#{path}") do
|
43
43
|
strexp = Router::Strexp.new(
|
@@ -47,7 +47,7 @@ module Journey
|
|
47
47
|
false
|
48
48
|
)
|
49
49
|
path = Pattern.new strexp
|
50
|
-
assert_equal(expected, path.
|
50
|
+
assert_equal(expected, path.to_regexp)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -101,6 +101,17 @@ module Journey
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
+
def test_to_regexp_match_non_optional
|
105
|
+
strexp = Router::Strexp.new(
|
106
|
+
'/:name',
|
107
|
+
{ :name => /\d+/ },
|
108
|
+
["/", ".", "?"]
|
109
|
+
)
|
110
|
+
path = Pattern.new strexp
|
111
|
+
assert_match('/123', path)
|
112
|
+
refute_match('/', path)
|
113
|
+
end
|
114
|
+
|
104
115
|
def test_to_regexp_with_group
|
105
116
|
strexp = Router::Strexp.new(
|
106
117
|
'/page/:name',
|
@@ -157,6 +168,17 @@ module Journey
|
|
157
168
|
assert_equal %w{ tender 10 }, match.captures
|
158
169
|
end
|
159
170
|
|
171
|
+
def test_star_with_custom_re
|
172
|
+
z = /\d+/
|
173
|
+
strexp = Router::Strexp.new(
|
174
|
+
'/page/*foo',
|
175
|
+
{ :foo => z },
|
176
|
+
["/", ".", "?"]
|
177
|
+
)
|
178
|
+
path = Pattern.new strexp
|
179
|
+
assert_equal(%r{\A/page/(#{z})\Z}, path.to_regexp)
|
180
|
+
end
|
181
|
+
|
160
182
|
def test_insensitive_regexp_with_group
|
161
183
|
strexp = Router::Strexp.new(
|
162
184
|
'/page/:name/aaron',
|
@@ -180,7 +202,7 @@ module Journey
|
|
180
202
|
def test_to_regexp_defaults
|
181
203
|
path = Pattern.new '/:controller(/:action(/:id))'
|
182
204
|
expected = %r{\A/([^/.?]+)(?:/([^/.?]+)(?:/([^/.?]+))?)?\Z}
|
183
|
-
assert_equal expected, path.
|
205
|
+
assert_equal expected, path.to_regexp
|
184
206
|
end
|
185
207
|
|
186
208
|
def test_failed_match
|
data/test/test_route.rb
CHANGED
@@ -74,6 +74,20 @@ module Journey
|
|
74
74
|
assert_equal '/page/10', route.format({ :id => 10 })
|
75
75
|
end
|
76
76
|
|
77
|
+
def test_extras_are_not_included_if_optional_with_parameter
|
78
|
+
path = Path::Pattern.new '(/sections/:section)/pages/:id'
|
79
|
+
route = Route.new("name", nil, path, { }, { :action => 'show' })
|
80
|
+
|
81
|
+
assert_equal '/pages/10', route.format({:id => 10})
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_extras_are_not_included_if_optional_parameter_is_nil
|
85
|
+
path = Path::Pattern.new '(/sections/:section)/pages/:id'
|
86
|
+
route = Route.new("name", nil, path, { }, { :action => 'show' })
|
87
|
+
|
88
|
+
assert_equal '/pages/10', route.format({:id => 10, :section => nil})
|
89
|
+
end
|
90
|
+
|
77
91
|
def test_score
|
78
92
|
path = Path::Pattern.new "/page/:id(/:action)(.:format)"
|
79
93
|
specific = Route.new "name", nil, path, {}, {:controller=>"pages", :action=>"show"}
|
data/test/test_router.rb
CHANGED
@@ -26,6 +26,10 @@ module Journey
|
|
26
26
|
self.called = true
|
27
27
|
'world'
|
28
28
|
end
|
29
|
+
|
30
|
+
def path_info; env['PATH_INFO']; end
|
31
|
+
def request_method; env['REQUEST_METHOD']; end
|
32
|
+
def ip; env['REMOTE_ADDR']; end
|
29
33
|
end
|
30
34
|
|
31
35
|
def test_dashes
|
@@ -85,6 +89,49 @@ module Journey
|
|
85
89
|
assert_equal env.env, klass.env
|
86
90
|
end
|
87
91
|
|
92
|
+
class CustomPathRequest < Router::NullReq
|
93
|
+
def path_info
|
94
|
+
env['custom.path_info']
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_request_class_overrides_path_info
|
99
|
+
router = Router.new(routes, {:request_class => CustomPathRequest })
|
100
|
+
|
101
|
+
exp = Router::Strexp.new '/bar', {}, ['/.?']
|
102
|
+
path = Path::Pattern.new exp
|
103
|
+
|
104
|
+
routes.add_route nil, path, {}, {}, {}
|
105
|
+
|
106
|
+
env = rails_env 'PATH_INFO' => '/foo', 'custom.path_info' => '/bar'
|
107
|
+
|
108
|
+
recognized = false
|
109
|
+
router.recognize(env) do |r, _, params|
|
110
|
+
recognized = true
|
111
|
+
end
|
112
|
+
|
113
|
+
assert recognized, "route should have been recognized"
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_regexp_first_precedence
|
117
|
+
add_routes @router, [
|
118
|
+
Router::Strexp.new("/whois/:domain", {:domain => /\w+\.[\w\.]+/}, ['/', '.', '?']),
|
119
|
+
Router::Strexp.new("/whois/:id(.:format)", {}, ['/', '.', '?'])
|
120
|
+
]
|
121
|
+
|
122
|
+
env = rails_env 'PATH_INFO' => '/whois/example.com'
|
123
|
+
|
124
|
+
list = []
|
125
|
+
@router.recognize(env) do |r, _, params|
|
126
|
+
list << r
|
127
|
+
end
|
128
|
+
assert_equal 2, list.length
|
129
|
+
|
130
|
+
r = list.first
|
131
|
+
|
132
|
+
assert_equal '/whois/:domain', r.path.spec.to_s
|
133
|
+
end
|
134
|
+
|
88
135
|
def test_required_parts_verified_are_anchored
|
89
136
|
add_routes @router, [
|
90
137
|
Router::Strexp.new("/foo/:id", { :id => /\d/ }, ['/', '.', '?'], false)
|
data/test/test_routes.rb
CHANGED
@@ -34,5 +34,18 @@ module Journey
|
|
34
34
|
routes.add_route nil, path, {}, {}, {}
|
35
35
|
refute_equal sim, routes.simulator
|
36
36
|
end
|
37
|
+
|
38
|
+
def test_first_name_wins
|
39
|
+
#def add_route app, path, conditions, defaults, name = nil
|
40
|
+
routes = Routes.new
|
41
|
+
|
42
|
+
one = Path::Pattern.new '/hello'
|
43
|
+
two = Path::Pattern.new '/aaron'
|
44
|
+
|
45
|
+
routes.add_route nil, one, {}, {}, 'aaron'
|
46
|
+
routes.add_route nil, two, {}, {}, 'aaron'
|
47
|
+
|
48
|
+
assert_equal '/hello', routes.named_routes['aaron'].path.spec.to_s
|
49
|
+
end
|
37
50
|
end
|
38
51
|
end
|
metadata
CHANGED
@@ -1,30 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: andyjeffries-journey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0.20111022124133
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Aaron Patterson
|
9
|
+
- Andy Jeffries
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2011-10-22 00:00:00.000000000Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: minitest
|
16
|
-
requirement: &
|
17
|
+
requirement: &70099054425280 !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ~>
|
20
21
|
- !ruby/object:Gem::Version
|
21
|
-
version: '2.
|
22
|
+
version: '2.6'
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
+
version_requirements: *70099054425280
|
25
26
|
- !ruby/object:Gem::Dependency
|
26
27
|
name: racc
|
27
|
-
requirement: &
|
28
|
+
requirement: &70099054424560 !ruby/object:Gem::Requirement
|
28
29
|
none: false
|
29
30
|
requirements:
|
30
31
|
- - ! '>='
|
@@ -32,10 +33,10 @@ dependencies:
|
|
32
33
|
version: 1.4.6
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
+
version_requirements: *70099054424560
|
36
37
|
- !ruby/object:Gem::Dependency
|
37
38
|
name: json
|
38
|
-
requirement: &
|
39
|
+
requirement: &70099054423700 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
41
42
|
- - ! '>='
|
@@ -43,21 +44,10 @@ dependencies:
|
|
43
44
|
version: '0'
|
44
45
|
type: :development
|
45
46
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: rdoc
|
49
|
-
requirement: &70141541895120 !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '3.10'
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: *70141541895120
|
47
|
+
version_requirements: *70099054423700
|
58
48
|
- !ruby/object:Gem::Dependency
|
59
49
|
name: hoe
|
60
|
-
requirement: &
|
50
|
+
requirement: &70099054423180 !ruby/object:Gem::Requirement
|
61
51
|
none: false
|
62
52
|
requirements:
|
63
53
|
- - ~>
|
@@ -65,7 +55,7 @@ dependencies:
|
|
65
55
|
version: '2.12'
|
66
56
|
type: :development
|
67
57
|
prerelease: false
|
68
|
-
version_requirements: *
|
58
|
+
version_requirements: *70099054423180
|
69
59
|
description: Journey is a router. It routes requests.
|
70
60
|
email:
|
71
61
|
- aaron@tenderlovemaking.com
|
@@ -140,9 +130,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
130
|
- - ! '>='
|
141
131
|
- !ruby/object:Gem::Version
|
142
132
|
version: '0'
|
143
|
-
segments:
|
144
|
-
- 0
|
145
|
-
hash: 3858943851392941251
|
146
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
134
|
none: false
|
148
135
|
requirements:
|
@@ -150,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
137
|
- !ruby/object:Gem::Version
|
151
138
|
version: '0'
|
152
139
|
requirements: []
|
153
|
-
rubyforge_project:
|
140
|
+
rubyforge_project: journey
|
154
141
|
rubygems_version: 1.8.10
|
155
142
|
signing_key:
|
156
143
|
specification_version: 3
|
@@ -169,3 +156,4 @@ test_files:
|
|
169
156
|
- test/test_route.rb
|
170
157
|
- test/test_router.rb
|
171
158
|
- test/test_routes.rb
|
159
|
+
has_rdoc:
|