提交 3cce7628 编写于 作者: A Akira Matsuda

Reset ActiveRecord::SchemaDumper.ignore_tables value after changed in tests

上级 268a55f5
......@@ -2,6 +2,7 @@
require 'support/schema_dumping_helper'
class SchemaDumperTest < ActiveRecord::TestCase
include SchemaDumpingHelper
self.use_transactional_fixtures = false
setup do
......@@ -10,9 +11,11 @@ class SchemaDumperTest < ActiveRecord::TestCase
def standard_dump
@stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = []
old_ignore_tables, ActiveRecord::SchemaDumper.ignore_tables = ActiveRecord::SchemaDumper.ignore_tables, []
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, @stream)
@stream.string
ensure
ActiveRecord::SchemaDumper.ignore_tables = old_ignore_tables
end
def test_dump_schema_information_outputs_lexically_ordered_versions
......@@ -90,20 +93,12 @@ def test_no_dump_errors
end
def test_schema_dump_includes_not_null_columns
stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = [/^[^r]/]
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
output = stream.string
output = dump_all_table_schema([/^[^r]/])
assert_match %r{null: false}, output
end
def test_schema_dump_includes_limit_constraint_for_integer_columns
stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = [/^(?!integer_limits)/]
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
output = stream.string
output = dump_all_table_schema([/^(?!integer_limits)/])
if current_adapter?(:PostgreSQLAdapter)
assert_match %r{c_int_1.*limit: 2}, output
......@@ -150,22 +145,14 @@ def test_schema_dump_includes_limit_constraint_for_integer_columns
end
def test_schema_dump_with_string_ignored_table
stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = ['accounts']
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
output = stream.string
output = dump_all_table_schema(['accounts'])
assert_no_match %r{create_table "accounts"}, output
assert_match %r{create_table "authors"}, output
assert_no_match %r{create_table "schema_migrations"}, output
end
def test_schema_dump_with_regexp_ignored_table
stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = [/^account/]
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
output = stream.string
output = dump_all_table_schema([/^account/])
assert_no_match %r{create_table "accounts"}, output
assert_match %r{create_table "authors"}, output
assert_no_match %r{create_table "schema_migrations"}, output
......@@ -173,10 +160,12 @@ def test_schema_dump_with_regexp_ignored_table
def test_schema_dump_illegal_ignored_table_value
stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = [5]
old_ignore_tables, ActiveRecord::SchemaDumper.ignore_tables = ActiveRecord::SchemaDumper.ignore_tables, [5]
assert_raise(StandardError) do
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
end
ensure
ActiveRecord::SchemaDumper.ignore_tables = old_ignore_tables
end
def test_schema_dumps_index_columns_in_right_order
......@@ -245,10 +234,7 @@ def test_schema_dumps_index_type
end
def test_schema_dump_includes_decimal_options
stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = [/^[^n]/]
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
output = stream.string
output = dump_all_table_schema([/^[^n]/])
assert_match %r{precision: 3,[[:space:]]+scale: 2,[[:space:]]+default: 2.78}, output
end
......
......@@ -8,4 +8,13 @@ def dump_table_schema(table, connection = ActiveRecord::Base.connection)
ensure
ActiveRecord::SchemaDumper.ignore_tables = old_ignore_tables
end
def dump_all_table_schema(ignore_tables)
old_ignore_tables, ActiveRecord::SchemaDumper.ignore_tables = ActiveRecord::SchemaDumper.ignore_tables, ignore_tables
stream = StringIO.new
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
stream.string
ensure
ActiveRecord::SchemaDumper.ignore_tables = old_ignore_tables
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册