Sha256: 82f45ef26a1e275dd8abf0bae49e352a8a91ff812323b7aeaf4a5a194847e64a

Contents?: true

Size: 1.92 KB

Versions: 4

Compression:

Stored size: 1.92 KB

Contents

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

require 'test/unit'

require 'og'
require 'glue/logger'
require 'glue/property'

def VarChar(size)
  return String, :sql => "VARCHAR(#{ size })"
end
NotNull = {:sql => "NOT NULL"}.freeze
Null = {:sql => "NULL"}.freeze

Property.type_checking = false

module Test # :nodoc: all

class Msg
  include Og::Unmanageable
  
  prop Fixnum, :owner_oid
  prop_accessor :val1, :val2, :val3, Fixnum, :sql => "smallint"
  prop_accessor :title, :body, String
  prop_accessor :test, String, :sql => "char(10) NOT NULL"
  prop_accessor :count, Fixnum
  prop_accessor :create_time, Time  

  # a marshaled property
  prop_accessor Array, :options

  # property with macro arguments!
  prop_accessor :address, VarChar(30), NotNull
  
  def initialize
    @create_time = Time.now
    @options = []
  end

end

class SubMsg < Msg
  # to avoid conflicts with tc_og.rb
  include Og::Unmanageable
  
  # duplicate definition with different type!
  prop_accessor :count, Float

  # another property
  prop_accessor :another, Fixnum
end

class TC_N_Properties < Test::Unit::TestCase

  def setup
    @msg1 = Msg.new
  end

  def teardown
    @msg1 = nil
  end

  def test_props
    
    # bug: props for subclasses.
    # bug: props propagated to base classes.

    assert(SubMsg.__props)
    assert_equal(Msg.__props.size(), SubMsg.__props.size() - 1)

    assert_equal(11, Msg.__props.size)
    assert_equal(12, SubMsg.__props.size)

    # bug: duplicate definition       
    
    assert_equal(Float, SubMsg.__props.find { |p| :count == p.symbol }.klass)

    # dont force conversion
    
    @msg1.count = 2.4
    assert_equal(Float, @msg1.count.class)

    # force conversion
    
    @msg1.__force_count(2.4)
    assert_equal(Fixnum, @msg1.count.class)    
  end

  def test_macro_params
    sql = Msg.__props.find { |p| :address == p.symbol }.meta[:sql]
    assert_equal 'VARCHAR(30) NOT NULL', sql
  end
  
end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
glue-0.21.0 test/glue/tc_property.rb
glue-0.21.2 test/glue/tc_property.rb
glue-0.22.0 test/glue/tc_property.rb
glue-0.23.0 test/glue/tc_property.rb