Sha256: 128ec291b4b2e7ce3c03a0ae9cdfab39545c7c0f14a0e7cd63b8f65127628abb
Contents?: true
Size: 1.92 KB
Versions: 3
Compression:
Stored size: 1.92 KB
Contents
require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../../lib/merb/merb_router' require File.dirname(__FILE__) + '/../../lib/merb/merb_utils' require 'set' class RouteMatcherTest < Test::Unit::TestCase def assert_same_hash(hsh1, hsh2) assert_equal hsh1.keys.map(&:to_s).sort, hsh2.keys.map(&:to_s).sort assert_equal hsh1.values.map(&:to_s).sort, hsh2.values.map(&:to_s).sort end def setup Merb::RouteMatcher.prepare do |r| 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 assert( r.compiled_statement.kind_of?(String)) assert( r.compiled_statement =~ /lambda\{\|path/) assert( r.compiled_statement =~ /Regexp\.new/) assert( r.compiled_statement =~ /merge\(@sections\)/) end def test_route_matching routes = Merb::RouteMatcher.new 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({:controller=>"upload", :id=>"12", :action=>"test"},routes.route_request( "/upload/test/12")) routes = Merb::RouteMatcher.new assert_same_hash({:controller=>"upload", :id=>nil, :action=>"index"},routes.route_request( "/upload")) routes = Merb::RouteMatcher.new assert_same_hash({:controller=>"nik", :action=>"nak", :id => nil},routes.route_request( "/nik/nak")) routes = Merb::RouteMatcher.new assert_same_hash({:controller=>"lots", :action=>"of", :id => "12"},routes.route_request( "/lots/of/12")) end def test_catch_all_glob_route routes = Merb::RouteMatcher.new assert_same_hash({:controller=>"Test", :action=>"glob", :rest => "hey/you/guys"},routes.route_request( "/bar/hey/you/guys")) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
merb-0.0.8 | test/unit/route_matcher_test.rb |
merb-0.0.6 | test/unit/route_matcher_test.rb |
merb-0.0.7 | test/unit/route_matcher_test.rb |