spec/private/recognize_spec.rb in usher-0.7.1 vs spec/private/recognize_spec.rb in usher-0.7.2
- old
+ new
@@ -57,16 +57,10 @@
@route_set.add_route('(/)').to(:test)
@route_set.recognize(build_request({:path => ''})).path.route.destination.should == :test
@route_set.recognize(build_request({:path => '/'})).path.route.destination.should == :test
end
- it "should allow adding a pure regex" do
- @route_set.add_route(/\/test\/(testing|gold)/).to(:test)
- @route_set.recognize(build_request({:path => '/test/testing'})).path.route.destination.should == :test
- @route_set.recognize(build_request({:path => '/test/gold'})).path.route.destination.should == :test
- end
-
it "should correctly fix that tree if conditionals are used later" do
noop_route = @route_set.add_route('/noop', :controller => 'products', :action => 'noop')
product_show_route = @route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:method => 'get'})
@route_set.recognize(build_request({:method => 'get', :path => '/noop', :domain => 'admin.host.com'})).path.route.should == noop_route
@route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com'})).path.route.should == product_show_route
@@ -99,11 +93,13 @@
response.path.route.should == target_route
end
it "should recognize a format-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', :domain => 'admin.host.com'})).should == Usher::Node::Response.new(target_route.paths.first, ['html'], nil, "/sample.html")
+ response = @route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'}))
+ response.path.should == target_route.paths.first
+ response.params.should == [[:format, 'html']]
end
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']]]
@@ -164,11 +160,11 @@
@route_set.recognize(build_request({:method => 'get', :path => '/one'})).path.route.should == target_route
@route_set.recognize(build_request({:method => 'get', :path => '/'})).should == nil
end
it "should recgonize a regex static part containing {}'s" do
- target_route = @route_set.add_route('/test/part/{^o{2,3}$}')
+ target_route = @route_set.add_route('/test/part/{oo,^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
@@ -234,16 +230,20 @@
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, ['sample'], nil, "/sample.html")
+ response = @route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'}))
+ response.path.should == target_route.paths.first
+ response.params.should == [[:action, 'sample']]
end
it "should recognize a format-style variable along side another variable" do
target_route = @route_set.add_route('/:action.:format', :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, ['sample', 'html'], nil, '/sample.html')
+ response = @route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'}))
+ response.path.should == target_route.paths.first
+ response.params.should == [[:action, 'sample'], [:format, 'html']]
end
it "should use a requirement (proc) on incoming variables" do
@route_set.add_route('/:controller/:action/:id', :id => proc{|v| Integer(v)})
proc {@route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com'}))}.should_not raise_error(Usher::ValidationException)
@@ -313,17 +313,17 @@
route_lower = @route_set.add_route("/foo", :conditions => {:protocol => 'https'}, :priority => 1)
route_higher = @route_set.add_route("/foo", :conditions => {:method => 'post'}, :priority => 2)
@route_set.recognize(build_request({:method => 'post', :protocol => 'https', :path => '/foo'})).path.route.should == route_higher
- @route_set.clear!
+ @route_set.reset!
route_higher = @route_set.add_route("/foo", :conditions => {:protocol => 'https'}, :priority => 2)
route_lower = @route_set.add_route("/foo", :conditions => {:method => 'post'}, :priority => 1)
@route_set.recognize(build_request({:method => 'post', :protocol => 'https', :path => '/foo'})).path.route.should == route_higher
- @route_set.clear!
+ @route_set.reset!
end
it "should only match the specified path of the route when a condition is specified" do
@route_set.add_route("/", :conditions => {:method => "get"})
@route_set.add_route("/foo")