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

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

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