spec/private/recognize_spec.rb in usher-0.5.13 vs spec/private/recognize_spec.rb in usher-0.6.0

- old
+ new

@@ -45,10 +45,27 @@ @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 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 @@ -71,10 +88,19 @@ www_product_show_route.should == @route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :subdomains => 'admin', :user_agent => true})).path.route www_product_show_route.should == @route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :subdomains => 'www', :user_agent => false})).path.route 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") end @@ -366,6 +392,7 @@ r4.recognize(build_request(:path => "/r3")).path.route.destination.should == r3 r1.recognize(build_request(:path => "/r3")).should be_nil end end + end