提交 1729d3b4 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #29653 from kamipo/fix_test_copying_migrations_preserving_magic_comments

Fix `test_copying_migrations_preserving_magic_comments`
...@@ -863,15 +863,17 @@ def copy(destination, sources, options = {}) ...@@ -863,15 +863,17 @@ def copy(destination, sources, options = {})
source_migrations.each do |migration| source_migrations.each do |migration|
source = File.binread(migration.filename) source = File.binread(migration.filename)
inserted_comment = "# This migration comes from #{scope} (originally #{migration.version})\n" 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, # If we have a magic comment in the original migration,
# insert our comment after the first newline(end of the magic comment line) # insert our comment after the first newline(end of the magic comment line)
# so the magic keep working. # so the magic keep working.
# Note that magic comments must be at the first line(except sh-bang). # Note that magic comments must be at the first line(except sh-bang).
source[/\n/] = "\n#{inserted_comment}" source.sub!(/\A(?:#.*\b(?:en)?coding:\s*\S+|#\s*frozen_string_literal:\s*(?:true|false)).*\n/) do |magic_comment|
else magic_comments << magic_comment; ""
source = "#{inserted_comment}#{source}" end || break
end end
source = "#{magic_comments}#{inserted_comment}#{source}"
if duplicate = destination_migrations.detect { |m| m.name == migration.name } if duplicate = destination_migrations.detect { |m| m.name == migration.name }
if options[:on_skip] && duplicate.scope != scope.to_s if options[:on_skip] && duplicate.scope != scope.to_s
......
...@@ -1015,8 +1015,8 @@ def test_copying_migrations_preserving_magic_comments ...@@ -1015,8 +1015,8 @@ def test_copying_migrations_preserving_magic_comments
assert File.exist?(@migrations_path + "/4_currencies_have_symbols.bukkits.rb") assert File.exist?(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")
assert_equal [@migrations_path + "/4_currencies_have_symbols.bukkits.rb"], copied.map(&:filename) 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)" 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..1].join.chomp assert_equal expected, IO.readlines(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")[0..2].join.chomp
files_count = Dir[@migrations_path + "/*.rb"].length files_count = Dir[@migrations_path + "/*.rb"].length
copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/magic") copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/magic")
......
# frozen_string_literal: true
# coding: ISO-8859-15 # coding: ISO-8859-15
class CurrenciesHaveSymbols < ActiveRecord::Migration::Current class CurrenciesHaveSymbols < ActiveRecord::Migration::Current
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册