Sha256: d2e508fa700c7d8992e19067bac47fbfc568c9776182575be96e340b5e89f74c

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

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

require 'test/unit'
require 'ostruct'

require 'glue/configuration'
require 'nitro/router'

class IdController; end
class AdminController; end

class AbstractRouter
  include Nitro::Router
end

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

  def setup
    @r = AbstractRouter.new

    @r.add_route(%r{rewritten/url/(.*)}, :controller => IdController, :action => :register, :param => :name)
    @r.add_route(%r{another/zelo/(.*)/(.*)}, :controller => AdminController, :action => :kick, :params => [:name, :age])
    @r.add_route(%r{cool/(.*)_(.*).html}, :controller => AdminController, :action => :long, :params => [:name, :age])
  end
  
  def teardown
    @r = nil
  end
    
  def test_decode
    c, a, params = @r.decode_route('rewritten/url/gmosx')
    assert_equal IdController, c   
    assert_equal :register, a 
    assert_equal 'gmosx', params['name']  
    
    c, a, params = @r.decode_route('another/zelo/gmosx/32')
    assert_equal AdminController, c   
    assert_equal :kick, a 
    assert_equal 'gmosx', params['name']      
    assert_equal '32', params['age']

    c, a, params = @r.decode_route('cool/gmosx_32.html')
    assert_equal AdminController, c   
    assert_equal :long, a 
    assert_equal 'gmosx', params['name']      
    assert_equal '32', params['age']
    
    assert_equal false, @r.decode_route('this/doesnt/decode')      
  end

  def test_encode
    assert_equal 'rewritten/url/gmosx', @r.encode_route(IdController, :register, :name, 'gmosx')
    assert_equal 'cool/gmosx_32.html', @r.encode_route(AdminController, :long, :name, 'gmosx', :age, 32)
    assert_equal false, @r.encode_route(AdminController, :invalid, :gender, 'male')
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.29.0 test/nitro/tc_router.rb