require 'test/unit' class TestUpdateOnMarjoree < Test::Unit::TestCase include Marjoree def setup $db.do( "CREATE TABLE TEST_TABLE( id int NOT NULL, value varchar(20) NOT NULL )" ) $db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 0, 'stuff' )" ) $db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 1, 'more stuff' )" ) end def test_update assert( contains?( "TEST_TABLE", :id => 0, :value => 'stuff' ) ) update( "TEST_TABLE", { :id => 0 }, :value => 'more stuff' ) assert( !contains?( "TEST_TABLE", :id => 0, :value => 'stuff' ) ) assert( contains?( "TEST_TABLE", :id => 0, :value => 'more stuff' ) ) end def test_update_with_no_where_clause assert( contains?( "TEST_TABLE", :id => 0, :value => 'stuff' ) ) update( "TEST_TABLE", {}, :value => 'more stuff' ) assert( !contains?( "TEST_TABLE", :id => 0, :value => 'stuff' ) ) assert( contains?( "TEST_TABLE", :id => 0, :value => 'more stuff' ) ) end def test_update_with_bad_table begin update( "TABLE_NOT_INT_DB", { :id => 0 }, :value => 'more stuff' ) fail rescue ODBC::Error end end def test_update_with_bad_column_header begin update( "TEST_TABLE", { :jimmy => 0 }, :value => 'more stuff' ) fail rescue ODBC::Error end end def test_update_with_column_value_type begin update( "TEST_TABLE", { :id => 'bad' }, :value => 'more stuff' ) fail rescue ODBC::Error end end def teardown $db.do( "TRUNCATE TABLE TEST_TABLE" ) $db.do( "DROP TABLE TEST_TABLE" ) end end