class CopyMigrationsTest

Public Instance Methods

clear() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 900
def clear
  ActiveRecord::Base.timestamped_migrations = true
  to_delete = Dir[@migrations_path + "/*.rb"] - @existing_migrations
  File.delete(*to_delete)
end
setup() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 897
def setup
end
test_check_pending_with_stdlib_logger() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 1097
def test_check_pending_with_stdlib_logger
  old, ActiveRecord::Base.logger = ActiveRecord::Base.logger, ::Logger.new($stdout)
  quietly do
    assert_nothing_raised { ActiveRecord::Migration::CheckPending.new(Proc.new {}).call({}) }
  end
ensure
  ActiveRecord::Base.logger = old
end
test_copying_migrations_preserving_magic_comments() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 1011
def test_copying_migrations_preserving_magic_comments
  ActiveRecord::Base.timestamped_migrations = false
  @migrations_path = MIGRATIONS_ROOT + "/valid"
  @existing_migrations = Dir[@migrations_path + "/*.rb"]

  copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/magic")
  assert File.exist?(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")
  assert_equal [@migrations_path + "/4_currencies_have_symbols.bukkits.rb"], copied.map(&:filename)

  expected = "# frozen_string_literal: true\n# coding: ISO-8859-15\n# This migration comes from bukkits (originally 1)"
  assert_equal expected, IO.readlines(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")[0..2].join.chomp

  files_count = Dir[@migrations_path + "/*.rb"].length
  copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/magic")
  assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
  assert copied.empty?
ensure
  clear
end
test_copying_migrations_to_empty_directory() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 1083
def test_copying_migrations_to_empty_directory
  @migrations_path = MIGRATIONS_ROOT + "/empty"
  @existing_migrations = []

  travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
    copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/to_copy_with_timestamps")
    assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
    assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
    assert_equal 2, copied.length
  end
ensure
  clear
end
test_copying_migrations_to_non_existing_directory() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 1068
def test_copying_migrations_to_non_existing_directory
  @migrations_path = MIGRATIONS_ROOT + "/non_existing"
  @existing_migrations = []

  travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
    copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/to_copy_with_timestamps")
    assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
    assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
    assert_equal 2, copied.length
  end
ensure
  clear
  Dir.delete(@migrations_path)
end
test_copying_migrations_with_timestamps() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 948
def test_copying_migrations_with_timestamps
  @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
  @existing_migrations = Dir[@migrations_path + "/*.rb"]

  travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
    copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/to_copy_with_timestamps")
    assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
    assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
    expected = [@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb",
                @migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb"]
    assert_equal expected, copied.map(&:filename)

    files_count = Dir[@migrations_path + "/*.rb"].length
    copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/to_copy_with_timestamps")
    assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
    assert copied.empty?
  end
ensure
  clear
end
test_copying_migrations_with_timestamps_from_2_sources() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 969
def test_copying_migrations_with_timestamps_from_2_sources
  @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
  @existing_migrations = Dir[@migrations_path + "/*.rb"]

  sources = {}
  sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
  sources[:omg]     = MIGRATIONS_ROOT + "/to_copy_with_timestamps2"

  travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
    copied = ActiveRecord::Migration.copy(@migrations_path, sources)
    assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
    assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
    assert File.exist?(@migrations_path + "/20100726101012_create_articles.omg.rb")
    assert File.exist?(@migrations_path + "/20100726101013_create_comments.omg.rb")
    assert_equal 4, copied.length

    files_count = Dir[@migrations_path + "/*.rb"].length
    ActiveRecord::Migration.copy(@migrations_path, sources)
    assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
  end
ensure
  clear
end
test_copying_migrations_with_timestamps_to_destination_with_timestamps_in_future() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 993
def test_copying_migrations_with_timestamps_to_destination_with_timestamps_in_future
  @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
  @existing_migrations = Dir[@migrations_path + "/*.rb"]

  travel_to(Time.utc(2010, 2, 20, 10, 10, 10)) do
    ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/to_copy_with_timestamps")
    assert File.exist?(@migrations_path + "/20100301010102_people_have_hobbies.bukkits.rb")
    assert File.exist?(@migrations_path + "/20100301010103_people_have_descriptions.bukkits.rb")

    files_count = Dir[@migrations_path + "/*.rb"].length
    copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/to_copy_with_timestamps")
    assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
    assert copied.empty?
  end
ensure
  clear
end
test_copying_migrations_without_timestamps() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 906
def test_copying_migrations_without_timestamps
  ActiveRecord::Base.timestamped_migrations = false
  @migrations_path = MIGRATIONS_ROOT + "/valid"
  @existing_migrations = Dir[@migrations_path + "/*.rb"]

  copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/to_copy")
  assert File.exist?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
  assert File.exist?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
  assert_equal [@migrations_path + "/4_people_have_hobbies.bukkits.rb", @migrations_path + "/5_people_have_descriptions.bukkits.rb"], copied.map(&:filename)

  expected = "# This migration comes from bukkits (originally 1)"
  assert_equal expected, IO.readlines(@migrations_path + "/4_people_have_hobbies.bukkits.rb")[1].chomp

  files_count = Dir[@migrations_path + "/*.rb"].length
  copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/to_copy")
  assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
  assert copied.empty?
ensure
  clear
end
test_copying_migrations_without_timestamps_from_2_sources() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 927
def test_copying_migrations_without_timestamps_from_2_sources
  ActiveRecord::Base.timestamped_migrations = false
  @migrations_path = MIGRATIONS_ROOT + "/valid"
  @existing_migrations = Dir[@migrations_path + "/*.rb"]

  sources = {}
  sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy"
  sources[:omg] = MIGRATIONS_ROOT + "/to_copy2"
  ActiveRecord::Migration.copy(@migrations_path, sources)
  assert File.exist?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
  assert File.exist?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
  assert File.exist?(@migrations_path + "/6_create_articles.omg.rb")
  assert File.exist?(@migrations_path + "/7_create_comments.omg.rb")

  files_count = Dir[@migrations_path + "/*.rb"].length
  ActiveRecord::Migration.copy(@migrations_path, sources)
  assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
ensure
  clear
end
test_deprecate_initialize_internal_tables() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 1110
def test_deprecate_initialize_internal_tables
  assert_deprecated { ActiveRecord::Base.connection.initialize_schema_migrations_table }
  assert_deprecated { ActiveRecord::Base.connection.initialize_internal_metadata_table }
end
test_deprecate_schema_migrations_table_name() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 1119
def test_deprecate_schema_migrations_table_name
  assert_deprecated { ActiveRecord::Migrator.schema_migrations_table_name }
end
test_deprecate_supports_migrations() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 1115
def test_deprecate_supports_migrations
  assert_deprecated { ActiveRecord::Base.connection.supports_migrations? }
end
test_skip_is_not_called_if_migrations_are_from_the_same_plugin() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 1050
def test_skip_is_not_called_if_migrations_are_from_the_same_plugin
  @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
  @existing_migrations = Dir[@migrations_path + "/*.rb"]

  sources = {}
  sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"

  skipped = []
  on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
  copied = ActiveRecord::Migration.copy(@migrations_path, sources, on_skip: on_skip)
  ActiveRecord::Migration.copy(@migrations_path, sources, on_skip: on_skip)

  assert_equal 2, copied.length
  assert_equal 0, skipped.length
ensure
  clear
end
test_skipping_migrations() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 1031
def test_skipping_migrations
  @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
  @existing_migrations = Dir[@migrations_path + "/*.rb"]

  sources = {}
  sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
  sources[:omg]     = MIGRATIONS_ROOT + "/to_copy_with_name_collision"

  skipped = []
  on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
  copied = ActiveRecord::Migration.copy(@migrations_path, sources, on_skip: on_skip)
  assert_equal 2, copied.length

  assert_equal 1, skipped.length
  assert_equal ["omg PeopleHaveHobbies"], skipped
ensure
  clear
end
test_unknown_migration_version_should_raise_an_argument_error() click to toggle source
# File activerecord/test/cases/migration_test.rb, line 1106
def test_unknown_migration_version_should_raise_an_argument_error
  assert_raise(ArgumentError) { ActiveRecord::Migration[1.0] }
end