Sha256: 2d927e215611eee61be4f14230d0c93e8159ce070b42d8556f71af8e2ff27ed2

Contents?: true

Size: 1.78 KB

Versions: 5

Compression:

Stored size: 1.78 KB

Contents

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

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

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

	class MainController < Controller
	end

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

		@dxml = Dispatcher.new({
			:root => MainController,
			'blog' => BlogController,
			# FIXME: this is a hack!
			'xml:blog' => BlogController
		})
	end
	
	def teardown
		@d = @dxml = nil
	end

	def test_initialize
		d = 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 'list_action', action
		
		klass, action = @d.dispatch('/blog/another/very_litle/list')
		assert_equal BlogController, klass
		assert_equal 'another__very_litle__list_action', action
		
		klass, action = @d.dispatch('/another/litle/list')
		assert_equal MainController, klass
		assert_equal 'another__litle__list_action', action
		
		klass, action = @d.dispatch('/blog')
		assert_equal BlogController, klass
		assert_equal 'index_action', action
		
		klass, action, ctype = @d.dispatch('/login')
		assert_equal MainController, klass
		assert_equal 'login_action', action
		
		klass, action = @d.dispatch('/')
		assert_equal MainController, klass
		assert_equal 'index_action', action
	
		# multi-api dispatcher. 

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

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

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nitro-0.16.0 test/nitro/tc_dispatcher.rb
nitro-0.17.0 test/nitro/tc_dispatcher.rb
nitro-0.18.0 test/nitro/tc_dispatcher.rb
nitro-0.18.1 test/nitro/tc_dispatcher.rb
nitro-0.19.0 test/nitro/tc_dispatcher.rb