diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-01-12 08:46:01 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-01-12 08:46:01 +0000 |
commit | dbd7b5e11177c46c8688b54d46be8fcb5b8a4317 (patch) | |
tree | e54b90ce01d1f4d2762485d45c8b7743a9b07f4c /activerecord | |
parent | 6e1e088b8f843662c6236751896999cd4e797656 (diff) | |
download | rails-dbd7b5e11177c46c8688b54d46be8fcb5b8a4317.tar.gz rails-dbd7b5e11177c46c8688b54d46be8fcb5b8a4317.tar.bz2 rails-dbd7b5e11177c46c8688b54d46be8fcb5b8a4317.zip |
Test MySQL implicit NULL for integer columns. Closes #6156.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5901 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/defaults_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/defaults_test.rb b/activerecord/test/defaults_test.rb index 4a910de523..924a4fbf49 100644 --- a/activerecord/test/defaults_test.rb +++ b/activerecord/test/defaults_test.rb @@ -18,6 +18,32 @@ class DefaultTest < Test::Unit::TestCase end end + if current_adapter?(:MysqlAdapter) + # MySQL uses an implicit default 0 rather than NULL unless in strict mode. + # We use an implicit NULL so schema.rb is compatible with other databases. + def test_mysql_integer_not_null_defaults + klass = Class.new(ActiveRecord::Base) + klass.table_name = 'test_integer_not_null_default_zero' + klass.connection.create_table klass.table_name do |t| + t.column :zero, :integer, :null => false, :default => 0 + t.column :omit, :integer, :null => false + end + + assert_equal 0, klass.columns_hash['zero'].default + assert !klass.columns_hash['zero'].null + assert_equal nil, klass.columns_hash['omit'].default + assert !klass.columns_hash['omit'].null + + assert_nothing_raised do + instance = klass.create! + assert_equal 0, instance.zero + assert_nil instance.omit + end + ensure + klass.connection.drop_table(klass.table_name) rescue nil + end + end + if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter, :FirebirdAdapter, :OpenBaseAdapter) def test_default_integers default = Default.new |