usher 0.5.8 → 0.5.10
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/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/lib/usher/node.rb +2 -1
- data/lib/usher.rb +4 -0
- data/spec/private/recognize_spec.rb +51 -38
- metadata +3 -3
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ begin
|
|
12
12
|
s.homepage = "http://github.com/joshbuddy/usher"
|
13
13
|
s.authors = ["Joshua Hull"]
|
14
14
|
s.files = FileList["[A-Z]*", "{lib,spec,rails}/**/*"]
|
15
|
-
s.add_dependency 'fuzzyhash', '>=0.0.
|
15
|
+
s.add_dependency 'fuzzyhash', '>=0.0.9'
|
16
16
|
s.rubyforge_project = 'joshbuddy-usher'
|
17
17
|
end
|
18
18
|
Jeweler::GemcutterTasks.new
|
data/VERSION.yml
CHANGED
data/lib/usher/node.rb
CHANGED
@@ -121,7 +121,8 @@ class Usher
|
|
121
121
|
position += matched_part.size
|
122
122
|
params << [next_path.value.name, whole_path.slice!(0, matched_part.size)]
|
123
123
|
next_path.find(usher, request_object, original_path, whole_path.empty? ? whole_path : usher.splitter.url_split(whole_path), params, position)
|
124
|
-
elsif !path.empty? && normal && (next_part = normal[
|
124
|
+
elsif !path.empty? && normal && (next_part = normal[path.first] || normal[nil])
|
125
|
+
part = path.shift
|
125
126
|
position += part.size
|
126
127
|
case next_part.value
|
127
128
|
when Route::Variable::Glob
|
data/lib/usher.rb
CHANGED
@@ -283,6 +283,10 @@ class Usher
|
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
286
|
+
if conditions
|
287
|
+
conditions.keys.all?{|k| request_methods.include?(k)} or raise
|
288
|
+
end
|
289
|
+
|
286
290
|
route = parser.generate_route(path, conditions, requirements, default_values, generate_with)
|
287
291
|
route.to(options) if options && !options.empty?
|
288
292
|
route
|
@@ -10,19 +10,19 @@ def build_request(opts)
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "Usher route recognition" do
|
13
|
-
|
13
|
+
|
14
14
|
before(:each) do
|
15
15
|
@route_set = Usher.new(:request_methods => [:protocol, :domain, :port, :query_string, :remote_ip, :user_agent, :referer, :method, :subdomains])
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
describe 'request conditions' do
|
19
|
-
|
19
|
+
|
20
20
|
it "should recognize a specific domain name" do
|
21
21
|
target_route = @route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http'})
|
22
22
|
@route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https'})
|
23
23
|
@route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http'})).path.route.should == target_route
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should recognize a regex domain name" do
|
27
27
|
target_route = @route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:domain => /^admin.*$/})
|
28
28
|
@route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:domain => 'www.host.com'})
|
@@ -40,7 +40,7 @@ describe "Usher route recognition" do
|
|
40
40
|
@route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'https', :domain => 'admin.spec.com', :user_agent => 'MSIE 6.0'})).path.route.should == target_route_https_msie
|
41
41
|
@route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'https', :domain => 'admin.spec.com', :user_agent => nil})).path.route.should == target_route_https_admin
|
42
42
|
@route_set.recognize(build_request({:method => 'put', :path => '/sample', :protocol => 'wacky', :domain => 'admin.spec.com', :user_agent => nil})).path.route.should == target_route_http_admin_generic
|
43
|
-
|
43
|
+
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should correctly fix that tree if conditionals are used later" do
|
@@ -68,44 +68,51 @@ describe "Usher route recognition" do
|
|
68
68
|
www_product_show_route.should == @route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :subdomains => ['www'], :user_agent => false})).path.route
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
it "should recognize a format-style variable" do
|
73
73
|
target_route = @route_set.add_route('/sample.:format', :controller => 'sample', :action => 'action')
|
74
74
|
@route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'})).should == Usher::Node::Response.new(target_route.paths.first, [[:format , 'html']], nil, "/sample.html")
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
it "should recognize a glob-style variable" do
|
78
78
|
target_route = @route_set.add_route('/sample/*format', :controller => 'sample', :action => 'action')
|
79
79
|
@route_set.recognize(build_request({:method => 'get', :path => '/sample/html/json/apple'})).params.should == [[:format, ['html', 'json', 'apple']]]
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
it "should recgonize only a glob-style variable" do
|
83
83
|
target_route = @route_set.add_route('/*format')
|
84
84
|
response = @route_set.recognize(build_request({:method => 'get', :path => '/sample/html/json/apple'}))
|
85
85
|
response.params.should == [[:format, ['sample', 'html', 'json', 'apple']]]
|
86
86
|
response.path.route.should == target_route
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
it "should recgonize a regex static part" do
|
90
90
|
target_route = @route_set.add_route('/test/part/{one|two}')
|
91
91
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/one'})).path.route.should == target_route
|
92
92
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/two'})).path.route.should == target_route
|
93
93
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/three'})).should == nil
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
|
+
it "should recgonize a two identical regex static parts distinguished by request methods" do
|
97
|
+
get_route = @route_set.add_route('/{:val,test}', :conditions => {:method => 'get'})
|
98
|
+
post_route = @route_set.add_route('/{:val,test}', :conditions => {:method => 'post'})
|
99
|
+
@route_set.recognize(build_request({:method => 'get', :path => '/test'})).path.route.should == get_route
|
100
|
+
@route_set.recognize(build_request({:method => 'post', :path => '/test'})).path.route.should == post_route
|
101
|
+
end
|
102
|
+
|
96
103
|
it "shouldn't accept a nil variable" do
|
97
104
|
target_route = @route_set.add_route('/:one')
|
98
105
|
@route_set.recognize(build_request({:method => 'get', :path => '/one'})).path.route.should == target_route
|
99
106
|
@route_set.recognize(build_request({:method => 'get', :path => '/'})).should == nil
|
100
107
|
end
|
101
|
-
|
108
|
+
|
102
109
|
it "should recgonize a regex static part containing {}'s" do
|
103
110
|
target_route = @route_set.add_route('/test/part/{^o{2,3}$}')
|
104
111
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/oo'})).path.route.should == target_route
|
105
112
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/ooo'})).path.route.should == target_route
|
106
113
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/oooo'})).should == nil
|
107
114
|
end
|
108
|
-
|
115
|
+
|
109
116
|
it "should recgonize a regex single variable" do
|
110
117
|
target_route = @route_set.add_route('/test/part/{:test,hello|again}')
|
111
118
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello'})).path.route.should == target_route
|
@@ -114,20 +121,20 @@ describe "Usher route recognition" do
|
|
114
121
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/again'})).params.should == [[:test, 'again']]
|
115
122
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/world'})).should == nil
|
116
123
|
end
|
117
|
-
|
124
|
+
|
118
125
|
it "should recgonize a regex glob variable" do
|
119
126
|
target_route = @route_set.add_route('/test/part/{*test,^(hello|again|\d+)$}')
|
120
127
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again'})).path.route.should == target_route
|
121
128
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again'})).params.should == [[:test, ['hello', 'again', '123', 'hello', 'again']]]
|
122
129
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/agaim/123/hello/again'})).should == nil
|
123
130
|
end
|
124
|
-
|
131
|
+
|
125
132
|
it "should recgonize a regex glob variable terminated by a static part" do
|
126
133
|
target_route = @route_set.add_route('/test/part/{*test,^(hello|again|\d+)$}/onemore')
|
127
134
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again/onemore'})).path.route.should == target_route
|
128
135
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again/onemore'})).params.should == [[:test, ['hello', 'again', '123', 'hello', 'again']]]
|
129
136
|
end
|
130
|
-
|
137
|
+
|
131
138
|
it "should recgonize a regex glob variable terminated by a single regex variable" do
|
132
139
|
target_route = @route_set.add_route('/test/part/{*test,^(hello|again|\d+)$}/{:party,onemore}')
|
133
140
|
@route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again/onemore'})).path.route.should == target_route
|
@@ -160,24 +167,24 @@ describe "Usher route recognition" do
|
|
160
167
|
response.params.should == [[:format, ['sample', 'html']], [:onemore, ['apple']]]
|
161
168
|
response.path.route.should == target_route
|
162
169
|
end
|
163
|
-
|
170
|
+
|
164
171
|
it "should recgonize only a glob-style variable with a condition" do
|
165
172
|
target_route = @route_set.add_route('/*format', :conditions => {:domain => 'test-domain'})
|
166
173
|
response = @route_set.recognize(build_request({:method => 'get', :path => '/sample/html/json/apple', :domain => 'test-domain'}))
|
167
174
|
response.params.should == [[:format, ['sample', 'html', 'json', 'apple']]]
|
168
175
|
response.path.route.should == target_route
|
169
176
|
end
|
170
|
-
|
177
|
+
|
171
178
|
it "should recognize a format-style literal" do
|
172
179
|
target_route = @route_set.add_route('/:action.html', :controller => 'sample', :action => 'action')
|
173
180
|
@route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'})).should == Usher::Node::Response.new(target_route.paths.first, [[:action , 'sample']], nil, "/sample.html")
|
174
181
|
end
|
175
|
-
|
182
|
+
|
176
183
|
it "should recognize a format-style variable along side another variable" do
|
177
184
|
target_route = @route_set.add_route('/:action.:format', :controller => 'sample', :action => 'action')
|
178
185
|
@route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'})).should == Usher::Node::Response.new(target_route.paths.first, [[:action , 'sample'], [:format, 'html']], nil, '/sample.html')
|
179
186
|
end
|
180
|
-
|
187
|
+
|
181
188
|
it "should use a requirement (proc) on incoming variables" do
|
182
189
|
@route_set.add_route('/:controller/:action/:id', :id => proc{|v| Integer(v)})
|
183
190
|
proc {@route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com'}))}.should_not raise_error(Usher::ValidationException)
|
@@ -188,17 +195,17 @@ describe "Usher route recognition" do
|
|
188
195
|
route = @route_set.add_route('/!asd,qwe/hjk$qwe/:id')
|
189
196
|
@route_set.recognize(build_request({:method => 'get', :path => '/!asd,qwe/hjk$qwe/09AZaz$-_+!*\'', :domain => 'admin.host.com'})).params.rassoc('09AZaz$-_+!*\'').first.should == :id
|
190
197
|
end
|
191
|
-
|
198
|
+
|
192
199
|
it "shouldn't care about non-primary delimiters in the path" do
|
193
200
|
route = @route_set.add_route('/testing/:id/testing2/:id2/:id3')
|
194
201
|
@route_set.recognize(build_request({:method => 'get', :path => '/testing/asd.qwe/testing2/poi.zxc/oiu.asd'})).params.should == [[:id, 'asd.qwe'], [:id2, 'poi.zxc'], [:id3, 'oiu.asd']]
|
195
202
|
end
|
196
|
-
|
203
|
+
|
197
204
|
it "should pick the path when there are mutliple conflicting delimiters" do
|
198
205
|
@route_set.add_route('/:id1(.:format)')
|
199
206
|
@route_set.add_route('/:id1/one(.:format)')
|
200
207
|
@route_set.add_route('/:id1/one/:id2(.:format)')
|
201
|
-
|
208
|
+
|
202
209
|
@route_set.recognize(build_request({:path => '/id1'})).params.should == [[:id1, 'id1']]
|
203
210
|
@route_set.recognize(build_request({:path => '/id1.html'})).params.should == [[:id1, 'id1'], [:format, 'html']]
|
204
211
|
@route_set.recognize(build_request({:path => '/id1/one'})).params.should == [[:id1, 'id1']]
|
@@ -206,20 +213,20 @@ describe "Usher route recognition" do
|
|
206
213
|
@route_set.recognize(build_request({:path => '/id1/one/id2'})).params.should == [[:id1, 'id1'], [:id2, 'id2']]
|
207
214
|
@route_set.recognize(build_request({:path => '/id1/one/id2.html'})).params.should == [[:id1, 'id1'], [:id2, 'id2'], [:format, 'html']]
|
208
215
|
end
|
209
|
-
|
216
|
+
|
210
217
|
it "should recognize a path with an optional compontnet" do
|
211
218
|
@route_set.add_route("/:name(/:surname)", :conditions => {:method => 'get'})
|
212
219
|
result = @route_set.recognize(build_request({:method => 'get', :path => '/homer'}))
|
213
220
|
result.params.should == [[:name, "homer"]]
|
214
221
|
result = @route_set.recognize(build_request({:method => 'get', :path => "/homer/simpson"}))
|
215
222
|
result.params.should == [[:name, "homer"],[:surname, "simpson"]]
|
216
|
-
end
|
217
|
-
|
223
|
+
end
|
224
|
+
|
218
225
|
it "should should raise if malformed variables are used" do
|
219
226
|
@route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:method => 'get'})
|
220
227
|
proc {@route_set.recognize(build_request({:method => 'get', :path => '/products/show/qweasd', :domain => 'admin.host.com'}))}.should raise_error
|
221
228
|
end
|
222
|
-
|
229
|
+
|
223
230
|
it "should recognize multiple optional parts" do
|
224
231
|
target_route = @route_set.add_route('/test(/this)(/too)')
|
225
232
|
@route_set.recognize_path('/test').path.route.should == target_route
|
@@ -227,15 +234,22 @@ describe "Usher route recognition" do
|
|
227
234
|
@route_set.recognize_path('/test/too').path.route.should == target_route
|
228
235
|
@route_set.recognize_path('/test/this/too').path.route.should == target_route
|
229
236
|
end
|
230
|
-
|
237
|
+
|
231
238
|
it "should match between two routes where one is more specific from request conditions" do
|
232
239
|
route_with_post = @route_set.add_route("/foo", :conditions => {:method => 'post'})
|
233
240
|
route = @route_set.add_route("/foo")
|
234
|
-
|
241
|
+
|
235
242
|
@route_set.recognize(build_request({:method => 'post', :path => '/foo'})).path.route.should == route_with_post
|
236
243
|
@route_set.recognize(build_request({:method => 'get', :path => '/foo'})).path.route.should == route
|
237
244
|
end
|
238
245
|
|
246
|
+
it "should only match the specified path of the route when a condition is specified" do
|
247
|
+
@route_set.add_route("/", :conditions => {:method => "get"})
|
248
|
+
@route_set.add_route("/foo")
|
249
|
+
|
250
|
+
@route_set.recognize(build_request(:method => "get", :path => "/asdf")).should be_nil
|
251
|
+
end
|
252
|
+
|
239
253
|
describe "partial recognition" do
|
240
254
|
it "should partially match a route" do
|
241
255
|
route = @route_set.add_route("/foo")
|
@@ -256,20 +270,19 @@ describe "Usher route recognition" do
|
|
256
270
|
@route_set.recognize(build_request(:path => "/foo")).path.route.should == route
|
257
271
|
@route_set.recognize(build_request(:path => "/foo/bar")).should be_nil
|
258
272
|
end
|
259
|
-
|
260
273
|
|
261
274
|
end
|
262
275
|
|
263
276
|
describe "dup safety" do
|
264
|
-
before do
|
277
|
+
before do
|
265
278
|
@route_set.add_route("/foo", :foo => "foo")
|
266
279
|
@r2 = @route_set.dup
|
267
280
|
end
|
268
|
-
|
281
|
+
|
269
282
|
it "should provide a different object" do
|
270
283
|
@route_set.should_not eql(@r2)
|
271
284
|
end
|
272
|
-
|
285
|
+
|
273
286
|
it "should recognize the originals routes in the dup" do
|
274
287
|
@route_set.recognize( build_request(:path => "/foo")).path.route.destination.should == {:foo =>"foo"}
|
275
288
|
@r2.recognize( build_request(:path => "/foo")).path.route.destination.should == {:foo =>"foo"}
|
@@ -280,23 +293,23 @@ describe "Usher route recognition" do
|
|
280
293
|
@r2.recognize( build_request(:path => "/bar")).path.route.destination.should == {:bar => "bar"}
|
281
294
|
@route_set.recognize( build_request(:path => "/bar")).should == nil
|
282
295
|
end
|
283
|
-
|
296
|
+
|
284
297
|
it "should not delete routes added to the dup to the original" do
|
285
298
|
@r2.delete_route("/foo")
|
286
299
|
@route_set.recognize( build_request(:path => "/foo")).path.route.destination.should == {:foo => "foo"}
|
287
300
|
@r2.recognize( build_request(:path => "/foo")).should == nil
|
288
301
|
end
|
289
|
-
|
290
|
-
|
302
|
+
|
303
|
+
|
291
304
|
it "should safely dup with nested ushers" do
|
292
305
|
r1 = Usher.new
|
293
306
|
r2 = Usher.new
|
294
307
|
r3 = Usher.new
|
295
|
-
|
308
|
+
|
296
309
|
r1.add_route("/mounted" ).match_partially!.to(r2)
|
297
310
|
r2.add_route("/inner" ).match_partially!.to(r3)
|
298
311
|
r3.add_route("/baz", :baz => :baz )
|
299
|
-
|
312
|
+
|
300
313
|
r1.recognize(build_request(:path => "/mounted/inner")).path.route.destination.should == r2
|
301
314
|
r4 = r1.dup
|
302
315
|
r4.recognize(build_request(:path => "/mounted/inner")).path.route.destination.should == r2
|
@@ -304,6 +317,6 @@ describe "Usher route recognition" do
|
|
304
317
|
r4.recognize(build_request(:path => "/r3")).path.route.destination.should == r3
|
305
318
|
r1.recognize(build_request(:path => "/r3")).should be_nil
|
306
319
|
end
|
307
|
-
|
320
|
+
|
308
321
|
end
|
309
322
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-11 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.
|
23
|
+
version: 0.0.9
|
24
24
|
version:
|
25
25
|
description: A general purpose routing library
|
26
26
|
email: joshbuddy@gmail.com
|