aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2010-07-31 14:43:41 +0200
committerPiotr Sarnacki <drogus@gmail.com>2010-09-03 22:59:10 +0200
commite063879daf55f100f316ad55f44a0df6d545693d (patch)
treedebee2d726dcf47fa57314f0047b7dd8561bc654 /activerecord
parentc7664d112fadb313146da33f48d1da318f249927 (diff)
downloadrails-e063879daf55f100f316ad55f44a0df6d545693d.tar.gz
rails-e063879daf55f100f316ad55f44a0df6d545693d.tar.bz2
rails-e063879daf55f100f316ad55f44a0df6d545693d.zip
Fix copying migrations to empty directory
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/migration.rb2
-rw-r--r--activerecord/test/cases/migration_test.rb14
-rw-r--r--activerecord/test/migrations/empty/.gitkeep0
3 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 293c9f3c08..e708b3fbcf 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -395,7 +395,7 @@ module ActiveRecord
source_migrations.each do |migration|
next if destination_migrations.any? { |m| m.name == migration.name && m.scope == scope.to_s }
- migration.version = next_migration_number(last.version + 1).to_i
+ migration.version = next_migration_number(last ? last.version + 1 : 0).to_i
last = migration
new_path = File.join(destination, "#{migration.version}_#{migration.name.underscore}.#{scope}.rb")
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index 85e1898b15..03a8cc90f6 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -1985,6 +1985,20 @@ if ActiveRecord::Base.connection.supports_migrations?
ensure
clear
end
+
+ def test_copying_migrations_to_empty_directory
+ @migrations_path = MIGRATIONS_ROOT + "/empty"
+ @existing_migrations = []
+
+ Time.travel_to(created_at = Time.utc(2010, 7, 26, 10, 10, 10)) do
+ copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
+ assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
+ assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
+ assert_equal 2, copied.length
+ end
+ ensure
+ clear
+ end
end
end
diff --git a/activerecord/test/migrations/empty/.gitkeep b/activerecord/test/migrations/empty/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/activerecord/test/migrations/empty/.gitkeep