spec/private/recognize_spec.rb in usher-0.5.4 vs spec/private/recognize_spec.rb in usher-0.5.5

- old
+ new

@@ -193,10 +193,18 @@ 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 recognize a path with an optional compontnet" do + route_set.add_route("/:name(/:surname)", :conditions => {:method => 'get'}) + result = route_set.recognize(build_request({:method => 'get', :path => '/homer'})) + result.params.should == [[:name, "homer"]] + result = route_set.recognize(build_request({:method => 'get', :path => "/homer/simpson"})) + result.params.should == [[:name, "homer"],[:surname, "simpson"]] + 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 @@ -226,23 +234,23 @@ it "should provide a different object" do route_set.should_not eql(@r2) end it "should recognize the originals routes in the dup" do - route_set.recognize(build_request(:path => "/foo")).path.route.destination.should == {:foo =>"foo"} - @r2.recognize( build_request(:path => "/foo")).path.route.destination.should == {:foo =>"foo"} + route_set.recognize( build_request(:path => "/foo")).path.route.destination.should == {:foo =>"foo"} + @r2.recognize( build_request(:path => "/foo")).path.route.destination.should == {:foo =>"foo"} end it "should not add routes added to the dup to the original" do @r2.add_route("/bar", :bar => "bar") @r2.recognize( build_request(:path => "/bar")).path.route.destination.should == {:bar => "bar"} route_set.recognize( build_request(:path => "/bar")).should == nil end it "should not delete routes added to the dup to the original" do @r2.delete_route("/foo") - route_set.recognize( build_request(:path => "/foo")).path.route.destination.should == {:foo => "foo"} - @r2.recognize( build_request(:path => "/foo")).should == nil + route_set.recognize( build_request(:path => "/foo")).path.route.destination.should == {:foo => "foo"} + @r2.recognize( build_request(:path => "/foo")).should == nil end it "should safely dup with nested ushers" do r1 = Usher.new \ No newline at end of file