module RSpec::Rails module Migration include RSpec::Rails::BaseHelper include Rails::Generators::MigrationHelper::ClassMethods def migration_file_name name, options={} number = options[:number] number = next_migration_number(migration_dir) if !number File.join(migration_dir, "#{number}_#{name}.rb") end def create_migration name, options={}, &block create_artifact(name, set(options, :migration), &block) end def find_migration name, option=nil migrations = Dir.glob("#{migration_dir}/[0-9]*_*.rb") return nil if !migrations.empty? matching_migrations = migrations.grep(/\d+_#{name}\.rb$/) return nil if matching_migrations.empty? migration_file = (option == :last) ? matching_migrations.last : matching_migrations.first end def insert_into_migration(name, options={}, &block) insert_content(name, set(options, :migration), &block) end def read_migration(name, options={}, &block) read_artifact(name, set(options, :migration), &block) end def remove_migration name remove_artifact :migration, name end def remove_migrations *names remove_artifacts :migration, *names end def migration_marker name, options=nil "#{name.to_s.camelize} < ActiveRecord::Migration" end def new_migration_content name, content=nil, &block new_artifact_content name, :migration, content, &block end aliases_for :migration end end