require File.join(File.dirname(__FILE__), 'CONFIG.rb') require 'test/unit' require 'ostruct' require 'glue' require 'glue/logger' require 'nitro' class TC_Controller < Test::Unit::TestCase # :nodoc: all include Nitro class FirstController < Controller def list end end class SecondController < Controller attr_reader :aqflag, :tflag def self.setup_template_root(path) @template_root << File.expand_path(File.join(Nitro::LibPath, "../test/public/#{path}")) end def list @aqflag = true end def another(oid) # nop end private def encode_myself encode_url :list end def encode_first encode_url FirstController, :list end end def setup @disp = Dispatcher.new '/first' => FirstController, '/second' => SecondController @conf = OpenStruct.new @conf.dispatcher = @disp end def test_render ctx = Context.new(@conf) ctx.headers = {} ctx.params = {} ctx.headers['REQUEST_URI'] = '/second/list' ctx.instance_eval '@session = {}' klass, action = ctx.dispatcher.dispatch(ctx.path, ctx) c = klass.new(ctx) begin c.send(action) rescue RenderExit # drink end assert_equal('/second/list', c.send(:encode_myself)) assert_equal('/first/list', c.send(:encode_first)) # handle action with arity. assert_equal('/second/another/32', c.send(:encode_url, :another, :oid, 32)) assert_equal true, c.aqflag =begin # if anybody has an idea what this is for, go, fix it :) assert_equal true, $include1 assert_equal true, $include2 # the template is compiled assert_equal true, c.tflag =end end def test_action_methods assert_equal ['list'], FirstController.action_methods assert_equal 1, FirstController.action_methods.size assert_equal 4, SecondController.action_methods.size assert FirstController.action_methods.include?('list') assert SecondController.action_methods.include?('list') end def test_encode_decode_methods end def test_mount_path assert_equal '/first', FirstController.mount_path assert_equal '/second', SecondController.mount_path # path is private assert_equal '/first', FirstController.allocate.send(:mount_path) assert_equal '/second', SecondController.allocate.send(:mount_path) end end