Sha256: d239ffd9ec18a89edf51061a8ecdcf0462587442da2d522af52dbc28a9a8b5cd
Contents?: true
Size: 1.83 KB
Versions: 6
Compression:
Stored size: 1.83 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
6 entries across 6 versions & 1 rubygems