Browse files

Create directory before copying migrations if it does not exist

  • Loading branch information...
1 parent 510375b commit 437ceab139c9aace851b41ce6103d29302750e0c @drogus drogus committed Nov 16, 2010
Showing with 17 additions and 0 deletions.
  1. +2 −0 activerecord/lib/active_record/migration.rb
  2. +15 −0 activerecord/test/cases/migration_test.rb
View
2 activerecord/lib/active_record/migration.rb
@@ -387,6 +387,8 @@ def method_missing(method, *arguments, &block)
def copy(destination, sources, options = {})
copied = []
+ FileUtils.mkdir_p(destination) unless File.exists?(destination)
+
destination_migrations = ActiveRecord::Migrator.migrations(destination)
last = destination_migrations.last
sources.each do |name, path|
View
15 activerecord/test/cases/migration_test.rb
@@ -2024,6 +2024,21 @@ def test_skipping_migrations
clear
end
+ def test_copying_migrations_to_non_existing_directory
+ @migrations_path = MIGRATIONS_ROOT + "/non_existing"
+ @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.rb")
+ assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.rb")
+ assert_equal 2, copied.length
+ end
+ ensure
+ clear
+ Dir.delete(@migrations_path)
+ end
+
def test_copying_migrations_to_empty_directory
@migrations_path = MIGRATIONS_ROOT + "/empty"
@existing_migrations = []

0 comments on commit 437ceab

Please sign in to comment.