spec/private/recognize_spec.rb in usher-0.6.3 vs spec/private/recognize_spec.rb in usher-0.6.4
- old
+ new
@@ -45,22 +45,22 @@
@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
@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
@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
end
-
+
it "should recognize an empty path" do
@route_set.add_route('').to(:test)
@route_set.recognize(build_request({:path => ''})).path.route.destination.should == :test
end
-
+
it "should recognize an optionally empty path" do
@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
@@ -90,20 +90,20 @@
end
end
it "should recognize path with a trailing slash" do
@route_set = Usher.new(:request_methods => [:protocol, :domain, :port, :query_string, :remote_ip, :user_agent, :referer, :method, :subdomains], :ignore_trailing_delimiters => true)
-
+
target_route = @route_set.add_route('/path', :controller => 'sample', :action => 'action')
response = @route_set.recognize(build_request({:method => 'get', :path => '/path/'}))
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, [[:format , 'html']], nil, "/sample.html")
+ @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")
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']]]
@@ -234,16 +234,16 @@
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']], nil, "/sample.html")
+ @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")
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, [[:action , 'sample'], [:format, 'html']], nil, '/sample.html')
+ @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')
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)
@@ -334,11 +334,15 @@
describe "partial recognition" do
it "should partially match a route" do
route = @route_set.add_route("/foo")
route.match_partially!
- @route_set.recognize(build_request(:method => "get", :path => "/foo/bar")).should == Usher::Node::Response.new(route.paths.first, [], "/bar", '/foo')
+ response = @route_set.recognize(build_request(:method => "get", :path => "/foo/bar"))
+ response.partial_match?.should be_true
+ response.params.should == []
+ response.remaining_path.should == '/bar'
+ response.matched_path.should == '/foo'
end
it "should partially match a route and use request conditions" do
route = @route_set.add_route("/foo", :conditions => {:method => 'get'})
route.match_partially!
@@ -399,7 +403,7 @@
r4.recognize(build_request(:path => "/r3")).path.route.destination.should == r3
r1.recognize(build_request(:path => "/r3")).should be_nil
end
end
-
+
end