aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration_test.rb
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2011-12-09 01:49:08 +0100
committerPiotr Sarnacki <drogus@gmail.com>2011-12-09 01:54:20 +0100
commit62d556424adcbf473ec5fe2ed9b460c058a36463 (patch)
tree681e6a6f447c798abadcc51933120ad8271f3e9b /activerecord/test/cases/migration_test.rb
parent652db2fc3e1d62737e4bedb3b7cee313d7400c0a (diff)
downloadrails-62d556424adcbf473ec5fe2ed9b460c058a36463.tar.gz
rails-62d556424adcbf473ec5fe2ed9b460c058a36463.tar.bz2
rails-62d556424adcbf473ec5fe2ed9b460c058a36463.zip
Ignore origin comment when checking for duplicates on Migration.copy
49ebe51 fixed copying migrations, but existing migrations would still trigger warnings. The proper way to compare migrations is to ignore origin lines - if migration is identical it means that we can silently skip it, regardless where it comes from.
Diffstat (limited to 'activerecord/test/cases/migration_test.rb')
-rw-r--r--activerecord/test/cases/migration_test.rb32
1 files changed, 29 insertions, 3 deletions
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index 1997fc96ea..7c92db5def 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -2203,15 +2203,16 @@ if ActiveRecord::Base.connection.supports_migrations?
@existing_migrations = Dir[@migrations_path + "/*.rb"]
sources = ActiveSupport::OrderedHash.new
- sources[:bukkits] = sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
+ sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
+ sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_name_collision"
skipped = []
on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
assert_equal 2, copied.length
- assert_equal 2, skipped.length
- assert_equal ["bukkits PeopleHaveHobbies", "bukkits PeopleHaveDescriptions"], skipped
+ assert_equal 1, skipped.length
+ assert_equal ["omg PeopleHaveHobbies"], skipped
ensure
clear
end
@@ -2234,6 +2235,31 @@ if ActiveRecord::Base.connection.supports_migrations?
clear
end
+ def test_skip_ignores_origin_comment
+ ActiveRecord::Base.timestamped_migrations = false
+ @migrations_path = MIGRATIONS_ROOT + "/valid"
+ @existing_migrations = Dir[@migrations_path + "/*.rb"]
+
+ sources = ActiveSupport::OrderedHash.new
+ sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy"
+
+ skipped = []
+ on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
+ copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
+
+ # remove origin comment
+ migration = @migrations_path + "/4_people_have_hobbies.rb"
+ migration_source = File.read(migration).to_a[1..-1].join
+ File.open(migration, "w") { |f| f.write migration_source }
+
+ ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
+
+ assert_equal 2, copied.length
+ assert_equal 0, skipped.length
+ ensure
+ clear
+ end
+
def test_copying_migrations_to_non_existing_directory
@migrations_path = MIGRATIONS_ROOT + "/non_existing"
@existing_migrations = []