Sha256: bc16065278e49b04d6f09b68ae0c05ddcb332759132c09a72b2df3649241ed3e

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

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

require 'test/unit'

require 'nitro'
require 'nitro/render'
require 'facet/mock'

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

  class ContextMock < Mock
    mock :response_headers, {}
    mock :host_url, 'http://www.nitroproject.org'
  end

  class TestController < Controller
  end

  def setup
    ctx =  ContextMock.new
    @controller = TestController.new(ctx)
  end

  def teardown
    @controller = nil
  end

  def test_redirect
    # relative url, the controller base_url is prepended (uh, really?)
    redirect 'hello'
    assert_equal 'http://www.nitroproject.org/hello', @controller.context.response_headers['location']

    # absolute url, use as is.
    redirect '/main'
    assert_equal 'http://www.nitroproject.org/main', @controller.context.response_headers['location']

    # http://, use as is.
    redirect 'http://www.gmosx.com/info'
    assert_equal 'http://www.gmosx.com/info', @controller.context.response_headers['location']

    redirect 'edit/Home'
    assert_equal 'http://www.nitroproject.org/edit/Home', @controller.context.response_headers['location']

    redirect '/edit/Home'
    assert_equal 'http://www.nitroproject.org/edit/Home', @controller.context.response_headers['location']    
  end

  def redirect(*args)
    begin
      @controller.send :redirect, *args
    rescue Nitro::RenderExit
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.40.0 test/nitro/tc_render.rb