diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2011-12-09 20:07:29 +0100 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2011-12-09 21:43:36 +0100 |
commit | f0b782d060f76647e36adc40fe5fe818ec8e2c66 (patch) | |
tree | daaa633c3b8d17eaa84a7418379f76d1762eed2b /activerecord/test/cases | |
parent | ab30570b69e6118bbfbd8dfaa7577668b34e5eaf (diff) | |
download | rails-f0b782d060f76647e36adc40fe5fe818ec8e2c66.tar.gz rails-f0b782d060f76647e36adc40fe5fe818ec8e2c66.tar.bz2 rails-f0b782d060f76647e36adc40fe5fe818ec8e2c66.zip |
Allow to filter migrations by passing a block
Example:
ActiveRecord::Migrator.migrate(path) do |migration|
migration.name =~ /User/
end
The above example will migrate only migrations with User in
the name
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index b5fae3b7d3..1e68911ab3 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1235,6 +1235,24 @@ if ActiveRecord::Base.connection.supports_migrations? assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) } end + def test_filtering_migrations + assert !Person.column_methods_hash.include?(:last_name) + assert !Reminder.table_exists? + + name_filter = lambda { |migration| migration.name == "ValidPeopleHaveLastNames" } + ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", &name_filter) + + Person.reset_column_information + assert Person.column_methods_hash.include?(:last_name) + assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) } + + ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", &name_filter) + + Person.reset_column_information + assert !Person.column_methods_hash.include?(:last_name) + assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) } + end + class MockMigration < ActiveRecord::Migration attr_reader :went_up, :went_down def initialize |