Sha256: 0f82987bf10274e59fc590d301f1328ae2d45e47f888b26d37e2804198b2e498

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')

require 'test/unit'
require 'nitro/dispatcher'

class TC_Dispatcher < Test::Unit::TestCase # :nodoc: all

	class MainController < N::Controller
	end

	class BlogController < N::Controller
	end
	
	def setup
		@d = N::Dispatcher.new({
			:root => MainController,
			'blog' => BlogController
		})

		@dxml = N::Dispatcher.new({
			:root => MainController,
			'blog' => BlogController
		})
		@dxml.add_api('xml', 'xml')
	end
	
	def teardown
		@d = @dxml = nil
	end

	def test_initialize
		d = N::Dispatcher.new(BlogController)
		assert_equal BlogController, d.controllers[:root]
	end
	
	def test_dispatch
		klass, action = @d.dispatch('/blog/list')
		assert_equal BlogController, klass
		assert_equal '__xhtml__list', action
		
		klass, action, ctype  = @d.dispatch('/blog')
		assert_equal BlogController, klass
		assert_equal '__xhtml__index', action
		assert_equal 'text/html', ctype 
		
		klass, action, ctype = @d.dispatch('/login')
		assert_equal MainController, klass
		assert_equal '__xhtml__login', action
		
		klass, action = @d.dispatch('/')
		assert_equal MainController, klass
		assert_equal '__xhtml__index', action
	
		# multi-api dispatcher. 

		# no xml prefix, use xhtml api.
		klass, action = @dxml.dispatch('/blog/list')
		assert_equal BlogController, klass
		assert_equal '__xhtml__list', action

		# xml prefix, use xml api.
		klass, action = @dxml.dispatch('/xml/blog/list')
		assert_equal BlogController, klass
		assert_equal '__xml__list', action
	end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.13.0 test/nitro/tc_dispatcher.rb
nitro-0.14.0 test/nitro/tc_dispatcher.rb