2006-02-09 13:06:29 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
require 'fixtures/default'
|
2006-11-20 03:54:42 -05:00
|
|
|
require 'fixtures/entrant'
|
2006-02-09 13:06:29 -05:00
|
|
|
|
2006-11-20 03:54:42 -05:00
|
|
|
class DefaultTest < Test::Unit::TestCase
|
|
|
|
def test_nil_defaults_for_not_null_columns
|
|
|
|
column_defaults =
|
|
|
|
if current_adapter?(:MysqlAdapter)
|
2006-11-20 06:44:31 -05:00
|
|
|
{ 'id' => nil, 'name' => '', 'course_id' => nil }
|
2006-11-20 03:54:42 -05:00
|
|
|
else
|
|
|
|
{ 'id' => nil, 'name' => nil, 'course_id' => nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
column_defaults.each do |name, default|
|
|
|
|
column = Entrant.columns_hash[name]
|
|
|
|
assert !column.null, "#{name} column should be NOT NULL"
|
|
|
|
assert_equal default, column.default, "#{name} column should be DEFAULT #{default.inspect}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter, :FirebirdAdapter, :OpenBaseAdapter)
|
2006-02-09 13:06:29 -05:00
|
|
|
def test_default_integers
|
|
|
|
default = Default.new
|
2006-07-08 16:35:56 -04:00
|
|
|
assert_instance_of Fixnum, default.positive_integer
|
|
|
|
assert_equal 1, default.positive_integer
|
|
|
|
assert_instance_of Fixnum, default.negative_integer
|
|
|
|
assert_equal -1, default.negative_integer
|
|
|
|
assert_instance_of BigDecimal, default.decimal_number
|
|
|
|
assert_equal BigDecimal.new("2.78"), default.decimal_number
|
2006-02-09 14:32:32 -05:00
|
|
|
end
|
2006-02-09 13:06:29 -05:00
|
|
|
end
|
|
|
|
end
|