diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-11-16 17:00:01 +0100 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-11-16 17:00:01 +0100 |
commit | 437ceab139c9aace851b41ce6103d29302750e0c (patch) | |
tree | f04086ac8ee6c3787e8aae031f1b81a2e7ab393a | |
parent | 510375b501d1a158edf579966a51568d539dcd6e (diff) | |
download | rails-437ceab139c9aace851b41ce6103d29302750e0c.tar.gz rails-437ceab139c9aace851b41ce6103d29302750e0c.tar.bz2 rails-437ceab139c9aace851b41ce6103d29302750e0c.zip |
Create directory before copying migrations if it does not exist
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index a4c09b654a..2c306d233a 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -387,6 +387,8 @@ module ActiveRecord 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| diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index e6eef805cf..698075ea0c 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -2024,6 +2024,21 @@ if ActiveRecord::Base.connection.supports_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 = [] |