Class: Test::Unit::TestCase
- Inherits:
-
Object
- Object
- Test::Unit::TestCase
- Defined in:
- lib/plsql_unit_test/test_unit_patch.rb
Class Method Summary collapse
-
.set_database_interface(interface) ⇒ Object
Sets the class instance variable @@db_interface to the object that is passed in.
Instance Method Summary collapse
-
#assert_table_has_many_rows(table, row_count, where_clause = nil, message = nil) ⇒ Object
Used to assert / test a given table has a given number of rows.
-
#assert_table_has_one_row(table, where_clause = nil, message = nil) ⇒ Object
Used to assert / test a given table has only a single row.
-
#assert_table_has_zero_rows(table, where_clause = nil, message = nil) ⇒ Object
Used to assert / test a given table has zero rows.
-
#time_as_oracle_dt(time) ⇒ Object
Returns a string representing an Ruby Time object in Oracle to_date format, accurate to a day.
-
#time_as_oracle_dtm(time) ⇒ Object
Returns a string representing an Ruby Time object in Oracle to_date format, accurate to a second.
Class Method Details
.set_database_interface(interface) ⇒ Object
Sets the class instance variable @@db_interface to the object that is passed in
5 6 7 |
# File 'lib/plsql_unit_test/test_unit_patch.rb', line 5 def self.set_database_interface(interface) @@db_interface = interface end |
Instance Method Details
#assert_table_has_many_rows(table, row_count, where_clause = nil, message = nil) ⇒ Object
Used to assert / test a given table has a given number of rows. If a where clause is passed, it should start with ‘where’. The table name and where clause are used to form a select statement in the form:
"select count(*) from #{table} #{where_clause}"
It is possible to pass an array for the where clause, where the first element is the where string with bind placeholders, and the remaining elements are the bind variables:
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/plsql_unit_test/test_unit_patch.rb', line 78 def assert_table_has_many_rows(table, row_count, where_clause=nil, =nil) where = where_clause binds = Array.new if where_clause and where_clause.is_a? Array where = where_clause.shift binds = where_clause end results = @@db_interface.execute_sql("select count(*) from #{table} #{where}", *binds).all_array = (, "A count of <?> was expected but was <?> for <?> <?>", row_count.to_s, results[0][0].to_i, table, where_clause) assert_block() do row_count == results[0][0].to_i end end |
#assert_table_has_one_row(table, where_clause = nil, message = nil) ⇒ Object
Used to assert / test a given table has only a single row. If a where clause is passed, it should start with ‘where’. The table name and where clause are used to form a select statement in the form:
"select count(*) from #{table} #{where_clause}"
It is possible to pass an array for the where clause, where the first element is the where string with bind placeholders, and the remaining elements are the bind variables:
29 30 31 |
# File 'lib/plsql_unit_test/test_unit_patch.rb', line 29 def assert_table_has_one_row(table, where_clause=nil, =nil) assert_table_has_many_rows(table, 1, where_clause, ) end |
#assert_table_has_zero_rows(table, where_clause = nil, message = nil) ⇒ Object
Used to assert / test a given table has zero rows. If a where clause is passed, it should start with ‘where’. The table name and where clause are used to form a select statement in the form:
"select count(*) from #{table} #{where_clause}"
It is possible to pass an array for the where clause, where the first element is the where string with bind placeholders, and the remaining elements are the bind variables:
53 54 55 |
# File 'lib/plsql_unit_test/test_unit_patch.rb', line 53 def assert_table_has_zero_rows(table, where_clause=nil, =nil) assert_table_has_many_rows(table, 0, where_clause, ) end |
#time_as_oracle_dt(time) ⇒ Object
Returns a string representing an Ruby Time object in Oracle to_date format, accurate to a day.
100 101 102 |
# File 'lib/plsql_unit_test/test_unit_patch.rb', line 100 def time_as_oracle_dt(time) "to_date('#{time.strftime('%Y%m%d')}', 'YYYYMMDD')" end |
#time_as_oracle_dtm(time) ⇒ Object
Returns a string representing an Ruby Time object in Oracle to_date format, accurate to a second.
94 95 96 |
# File 'lib/plsql_unit_test/test_unit_patch.rb', line 94 def time_as_oracle_dtm(time) "to_date('#{time.strftime('%Y%m%d %H:%M:%S')}', 'YYYYMMDD HH24:MI:SS')" end |