Sha256: e67b179cbc10b10e50dcff7dc3124b12c6e4077069bab1e8846c84618afba2cc

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

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

require 'test/unit'
require 'ostruct'

require 'glue'
require 'glue/logger'
require 'nitro/context'
require 'nitro/dispatcher'
require 'nitro/controller'

class TC_Controller < Test::Unit::TestCase # :nodoc: all
  include Nitro
  
  class Blog2Controller < Controller
    attr_reader :aflag, :tflag

    @template_root = File.expand_path(Nitro::LibPath + '../../test/public/blog')

    def list
      @aflag = true 
    end
  end
  
  def setup
    @disp = Dispatcher.new({
      '/blog' => Blog2Controller,
    })
    @conf = OpenStruct.new
    @conf.dispatcher = @disp
  end
  
  def test_render
    ctx = Context.new(@conf)
    ctx.headers = {}
    ctx.params = {}
    ctx.headers['REQUEST_URI'] = '/blog/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 true, c.aflag
    assert_equal true, $include1
    assert_equal true, $include2

    # the template is compiled
    assert_equal true, c.tflag
  end

  def test_action_methods
    # aflag/tflag are counted too!
    assert_equal 3, Blog2Controller.action_methods.size
    assert Blog2Controller.action_methods.include?('list')
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.21.0 test/nitro/tc_controller.rb
nitro-0.21.2 test/nitro/tc_controller.rb