diff --git a/test/cases/helper_cockroachdb.rb b/test/cases/helper_cockroachdb.rb index 8ca0be9e..0d7e4a0b 100644 --- a/test/cases/helper_cockroachdb.rb +++ b/test/cases/helper_cockroachdb.rb @@ -37,6 +37,11 @@ def load_schema # Load ActiveRecord test helper require "cases/helper" +require "support/exclude_from_transactional_tests" + +# Allow exclusion of tests by name using #exclude_from_transactional_tests(test_name) +ActiveRecord::TestCase.prepend(ExcludeFromTransactionalTests) + # Load the CockroachDB specific schema. It replaces ActiveRecord's PostgreSQL # specific schema. def load_cockroachdb_specific_schema diff --git a/test/cases/show_create_test.rb b/test/cases/show_create_test.rb index 01832352..ac8be8ea 100644 --- a/test/cases/show_create_test.rb +++ b/test/cases/show_create_test.rb @@ -8,7 +8,7 @@ class ShowCreateTest < ActiveRecord::TestCase fixtures :posts def test_show_create - assert_match /CREATE TABLE public\.posts/, Post.show_create + assert_match(/CREATE TABLE public\.posts/, Post.show_create) end end end diff --git a/test/excludes/EachTest.rb b/test/excludes/EachTest.rb new file mode 100644 index 00000000..71faa290 --- /dev/null +++ b/test/excludes/EachTest.rb @@ -0,0 +1,8 @@ +require "support/copy_cat" + +# CockroachDB doesn't update schema information when adding an +# index until the transaction is done. Hence impossible to delete +# this index before completion of the transaction. +exclude_from_transactional_tests :test_in_batches_iterating_using_custom_columns +exclude_from_transactional_tests :test_in_batches_with_custom_columns_raises_when_non_unique_columns +exclude_from_transactional_tests :test_in_batches_when_loaded_iterates_using_custom_column diff --git a/test/excludes/MultiDbMigratorTest.rb b/test/excludes/MultiDbMigratorTest.rb index b6d196c1..2e27a540 100644 --- a/test/excludes/MultiDbMigratorTest.rb +++ b/test/excludes/MultiDbMigratorTest.rb @@ -1,10 +1,2 @@ -require "support/copy_cat" - -class CockroachDB < MultiDbMigratorTest - self.use_transactional_tests = false - - CopyCat.copy_methods(self, MultiDbMigratorTest, :test_internal_metadata_stores_environment) -end - -exclude :test_internal_metadata_stores_environment, "We can't add " \ - "and remove a column in the same transaction with CockroachDB" +# We can't add and remove a column in the same transaction with CockroachDB +exclude_from_transactional_tests :test_internal_metadata_stores_environment diff --git a/test/support/exclude_from_transactional_tests.rb b/test/support/exclude_from_transactional_tests.rb new file mode 100644 index 00000000..76da602a --- /dev/null +++ b/test/support/exclude_from_transactional_tests.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# Allow exclusion of tests by name using #exclude_from_transactional_tests(test_name) +module ExcludeFromTransactionalTests + module ClassMethods + def exclude_from_transactional_tests(name) + @non_transactional_list ||= [] + @non_transactional_list << name.to_s + end + + def non_transactional_list + @non_transactional_list ||= [] + end + end + + def self.prepended(base) + base.extend ClassMethods + end + + def before_setup + # binding.irb if self.class.non_transactional_list.include?(@NAME.to_s) + @old_use_transactional_tests = self.use_transactional_tests + if @old_use_transactional_tests # stay false if false + self.use_transactional_tests = !self.class.non_transactional_list.include?(@NAME.to_s) + end + super + end + + def after_teardown + super + ensure + self.use_transactional_tests = @old_use_transactional_tests + end +end