mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Reset ActiveRecord::SchemaDumper.ignore_tables value after changed in tests
This commit is contained in:
parent
268a55f5ef
commit
3cce7628e4
2 changed files with 21 additions and 26 deletions
|
@ -2,6 +2,7 @@ require "cases/helper"
|
|||
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 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|||
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 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|||
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 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|||
|
||||
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 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|||
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 @@ module SchemaDumpingHelper
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue