Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge [5901], [5902], [5903] from trunk. References #6156.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5905 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit d12bcdac9d62497fa1b3130083de69d156bd7e6c 1 parent 52923c9
@jeremy jeremy authored
Showing with 28 additions and 0 deletions.
  1. +28 −0 activerecord/test/defaults_test.rb
View
28 activerecord/test/defaults_test.rb
@@ -18,6 +18,34 @@ def test_nil_defaults_for_not_null_columns
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_raise(ActiveRecord::StatementInvalid) { klass.create! }
+
+ assert_nothing_raised do
+ instance = klass.create!(:omit => 1)
+ assert_equal 0, instance.zero
+ assert_equal 1, 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
Please sign in to comment.
Something went wrong with that request. Please try again.