提交 e8082246 编写于 作者: D David Trasbo 提交者: José Valim

Remove existing migration when using 'rails generate model' with --force [#5526 state:committed]

Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 20685d07
......@@ -53,7 +53,11 @@ def migration_template(source, destination=nil, config={})
destination = self.class.migration_exists?(migration_dir, @migration_file_name)
if behavior == :invoke
raise Error, "Another migration is already named #{@migration_file_name}: #{destination}" if destination
if destination && options.force?
remove_file(destination)
elsif destination
raise Error, "Another migration is already named #{@migration_file_name}: #{destination}"
end
destination = File.join(migration_dir, "#{@migration_number}_#{@migration_file_name}.rb")
end
......
......@@ -165,6 +165,15 @@ def test_migration_is_removed_on_revoke
assert_no_migration "db/migrate/create_accounts.rb"
end
def test_existing_migration_is_removed_on_force
run_generator
old_migration = Dir["#{destination_root}/db/migrate/*_create_accounts.rb"].first
error = capture(:stderr) { run_generator ["Account", "--force"] }
assert_no_match /Another migration is already named create_foos/, error
assert_no_file old_migration
assert_migration 'db/migrate/create_accounts.rb'
end
def test_invokes_default_test_framework
run_generator
assert_file "test/unit/account_test.rb", /class AccountTest < ActiveSupport::TestCase/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册