Merge pull request #41255 from euxx/fix-create-migration-generator-with-pretend-option

Fix create migration generator with `--pretend` option
This commit is contained in:
Rafael França 2021-03-29 22:27:34 -04:00 committed by GitHub
commit 6675f6b785
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View File

@ -20,6 +20,8 @@ module Rails
end end
def invoke! def invoke!
return super if pretend?
invoked_file = super invoked_file = super
File.exist?(@destination) ? invoked_file : relative_existing_migration File.exist?(@destination) ? invoked_file : relative_existing_migration
end end

View File

@ -55,6 +55,8 @@ class CreateMigrationTest < Rails::Generators::TestCase
def test_invoke_pretended def test_invoke_pretended
create_migration(default_destination_path, {}, { pretend: true }) create_migration(default_destination_path, {}, { pretend: true })
stdout = invoke!
assert_match(/create db\/migrate\/1_create_articles\.rb\n/, stdout)
assert_no_file @migration.destination assert_no_file @migration.destination
end end