Sha256: b74a047a784701fe077062b715e445770dc448340c7eb430506c692aa365a6d9

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 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
	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, base = @d.dispatch('/blog')
		assert_equal BlogController, klass
		assert_equal '__xhtml__index', action
		assert_equal 'root/blog', base
		
		klass, action, base = @d.dispatch('/login')
		assert_equal MainController, klass
		assert_equal '__xhtml__login', action
		assert_equal 'root', base
		
		klass, action, base = @d.dispatch('/')
		assert_equal MainController, klass
		assert_equal '__xhtml__index', action
		assert_equal 'root', base
	
		# 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.10.0 test/nitro/tc_dispatcher.rb
nitro-0.11.0 test/nitro/tc_dispatcher.rb