spec/private/recognize_spec.rb in joshbuddy-usher-0.4.2 vs spec/private/recognize_spec.rb in joshbuddy-usher-0.4.3

- old
+ new

@@ -8,12 +8,10 @@ request.should_receive(k).any_number_of_times.and_return(v) end request end -SampleController = Object.new - describe "Usher route recognition" do before(:each) do route_set.reset! end @@ -81,10 +79,16 @@ target_route = route_set.add_route('/test/part/{*test,^(hello|again|\d+)$}/onemore') route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again/onemore'})).path.route.should == target_route route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again/onemore'})).params.should == [[:test, ['hello', 'again', '123', 'hello', 'again']]] end + it "should recgonize a regex glob variable terminated by a single regex variable" do + target_route = route_set.add_route('/test/part/{*test,^(hello|again|\d+)$}/{:party,onemore}') + route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again/onemore'})).path.route.should == target_route + route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again/onemore'})).params.should == [[:test, ['hello', 'again', '123', 'hello', 'again']], [:party, 'onemore']] + 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 @@ -141,15 +145,10 @@ admin_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 - it "should use a transformer (proc) on incoming variables" do - route_set.add_route('/:controller/:action/:id', :transformers => {:id => proc{|v| v.to_i}}) - route_set.recognize(build_request({:method => 'get', :path => '/products/show/123asd', :domain => 'admin.host.com'})).params.rassoc(123).first.should == :id - 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 proc {route_set.recognize(build_request({:method => 'get', :path => '/products/show/123asd', :domain => 'admin.host.com'}))}.should raise_error Usher::ValidationException end @@ -162,21 +161,12 @@ it "shouldn't care about non-primary delimiters in the path" do route = route_set.add_route('/testing/:id/testing2/:id2/:id3') route_set.recognize(build_request({:method => 'get', :path => '/testing/asd.qwe/testing2/poi.zxc/oiu.asd'})).params.should == [[:id, 'asd.qwe'], [:id2, 'poi.zxc'], [:id3, 'oiu.asd']] end - it "should use a transformer (symbol) on incoming variables" do - route_set.add_route('/:controller/:action/:id', :transformers => {:id => :to_i}) - route_set.recognize(build_request({:method => 'get', :path => '/products/show/123asd', :domain => 'admin.host.com'})).params.rassoc(123).first.should == :id - end - it "should should raise if malformed variables are used" do route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:method => 'get'}) proc {route_set.recognize(build_request({:method => 'get', :path => '/products/show/qweasd', :domain => 'admin.host.com'}))}.should raise_error end - it "should should raise if transformer proc raises (anything)" do - route_set.add_route('/products/show/:id', :transformers => {:id => proc{|v| Integer(v)}}) - proc {route_set.recognize(build_request({:method => 'get', :path => '/products/show/qweasd', :domain => 'admin.host.com'}))}.should raise_error(Usher::ValidationException) - end end \ No newline at end of file