Skip to content

Commit 86dbe4c

Browse files
committed
add exclusion of transact test by name
1 parent 3067576 commit 86dbe4c

File tree

5 files changed

+50
-11
lines changed

5 files changed

+50
-11
lines changed

test/cases/helper_cockroachdb.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def load_schema
3737
# Load ActiveRecord test helper
3838
require "cases/helper"
3939

40+
require "support/exclude_from_transactional_tests"
41+
42+
# Allow exclusion of tests by name using #exclude_from_transactional_tests(test_name)
43+
ActiveRecord::TestCase.prepend(ExcludeFromTransactionalTests)
44+
4045
# Load the CockroachDB specific schema. It replaces ActiveRecord's PostgreSQL
4146
# specific schema.
4247
def load_cockroachdb_specific_schema

test/cases/show_create_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ShowCreateTest < ActiveRecord::TestCase
88
fixtures :posts
99

1010
def test_show_create
11-
assert_match /CREATE TABLE public\.posts/, Post.show_create
11+
assert_match(/CREATE TABLE public\.posts/, Post.show_create)
1212
end
1313
end
1414
end

test/excludes/EachTest.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require "support/copy_cat"
2+
3+
# CockroachDB doesn't update schema information when adding an
4+
# index until the transaction is done. Hence impossible to delete
5+
# this index before completion of the transaction.
6+
exclude_from_transactional_tests :test_in_batches_iterating_using_custom_columns
7+
exclude_from_transactional_tests :test_in_batches_with_custom_columns_raises_when_non_unique_columns
8+
exclude_from_transactional_tests :test_in_batches_when_loaded_iterates_using_custom_column
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
require "support/copy_cat"
2-
3-
class CockroachDB < MultiDbMigratorTest
4-
self.use_transactional_tests = false
5-
6-
CopyCat.copy_methods(self, MultiDbMigratorTest, :test_internal_metadata_stores_environment)
7-
end
8-
9-
exclude :test_internal_metadata_stores_environment, "We can't add " \
10-
"and remove a column in the same transaction with CockroachDB"
1+
# We can't add and remove a column in the same transaction with CockroachDB
2+
exclude_from_transactional_tests :test_internal_metadata_stores_environment
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
# Allow exclusion of tests by name using #exclude_from_transactional_tests(test_name)
4+
module ExcludeFromTransactionalTests
5+
module ClassMethods
6+
def exclude_from_transactional_tests(name)
7+
@non_transactional_list ||= []
8+
@non_transactional_list << name.to_s
9+
end
10+
11+
def non_transactional_list
12+
@non_transactional_list ||= []
13+
end
14+
end
15+
16+
def self.prepended(base)
17+
base.extend ClassMethods
18+
end
19+
20+
def before_setup
21+
# binding.irb if self.class.non_transactional_list.include?(@NAME.to_s)
22+
@old_use_transactional_tests = self.use_transactional_tests
23+
if @old_use_transactional_tests # stay false if false
24+
self.use_transactional_tests = !self.class.non_transactional_list.include?(@NAME.to_s)
25+
end
26+
super
27+
end
28+
29+
def after_teardown
30+
super
31+
ensure
32+
self.use_transactional_tests = @old_use_transactional_tests
33+
end
34+
end

0 commit comments

Comments
 (0)