aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorHongli Lai (Phusion) <hongli@phusion.nl>2008-10-09 14:35:42 +0200
committerHongli Lai (Phusion) <hongli@phusion.nl>2008-11-03 20:55:53 +0100
commitf48703e8c6ad8497795a67708ace4eb507a91119 (patch)
tree2e8d8a758a1d3773346f8fbf83867eb10768e17b /activerecord/test/cases
parent47b594cc5a2adc86e14a6a3d331583edde56a22f (diff)
downloadrails-f48703e8c6ad8497795a67708ace4eb507a91119.tar.gz
rails-f48703e8c6ad8497795a67708ace4eb507a91119.tar.bz2
rails-f48703e8c6ad8497795a67708ace4eb507a91119.zip
Fix the final MySQL unit test failure that's related to savepoint support.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/defaults_test.rb67
1 files changed, 39 insertions, 28 deletions
diff --git a/activerecord/test/cases/defaults_test.rb b/activerecord/test/cases/defaults_test.rb
index 3c4309753e..875b7f8dbc 100644
--- a/activerecord/test/cases/defaults_test.rb
+++ b/activerecord/test/cases/defaults_test.rb
@@ -20,34 +20,7 @@ class DefaultTest < ActiveRecord::TestCase
if current_adapter?(:MysqlAdapter)
- #MySQL 5 and higher is quirky with not null text/blob columns.
- #With MySQL Text/blob columns cannot have defaults. If the column is not null MySQL will report that the column has a null default
- #but it behaves as though the column had a default of ''
- def test_mysql_text_not_null_defaults
- klass = Class.new(ActiveRecord::Base)
- klass.table_name = 'test_mysql_text_not_null_defaults'
- klass.connection.create_table klass.table_name do |t|
- t.column :non_null_text, :text, :null => false
- t.column :non_null_blob, :blob, :null => false
- t.column :null_text, :text, :null => true
- t.column :null_blob, :blob, :null => true
- end
- assert_equal '', klass.columns_hash['non_null_blob'].default
- assert_equal '', klass.columns_hash['non_null_text'].default
-
- assert_equal nil, klass.columns_hash['null_blob'].default
- assert_equal nil, klass.columns_hash['null_text'].default
-
- assert_nothing_raised do
- instance = klass.create!
- assert_equal '', instance.non_null_text
- assert_equal '', instance.non_null_blob
- assert_nil instance.null_text
- assert_nil instance.null_blob
- end
- ensure
- klass.connection.drop_table(klass.table_name) rescue nil
- end
+
end
if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter, :FirebirdAdapter, :OpenBaseAdapter, :OracleAdapter)
@@ -73,8 +46,46 @@ end
if current_adapter?(:MysqlAdapter)
class DefaultsTestWithoutTransactionalFixtures < ActiveRecord::TestCase
+ # ActiveRecord::Base#create! (and #save and other related methods) will
+ # open a new transaction. When in transactional fixtures mode, this will
+ # cause ActiveRecord 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 fixtures here.
self.use_transactional_fixtures = false
+ # MySQL 5 and higher is quirky with not null text/blob columns.
+ # With MySQL Text/blob columns cannot have defaults. If the column is not
+ # null MySQL will report that the column has a null default
+ # but it behaves as though the column had a default of ''
+ def test_mysql_text_not_null_defaults
+ klass = Class.new(ActiveRecord::Base)
+ klass.table_name = 'test_mysql_text_not_null_defaults'
+ klass.connection.create_table klass.table_name do |t|
+ t.column :non_null_text, :text, :null => false
+ t.column :non_null_blob, :blob, :null => false
+ t.column :null_text, :text, :null => true
+ t.column :null_blob, :blob, :null => true
+ end
+ assert_equal '', klass.columns_hash['non_null_blob'].default
+ assert_equal '', klass.columns_hash['non_null_text'].default
+
+ assert_equal nil, klass.columns_hash['null_blob'].default
+ assert_equal nil, klass.columns_hash['null_text'].default
+
+ assert_nothing_raised do
+ instance = klass.create!
+ assert_equal '', instance.non_null_text
+ assert_equal '', instance.non_null_blob
+ assert_nil instance.null_text
+ assert_nil instance.null_blob
+ end
+ ensure
+ klass.connection.drop_table(klass.table_name) rescue nil
+ end
+
# 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