test/unit/route_matcher_test.rb in merb-0.0.3 vs test/unit/route_matcher_test.rb in merb-0.0.4
- old
+ new
@@ -8,17 +8,13 @@
assert_equal hsh1.values.map(&:to_s).sort_by{|k| k}, hsh2.values.map(&:to_s).sort_by{|k| k}
end
def setup
Merb::RouteMatcher.prepare do |r|
- r.add '/foo/:bar/baz/:id', :class => 'Test', :method => 'foo'
- r.add '/hey/:there/you/:guys', :class => 'Test', :method => 'hello'
- r.add '/these/:routes/are/:sweet', :class => 'Upload', :method => 'start'
- r.add '/h/:a/b/:c/d/:f/g/:id', :class => 'Test'
- r.add '/:class/:method/:id', {}
- r.add '/:class/:method', {}
- r.add '.*', {:class => 'NoRouteFound', :method => 'noroute'}
+ r.add '/foo/:bar/baz/:id', :controller => 'Test', :action => 'foo'
+ r.add '/:controller/:action/:id'
+ r.add '/bar/:*rest', :controller => 'Test', :action => 'glob'
end
end
def test_compiled_statement
r = Merb::RouteMatcher.new
@@ -28,37 +24,22 @@
assert( r.compiled_statement =~ /merge\(@sections\)/)
end
def test_route_matching
routes = Merb::RouteMatcher.new
- assert_same_hash( {:class=>"Test", :id =>"456", :bar =>"123", :method=>"foo"}, routes.route_request("/foo/123/baz/456"))
+ assert_same_hash( {:controller=>"Test", :id =>"456", :bar =>"123", :action=>"foo"}, routes.route_request("/foo/123/baz/456"))
routes = Merb::RouteMatcher.new
- assert_same_hash( {:class=>"Test", :guys =>"girls", :there =>"jon", :method=>"hello"}, routes.route_request( "/hey/jon/you/girls"))
+ assert_same_hash({:controller=>"upload", :id=>"12", :action=>"test"},routes.route_request( "/upload/test/12"))
routes = Merb::RouteMatcher.new
- assert_same_hash({:class=>"upload", :id=>"12", :method=>"test"},routes.route_request( "/upload/test/12"))
+ assert_same_hash({:controller=>"upload", :id=>nil, :action=>"index"},routes.route_request( "/upload"))
routes = Merb::RouteMatcher.new
- assert_same_hash({:class=>"nik", :method=>"nak"},routes.route_request( "/nik/nak"))
+ assert_same_hash({:controller=>"nik", :action=>"nak", :id => nil},routes.route_request( "/nik/nak"))
routes = Merb::RouteMatcher.new
- assert_same_hash({:class=>"lots", :method=>"of", :id => "12"},routes.route_request( "/lots/of/12"))
- routes = Merb::RouteMatcher.new
- assert_same_hash({:class => 'NoRouteFound', :method => 'noroute'},routes.route_request( "/"))
- routes = Merb::RouteMatcher.new
- assert_same_hash({:class => 'NoRouteFound', :method => 'noroute'},routes.route_request( "/dfnasfnafn"))
- routes = Merb::RouteMatcher.new
- assert_same_hash( {:class=>"Upload", :routes=>"234", :sweet=>"yup", :method=>"start"}, routes.route_request( "/these/234/are/yup"))
- routes = Merb::RouteMatcher.new
- assert_same_hash( {:class=>"Test", :a=>"12", :c=>"red", :id=>"12", :f=>"blue"}, routes.route_request( '/h/12/b/red/d/blue/g/12'))
+ assert_same_hash({:controller=>"lots", :action=>"of", :id => "12"},routes.route_request( "/lots/of/12"))
end
- def test_route_doesnt_match
+ def test_catch_all_glob_route
routes = Merb::RouteMatcher.new
- assert_same_hash({:class=>"NoRouteFound", :method=>"noroute"},routes.route_request( '/hdsfvsdfsdfdsf'))
- end
-
- def test_regexes_included_in_compiled_statement
- routes = Merb::RouteMatcher.new
- routes.routes.each do |r|
- assert Regexp.new(r[0]) =~ routes.compiled_statement
- end
- end
-
+ assert_same_hash({:controller=>"Test", :action=>"glob", :rest => "hey/you/guys"},routes.route_request( "/bar/hey/you/guys"))
+ end
+
end