class CreateMigrationTest
Public Instance Methods
create_migration(destination_path = default_destination_path, config = {}, generator_options = {}, &block)
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 23 def create_migration(destination_path = default_destination_path, config = {}, generator_options = {}, &block) migration_name = File.basename(destination_path, ".rb") generator([migration_name], generator_options) generator.set_migration_assigns!(destination_path) dir, base = File.split(destination_path) timestamped_destination_path = File.join(dir, ["%migration_number%", base].join("_")) @migration = Quails::Generators::Actions::CreateMigration.new(generator, timestamped_destination_path, block || "contents", config) end
default_destination_path()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 19 def default_destination_path "db/migrate/create_articles.rb" end
invoke!()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 40 def invoke! capture(:stdout) { @migration.invoke! } end
migration_exists!(*args)
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 34 def migration_exists!(*args) @existing_migration = create_migration(*args) invoke! @generator = nil end
revoke!()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 44 def revoke! capture(:stdout) { @migration.revoke! } end
test_invoke()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 48 def test_invoke create_migration assert_match(/create db\/migrate\/1_create_articles\.rb\n/, invoke!) assert_file @migration.destination end
test_invoke_forced_pretended_when_exists_not_identical()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 95 def test_invoke_forced_pretended_when_exists_not_identical migration_exists! create_migration(default_destination_path, { force: true }, { pretend: true }) do "different content" end stdout = invoke! assert_match(/remove db\/migrate\/1_create_articles\.rb\n/, stdout) assert_match(/create db\/migrate\/2_create_articles\.rb\n/, stdout) assert_no_file @migration.destination end
test_invoke_forced_when_exists_not_identical()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 83 def test_invoke_forced_when_exists_not_identical dest = "db/migrate/migration.rb" migration_exists!(dest) create_migration(dest, force: true) { "different content" } stdout = invoke! assert_match(/remove db\/migrate\/1_migration\.rb\n/, stdout) assert_match(/create db\/migrate\/2_migration\.rb\n/, stdout) assert_file @migration.destination assert_no_file @existing_migration.destination end
test_invoke_pretended()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 55 def test_invoke_pretended create_migration(default_destination_path, {}, { pretend: true }) assert_no_file @migration.destination end
test_invoke_skipped_when_exists_not_identical()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 107 def test_invoke_skipped_when_exists_not_identical migration_exists! create_migration(default_destination_path, {}, { skip: true }) { "different content" } assert_match(/skip db\/migrate\/2_create_articles\.rb\n/, invoke!) assert_no_file @migration.destination end
test_invoke_when_exists()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 61 def test_invoke_when_exists migration_exists! create_migration assert_equal @existing_migration.destination, @migration.existing_migration end
test_invoke_when_exists_identical()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 68 def test_invoke_when_exists_identical migration_exists! create_migration assert_match(/identical db\/migrate\/1_create_articles\.rb\n/, invoke!) assert @migration.identical? end
test_invoke_when_exists_not_identical()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 76 def test_invoke_when_exists_not_identical migration_exists! create_migration { "different content" } assert_raise(Quails::Generators::Error) { invoke! } end
test_revoke()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 115 def test_revoke migration_exists! create_migration assert_match(/remove db\/migrate\/1_create_articles\.rb\n/, revoke!) assert_no_file @existing_migration.destination end
test_revoke_pretended()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 123 def test_revoke_pretended migration_exists! create_migration(default_destination_path, {}, { pretend: true }) assert_match(/remove db\/migrate\/1_create_articles\.rb\n/, revoke!) assert_file @existing_migration.destination end
test_revoke_when_no_exists()
click to toggle source
# File railties/test/generators/create_migration_test.rb, line 131 def test_revoke_when_no_exists create_migration assert_match(/remove db\/migrate\/1_create_articles\.rb\n/, revoke!) end