aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-07-04 14:10:14 -0400
committerGitHub <noreply@github.com>2017-07-04 14:10:14 -0400
commit1729d3b4b2ea96becbb473c982a78d2cf957ce6d (patch)
tree107b989946317fd9828f0ca7399f2ae1a77ffef4 /activerecord/lib/active_record
parentb115dd17e44e39b62e3c4f18a749beaa8d10b51f (diff)
parent0ba55d2e0c251451eede1da069666eb15e86b2c7 (diff)
downloadrails-1729d3b4b2ea96becbb473c982a78d2cf957ce6d.tar.gz
rails-1729d3b4b2ea96becbb473c982a78d2cf957ce6d.tar.bz2
rails-1729d3b4b2ea96becbb473c982a78d2cf957ce6d.zip
Merge pull request #29653 from kamipo/fix_test_copying_migrations_preserving_magic_comments
Fix `test_copying_migrations_preserving_magic_comments`
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/migration.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 1ff1dcad43..42220b9a5e 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -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