activerecord/test/cases/defaults_test.rb
# ActiveRecord::Base#create! (and #save and other related methods) will
# open a new transaction. When in transactional tests mode, this will
# cause Active Record to create a new savepoint. However, since MySQL doesn't
# support DDL transactions, creating a table will result in any created
# savepoints to be automatically released. This in turn causes the savepoint
# release code in AbstractAdapter#transaction to fail.
#
# We don't want that to happen, so we disable transactional tests here.
:Base#create. (and #save and other related methods) will
open a new transaction. When in transactional tests mode, this will
cause Active Record to create a new savepoint. However, since MySQL doesn't
support DDL transactions, creating a table will result in any created
savepoints to be automatically released. This in turn causes the savepoint
release code in AbstractAdapter#transaction to fail.

We don't want that to happen, so we disable transactional tests here.
: Base#create . ( and #save and other related methods ) will open a new transaction . When in transactional tests mode this will cause Active Record to create a new savepoint . However since MySQL doesn ' t support DDL transactions creating a table will result in any created savepoints to be automatically released . This in turn causes the savepoint release code in AbstractAdapter#transaction to fail . We don ' t want that to happen so we disable transactional tests here .
def with_mysql_not_null_table
      klass = Class.new(ActiveRecord::Base)
      klass.table_name = "test_mysql_not_null_defaults"
      klass.connection.create_table klass.table_name do |t|
        t.integer :non_null_integer, null: false
        t.string  :non_null_string,  null: false
        t.text    :non_null_text,    null: false
        t.blob    :non_null_blob,    null: false
      end
      yield klass
    ensure
      klass.connection.drop_table(klass.table_name) rescue nil
    end
def with_mysql_not_null_table klass = Class . new ( ActiveRecord :: Base ) klass . table_name = "test_mysql_not_null_defaults" klass . connection . create_table klass . table_name do | t | t . integer :non_null_integer , null : false t . string :non_null_string , null : false t . text :non_null_text , null : false t . blob :non_null_blob , null : false end yield klass ensure klass . connection . drop_table ( klass . table_name ) rescue nil end
ActiveRecord::Base#create!
ActiveRecord :: Base#create!