diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/defaults_test.rb | 20 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/postgresql.sql | 4 |
2 files changed, 20 insertions, 4 deletions
diff --git a/activerecord/test/defaults_test.rb b/activerecord/test/defaults_test.rb index aba3c66de4..f15f422dc7 100644 --- a/activerecord/test/defaults_test.rb +++ b/activerecord/test/defaults_test.rb @@ -1,8 +1,24 @@ require 'abstract_unit' require 'fixtures/default' +require 'fixtures/entrant' -if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter) - class DefaultsTest < Test::Unit::TestCase +class DefaultTest < Test::Unit::TestCase + def test_nil_defaults_for_not_null_columns + column_defaults = + if current_adapter?(:MysqlAdapter) + { 'id' => nil, 'name' => '', 'course_id' => 0 } + 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) def test_default_integers default = Default.new assert_instance_of Fixnum, default.positive_integer diff --git a/activerecord/test/fixtures/db_definitions/postgresql.sql b/activerecord/test/fixtures/db_definitions/postgresql.sql index ce2c775aba..b5412c7400 100644 --- a/activerecord/test/fixtures/db_definitions/postgresql.sql +++ b/activerecord/test/fixtures/db_definitions/postgresql.sql @@ -130,8 +130,8 @@ CREATE TABLE auto_id_tests ( CREATE TABLE entrants ( id serial, - name text, - course_id integer + name text not null, + course_id integer not null ); CREATE TABLE colnametests ( |