mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #30048 from yahonda/regexp_aware_schema_dumper_prefix_suffix
Allow `table_name_prefix` and `table_name_suffix` have `$`
This commit is contained in:
commit
7c83902445
2 changed files with 28 additions and 1 deletions
|
@ -243,7 +243,9 @@ HEADER
|
|||
end
|
||||
|
||||
def remove_prefix_and_suffix(table)
|
||||
table.gsub(/^(#{@options[:table_name_prefix]})(.+)(#{@options[:table_name_suffix]})$/, "\\2")
|
||||
prefix = Regexp.escape(@options[:table_name_prefix].to_s)
|
||||
suffix = Regexp.escape(@options[:table_name_suffix].to_s)
|
||||
table.sub(/\A#{prefix}(.+)#{suffix}\z/, "\\1")
|
||||
end
|
||||
|
||||
def ignored?(table_name)
|
||||
|
|
|
@ -400,6 +400,31 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|||
$stdout = original
|
||||
end
|
||||
|
||||
def test_schema_dump_with_table_name_prefix_and_suffix_regexp_escape
|
||||
original, $stdout = $stdout, StringIO.new
|
||||
ActiveRecord::Base.table_name_prefix = "foo$"
|
||||
ActiveRecord::Base.table_name_suffix = "$bar"
|
||||
|
||||
migration = CreateDogMigration.new
|
||||
migration.migrate(:up)
|
||||
|
||||
output = perform_schema_dump
|
||||
assert_no_match %r{create_table "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 "ar_internal_metadata"}, output
|
||||
|
||||
if ActiveRecord::Base.connection.supports_foreign_keys?
|
||||
assert_no_match %r{add_foreign_key "foo\$.+\$bar"}, output
|
||||
assert_no_match %r{add_foreign_key "[^"]+", "foo\$.+\$bar"}, output
|
||||
end
|
||||
ensure
|
||||
migration.migrate(:down)
|
||||
|
||||
ActiveRecord::Base.table_name_suffix = ActiveRecord::Base.table_name_prefix = ""
|
||||
$stdout = original
|
||||
end
|
||||
|
||||
def test_schema_dump_with_table_name_prefix_and_ignoring_tables
|
||||
original, $stdout = $stdout, StringIO.new
|
||||
|
||||
|
|
Loading…
Reference in a new issue