Skip to content

Commit c02cf48

Browse files
authored
refactor(test): only dump necessary table in schema dumper tests
1 parent 8daf4fb commit c02cf48

File tree

4 files changed

+14
-71
lines changed

4 files changed

+14
-71
lines changed

test/cases/create_unlogged_tables_test.rb

Lines changed: 0 additions & 48 deletions
This file was deleted.

test/cases/migration/hidden_column_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_remove_index_with_a_hidden_column
6262
CREATE INDEX hash_idx ON rockets (name) USING HASH WITH (bucket_count=8);
6363
SQL
6464
@connection.remove_index :rockets, :name
65-
# assert :ok
65+
assert :ok
6666
end
6767
end
6868
end

test/cases/schema_dumper_test.rb

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ class SchemaDumperTest < ActiveRecord::TestCase
1515
@schema_migration.create_table
1616
end
1717

18-
def standard_dump
19-
@@standard_dump ||= perform_schema_dump
20-
end
21-
22-
def perform_schema_dump
23-
dump_all_table_schema []
24-
end
25-
2618
# See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/347
2719
def test_dump_index_rather_than_unique_constraints
2820
ActiveRecord::Base.with_connection do |conn|
@@ -35,13 +27,9 @@ def test_dump_index_rather_than_unique_constraints
3527
end
3628
end
3729

38-
stream = StringIO.new
39-
ActiveRecord::Base.connection_pool.with_connection do |conn|
40-
dumper = conn.create_schema_dumper({})
41-
dumper.send(:table, "payments", stream)
42-
end
43-
stream.rewind
44-
index_lines = stream.each_line.select { _1[/simple_unique|unique_with_where|as_unique_constraint/] }
30+
output = dump_table_schema("payments")
31+
32+
index_lines = output.each_line.select { _1[/simple_unique|unique_with_where|as_unique_constraint/] }
4533
assert_equal 2, index_lines.size
4634
index_lines.each do |line|
4735
assert_match(/t.index/, line)
@@ -69,7 +57,8 @@ def down
6957
end
7058
migration.migrate(:up)
7159

72-
output = perform_schema_dump
60+
output = dump_table_schema "timestamps"
61+
7362
assert output.include?('t.datetime "this_should_remain_datetime"')
7463
assert output.include?('t.datetime "this_is_an_alias_of_datetime"')
7564
assert output.include?('t.timestamp "without_time_zone"')
@@ -97,7 +86,7 @@ def down
9786
end
9887
migration.migrate(:up)
9988

100-
output = perform_schema_dump
89+
output = dump_table_schema "timestamps"
10190
# Normally we'd write `t.datetime` here. But because you've changed the `datetime_type`
10291
# to something else, `t.datetime` now means `:timestamptz`. To ensure that old columns
10392
# are still created as a `:timestamp` we need to change what is written to the schema dump.
@@ -131,7 +120,7 @@ def down
131120
end
132121
migration.migrate(:up)
133122

134-
output = perform_schema_dump
123+
output = dump_table_schema "timestamps"
135124
# Normally we'd write `t.datetime` here. But because you've changed the `datetime_type`
136125
# to something else, `t.datetime` now means `:timestamptz`. To ensure that old columns
137126
# are still created as a `:timestamp` we need to change what is written to the schema dump.
@@ -166,7 +155,7 @@ def down
166155
end
167156
migration.migrate(:up)
168157

169-
output = perform_schema_dump
158+
output = dump_table_schema "timestamps"
170159
# Normally we'd write `t.datetime` here. But because you've changed the `datetime_type`
171160
# to something else, `t.datetime` now means `:timestamptz`. To ensure that old columns
172161
# are still created as a `:timestamp` we need to change what is written to the schema dump.
@@ -200,15 +189,15 @@ def down
200189
end
201190
migration.migrate(:up)
202191

203-
output = perform_schema_dump
192+
output = dump_table_schema "timestamps"
204193
assert output.include?('t.datetime "default_format"')
205194
assert output.include?('t.datetime "without_time_zone"')
206195
assert output.include?('t.timestamptz "with_time_zone"')
207196

208197
datetime_type_was = ActiveRecord::ConnectionAdapters::CockroachDBAdapter.datetime_type
209198
ActiveRecord::ConnectionAdapters::CockroachDBAdapter.datetime_type = :timestamptz
210199

211-
output = perform_schema_dump
200+
output = dump_table_schema "timestamps"
212201
assert output.include?('t.timestamp "default_format"')
213202
assert output.include?('t.timestamp "without_time_zone"')
214203
assert output.include?('t.datetime "with_time_zone"')

test/excludes/UnloggedTablesTest.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
exclude :test_unlogged_in_test_environment_when_unlogged_setting_enabled, "Override because UNLOGGED cannot be specified in CockroachDB. Related https://github.com/cockroachdb/cockroach/issues/56827"
1+
instance_methods.grep(/\Atest_\w+\z/).each do |method_name|
2+
exclude method_name, "UNLOGGED has no effect in CockroachDB."
3+
end

0 commit comments

Comments
 (0)