mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix test_copying_migrations_preserving_magic_comments
Since #29540, `# frozen_string_literal: true` included original migration files.
This commit is contained in:
parent
310918f6a1
commit
0ba55d2e0c
3 changed files with 9 additions and 6 deletions
|
@ -863,15 +863,17 @@ module ActiveRecord
|
|||
source_migrations.each do |migration|
|
||||
source = File.binread(migration.filename)
|
||||
inserted_comment = "# This migration comes from #{scope} (originally #{migration.version})\n"
|
||||
if /\A#.*\b(?:en)?coding:\s*\S+/ =~ source
|
||||
magic_comments = "".dup
|
||||
loop do
|
||||
# If we have a magic comment in the original migration,
|
||||
# insert our comment after the first newline(end of the magic comment line)
|
||||
# so the magic keep working.
|
||||
# Note that magic comments must be at the first line(except sh-bang).
|
||||
source[/\n/] = "\n#{inserted_comment}"
|
||||
else
|
||||
source = "#{inserted_comment}#{source}"
|
||||
source.sub!(/\A(?:#.*\b(?:en)?coding:\s*\S+|#\s*frozen_string_literal:\s*(?:true|false)).*\n/) do |magic_comment|
|
||||
magic_comments << magic_comment; ""
|
||||
end || break
|
||||
end
|
||||
source = "#{magic_comments}#{inserted_comment}#{source}"
|
||||
|
||||
if duplicate = destination_migrations.detect { |m| m.name == migration.name }
|
||||
if options[:on_skip] && duplicate.scope != scope.to_s
|
||||
|
|
|
@ -1015,8 +1015,8 @@ class CopyMigrationsTest < ActiveRecord::TestCase
|
|||
assert File.exist?(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")
|
||||
assert_equal [@migrations_path + "/4_currencies_have_symbols.bukkits.rb"], copied.map(&:filename)
|
||||
|
||||
expected = "# coding: ISO-8859-15\n# This migration comes from bukkits (originally 1)"
|
||||
assert_equal expected, IO.readlines(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")[0..1].join.chomp
|
||||
expected = "# frozen_string_literal: true\n# coding: ISO-8859-15\n# This migration comes from bukkits (originally 1)"
|
||||
assert_equal expected, IO.readlines(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")[0..2].join.chomp
|
||||
|
||||
files_count = Dir[@migrations_path + "/*.rb"].length
|
||||
copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/magic")
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
# coding: ISO-8859-15
|
||||
|
||||
class CurrenciesHaveSymbols < ActiveRecord::Migration::Current
|
||||
|
|
Loading…
Reference in a new issue