mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Speed up schema dumper tests
Dump the standard schema once instead of redoing it per test
This commit is contained in:
parent
2c76793f08
commit
fdba1a791b
1 changed files with 9 additions and 11 deletions
|
@ -10,12 +10,11 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def standard_dump
|
def standard_dump
|
||||||
@stream = StringIO.new
|
@@standard_dump ||= perform_schema_dump
|
||||||
old_ignore_tables, ActiveRecord::SchemaDumper.ignore_tables = ActiveRecord::SchemaDumper.ignore_tables, []
|
end
|
||||||
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, @stream)
|
|
||||||
@stream.string
|
def perform_schema_dump
|
||||||
ensure
|
dump_all_table_schema []
|
||||||
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
|
||||||
|
@ -31,8 +30,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_magic_comment
|
def test_magic_comment
|
||||||
output = standard_dump
|
assert_match "# encoding: #{Encoding.default_external.name}", standard_dump
|
||||||
assert_match "# encoding: #{@stream.external_encoding.name}", output
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_schema_dump
|
def test_schema_dump
|
||||||
|
@ -255,12 +253,12 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
||||||
connection = ActiveRecord::Base.connection
|
connection = ActiveRecord::Base.connection
|
||||||
|
|
||||||
connection.stubs(:extensions).returns(['hstore'])
|
connection.stubs(:extensions).returns(['hstore'])
|
||||||
output = standard_dump
|
output = perform_schema_dump
|
||||||
assert_match "# These are extensions that must be enabled", output
|
assert_match "# These are extensions that must be enabled", output
|
||||||
assert_match %r{enable_extension "hstore"}, output
|
assert_match %r{enable_extension "hstore"}, output
|
||||||
|
|
||||||
connection.stubs(:extensions).returns([])
|
connection.stubs(:extensions).returns([])
|
||||||
output = standard_dump
|
output = perform_schema_dump
|
||||||
assert_no_match "# These are extensions that must be enabled", output
|
assert_no_match "# These are extensions that must be enabled", output
|
||||||
assert_no_match %r{enable_extension}, output
|
assert_no_match %r{enable_extension}, output
|
||||||
end
|
end
|
||||||
|
@ -401,7 +399,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
||||||
migration = CreateDogMigration.new
|
migration = CreateDogMigration.new
|
||||||
migration.migrate(:up)
|
migration.migrate(:up)
|
||||||
|
|
||||||
output = standard_dump
|
output = perform_schema_dump
|
||||||
assert_no_match %r{create_table "foo_.+_bar"}, output
|
assert_no_match %r{create_table "foo_.+_bar"}, output
|
||||||
assert_no_match %r{add_index "foo_.+_bar"}, output
|
assert_no_match %r{add_index "foo_.+_bar"}, output
|
||||||
assert_no_match %r{create_table "schema_migrations"}, output
|
assert_no_match %r{create_table "schema_migrations"}, output
|
||||||
|
|
Loading…
Reference in a new issue