spec/private/recognize_spec.rb in usher-0.5.10 vs spec/private/recognize_spec.rb in usher-0.5.11

- old
+ new

@@ -15,10 +15,15 @@ @route_set = Usher.new(:request_methods => [:protocol, :domain, :port, :query_string, :remote_ip, :user_agent, :referer, :method, :subdomains]) end describe 'request conditions' do + it "should ignore an unrecognized route" do + target_route = @route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http'}).unrecognizable! + @route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http'})).should be_nil + end + it "should recognize a specific domain name" do target_route = @route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http'}) @route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https'}) @route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http'})).path.route.should == target_route end @@ -77,10 +82,39 @@ 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 recognize variables between multi-char delimiters" do + @route_set = Usher.new(:delimiters => ['%28', '%29', '/', '.']) + target_route = @route_set.add_route('/cheese%28:kind%29', :controller => 'sample', :action => 'action') + + response = @route_set.recognize(build_request({:method => 'get', :path => '/cheese%28parmesan%29'})) + response.path.route.should == target_route + response.params.should == [[:kind , 'parmesan']] + end + + it "should recognize route with escaped characters as delimiters" do + @route_set = Usher.new(:delimiters => ['/', '.', '\\(', '\\)']) + + target_route = @route_set.add_route('/cheese\\(:kind\\)', :controller => 'sample', :action => 'action') + + response = @route_set.recognize(build_request({:method => 'get', :path => '/cheese(parmesan)'})) + response.should_not be_nil + response.path.route.should == target_route + response.params.should == [[:kind , 'parmesan']] + end + + it "should recognize route with consecutive delimiters" do + @route_set = Usher.new(:delimiters => ['!', '/']) + target_route = @route_set.add_route('/cheese/!:kind', :controller => 'sample', :action => 'action') + + response = @route_set.recognize(build_request({:method => 'get', :path => '/cheese/!parmesan'})) + response.path.route.should == target_route + response.params.should == [[:kind , 'parmesan']] + 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 @@ -92,13 +126,13 @@ @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 two identical regex static parts distinguished by request methods" do - get_route = @route_set.add_route('/{:val,test}', :conditions => {:method => 'get'}) - post_route = @route_set.add_route('/{:val,test}', :conditions => {:method => 'post'}) - @route_set.recognize(build_request({:method => 'get', :path => '/test'})).path.route.should == get_route - @route_set.recognize(build_request({:method => 'post', :path => '/test'})).path.route.should == post_route + get_route = @route_set.add_route('/test1/{:val,test}', :conditions => {:method => 'get'}) + post_route = @route_set.add_route('/test1/{:val,test}', :conditions => {:method => 'post'}) + @route_set.recognize(build_request({:method => 'get', :path => '/test1/test'})).path.route.should == get_route + @route_set.recognize(build_request({:method => 'post', :path => '/test1/test'})).path.route.should == post_route end it "shouldn't accept a nil variable" do target_route = @route_set.add_route('/:one') @route_set.recognize(build_request({:method => 'get', :path => '/one'})).path.route.should == target_route