spec/recognize_spec.rb in joshbuddy-usher-0.3.6 vs spec/recognize_spec.rb in joshbuddy-usher-0.4.0
- old
+ new
@@ -38,9 +38,53 @@
it "should recognize a glob-style variable" do
target_route = route_set.add_route('/sample/*format', :controller => 'sample', :action => 'action')
route_set.recognize(build_request({:method => 'get', :path => '/sample/html/json/apple'})).params.should == [[:format, ['html', 'json', 'apple']]]
end
+ it "should recgonize only a glob-style variable" do
+ target_route = route_set.add_route('/*format')
+ response = route_set.recognize(build_request({:method => 'get', :path => '/sample/html/json/apple'}))
+ response.params.should == [[:format, ['sample', 'html', 'json', 'apple']]]
+ response.path.route.should == target_route
+ end
+
+ it "should recgonize a regex static part" do
+ target_route = route_set.add_route('/test/part/{one|two}')
+ route_set.recognize(build_request({:method => 'get', :path => '/test/part/one'})).path.route.should == target_route
+ route_set.recognize(build_request({:method => 'get', :path => '/test/part/two'})).path.route.should == target_route
+ route_set.recognize(build_request({:method => 'get', :path => '/test/part/three'})).should == nil
+ end
+
+ it "should recgonize a regex static part containing {}'s" do
+ target_route = route_set.add_route('/test/part/{^o{2,3}$}')
+ route_set.recognize(build_request({:method => 'get', :path => '/test/part/oo'})).path.route.should == target_route
+ route_set.recognize(build_request({:method => 'get', :path => '/test/part/ooo'})).path.route.should == target_route
+ route_set.recognize(build_request({:method => 'get', :path => '/test/part/oooo'})).should == nil
+ end
+
+ it "should recgonize a regex static part containing {}'s" do
+ target_route = route_set.add_route('/test/part/{:test,hello|again}')
+ route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello'})).path.route.should == target_route
+ route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello'})).params.should == [[:test, 'hello']]
+ route_set.recognize(build_request({:method => 'get', :path => '/test/part/again'})).path.route.should == target_route
+ route_set.recognize(build_request({:method => 'get', :path => '/test/part/again'})).params.should == [[:test, 'again']]
+ route_set.recognize(build_request({:method => 'get', :path => '/test/part/world'})).should == nil
+ end
+
+ it "should recgonize two glob-style variables separated by a static part" do
+ target_route = route_set.add_route('/*format/innovate/*onemore')
+ response = route_set.recognize(build_request({:method => 'get', :path => '/sample/html/innovate/apple'}))
+ response.params.should == [[:format, ['sample', 'html']], [:onemore, ['apple']]]
+ response.path.route.should == target_route
+ end
+
+ it "should recgonize only a glob-style variable with a condition" do
+ target_route = route_set.add_route('/*format', :conditions => {:domain => 'test-domain'})
+ response = route_set.recognize(build_request({:method => 'get', :path => '/sample/html/json/apple', :domain => 'test-domain'}))
+ response.params.should == [[:format, ['sample', 'html', 'json', 'apple']]]
+ response.path.route.should == target_route
+ end
+
it "should recognize a format-style literal" do
target_route = route_set.add_route('/:action.html', :controller => 'sample', :action => 'action')
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']])
end
\ No newline at end of file