require 'test/unit' require 'time' class TestTimeStamp < Test::Unit::TestCase include Marjoree def setup @timestamp = '2006-09-22 11:31:35.923' $db.do( "CREATE TABLE TEST_TABLE( time DATETIME NOT NULL )" ) $db.do( "INSERT INTO TEST_TABLE ( time ) VALUES( '#{@timestamp}' )" ) end def test_timestamp_correct expected = ExpectedResultSet.new expected.columns = [:time] expected.rows << [ODBC::TimeStamp.new( @timestamp )] result_set = select "TEST_TABLE" assert_results( expected, result_set) end def test_timestamp_incorrect expected = ExpectedResultSet.new expected.columns = [:time] expected.rows << [ODBC::TimeStamp.new( '2006-09-23' )] result_set = select "TEST_TABLE" assert_not_equal_results( expected, result_set) end def test_timestamp_formatting time_text = '2006-09-22 11:31:35' testee = ODBC::TimeStamp.new( time_text ) assert_equal( time_text, testee.to_s ) time_text = '2006-09-22 11:31:35.923' testee = ODBC::TimeStamp.new( time_text ) assert_equal( time_text, testee.to_s ) end def test_from_date date = Time.parse '10/10/06 15:30:35' testee = ODBC::TimeStamp.from_date(date) assert_equal '2006-10-10 00:00:00', testee.to_s end def test_from_time time = Time.parse '10/10/06 15:30:35' testee = ODBC::TimeStamp.from_time(time) assert_equal '2006-10-10 15:30:35', testee.to_s end def teardown $db.do( "DROP TABLE TEST_TABLE" ) end end