Sha256: 3f61bf2f7b3b1cb50499f77af8fb570a126ecd213450e415dc03e23b7e321f15

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

require File.join(File.dirname(__FILE__), 'CONFIG.rb')

require 'test/unit'

require 'nitro'

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

  Glue::Template.root = File.expand_path(File.join('..', 'public'))

  class MyContext
    attr_accessor :headers
    
    def initialize
      @headers = {}
    end
  end
  
  class MainController < Controller
  end

  class BlogController < Controller
    def list
    end

    def another__very_litle
    end
  end
  
  def setup
    @d = Dispatcher.new({
      '/' => MainController,
      '/blog' => BlogController
    })

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

  def test_initialize
    d = Dispatcher.new(BlogController)
    assert_equal BlogController, d.controllers['/']
  end
  
  def test_dispatch
    klass, action = @d.dispatch('/blog/list', @ctx)
    assert_equal BlogController, klass
    assert_equal 'list_action', action
    
    klass, action = @d.dispatch('/blog/another/very_litle', @ctx)
    assert_equal BlogController, klass
    assert_equal 'another__very_litle_action', action

    assert_raises(NoActionError) do
      @d.dispatch('a/nonexistent/action')
    end
=begin
    klass, action = @d.dispatch('/another/litle/list', @ctx)
    assert_equal MainController, klass
    assert_equal 'another__litle__list_action', action
    
    klass, action = @d.dispatch('/blog', @ctx)
    assert_equal BlogController, klass
    assert_equal 'index_action', action
    
    klass, action, ctype = @d.dispatch('/login', @ctx)
    assert_equal MainController, klass
    assert_equal 'login_action', action
    
    klass, action = @d.dispatch('/', @ctx)
    assert_equal MainController, klass
    assert_equal 'index_action', action
=end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.30.0 test/nitro/tc_dispatcher.rb
nitro-0.31.0 test/nitro/tc_dispatcher.rb