Sha256: ae59b3d2328239d1ec8e19ce01bac96a99037d18e10cc7753c7805eb94c5fc5a

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 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
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.

		assert(SubMsg.__props)
		assert_equal(Msg.__props.size(), 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 # module

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nitro-0.10.0 test/glue/tc_property.rb
nitro-0.11.0 test/glue/tc_property.rb
nitro-0.12.0 test/glue/tc_property.rb