mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
stop depending on the filesystem for interleaved migration tests
This commit is contained in:
parent
b932310025
commit
8a3dcd716c
8 changed files with 49 additions and 84 deletions
|
@ -572,27 +572,6 @@ class MigrationTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class InterleavedMigrationsTest < ActiveRecord::TestCase
|
||||
def test_migrator_interleaved_migrations
|
||||
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_1")
|
||||
|
||||
assert_nothing_raised do
|
||||
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_2")
|
||||
end
|
||||
|
||||
Person.reset_column_information
|
||||
assert Person.column_methods_hash.include?(:last_name)
|
||||
|
||||
assert_nothing_raised do
|
||||
proxies = ActiveRecord::Migrator.down(
|
||||
MIGRATIONS_ROOT + "/interleaved/pass_3")
|
||||
names = proxies.map(&:name)
|
||||
assert names.include?('InterleavedPeopleHaveLastNames')
|
||||
assert names.include?('InterleavedInnocentJointable')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ReservedWordsMigrationTest < ActiveRecord::TestCase
|
||||
def test_drop_index_from_table_named_values
|
||||
connection = Person.connection
|
||||
|
|
|
@ -2,6 +2,31 @@ require "cases/helper"
|
|||
|
||||
module ActiveRecord
|
||||
class MigratorTest < ActiveRecord::TestCase
|
||||
# Use this class to sense if migrations have gone
|
||||
# up or down.
|
||||
class Sensor < ActiveRecord::Migration
|
||||
attr_reader :went_up, :went_down
|
||||
|
||||
def initialize name, version
|
||||
super
|
||||
@went_up = false
|
||||
@went_down = false
|
||||
end
|
||||
|
||||
def up; @went_up = true; end
|
||||
def down; @went_down = true; end
|
||||
end
|
||||
|
||||
def setup
|
||||
super
|
||||
ActiveRecord::SchemaMigration.delete_all rescue nil
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
ActiveRecord::SchemaMigration.delete_all rescue nil
|
||||
end
|
||||
|
||||
def test_migrator_with_duplicate_names
|
||||
assert_raises(ActiveRecord::DuplicateMigrationNameError, "Multiple migrations have the name Chunky") do
|
||||
list = [Migration.new('Chunky'), Migration.new('Chunky')]
|
||||
|
@ -57,7 +82,7 @@ module ActiveRecord
|
|||
|
||||
def test_deprecated_constructor
|
||||
assert_deprecated do
|
||||
ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/interleaved/pass_2")
|
||||
ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -80,5 +105,28 @@ module ActiveRecord
|
|||
assert_equal 1, migrations.size
|
||||
assert_equal migration_list.last, migrations.first
|
||||
end
|
||||
|
||||
def test_migrator_interleaved_migrations
|
||||
pass_one = [Sensor.new('One', 1)]
|
||||
|
||||
ActiveRecord::Migrator.new(:up, pass_one).migrate
|
||||
assert pass_one.first.went_up
|
||||
refute pass_one.first.went_down
|
||||
|
||||
pass_two = [Sensor.new('One', 1), Sensor.new('Three', 3)]
|
||||
ActiveRecord::Migrator.new(:up, pass_two).migrate
|
||||
refute pass_two[0].went_up
|
||||
assert pass_two[1].went_up
|
||||
assert pass_two.all? { |x| !x.went_down }
|
||||
|
||||
pass_three = [Sensor.new('One', 1),
|
||||
Sensor.new('Two', 2),
|
||||
Sensor.new('Three', 3)]
|
||||
|
||||
ActiveRecord::Migrator.new(:down, pass_three).migrate
|
||||
assert pass_three[0].went_down
|
||||
refute pass_three[1].went_down
|
||||
assert pass_three[2].went_down
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
class InterleavedInnocentJointable < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table("people_reminders", :id => false) do |t|
|
||||
t.column :reminder_id, :integer
|
||||
t.column :person_id, :integer
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table "people_reminders"
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
class InterleavedPeopleHaveLastNames < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column "people", "last_name", :string
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column "people", "last_name"
|
||||
end
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
class InterleavedInnocentJointable < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table("people_reminders", :id => false) do |t|
|
||||
t.column :reminder_id, :integer
|
||||
t.column :person_id, :integer
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table "people_reminders"
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
class InterleavedPeopleHaveLastNames < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column "people", "last_name", :string
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column "people", "last_name"
|
||||
end
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
class InterleavedIRaiseOnDown < ActiveRecord::Migration
|
||||
def self.up
|
||||
end
|
||||
|
||||
def self.down
|
||||
raise
|
||||
end
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
class InterleavedInnocentJointable < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table("people_reminders", :id => false) do |t|
|
||||
t.column :reminder_id, :integer
|
||||
t.column :person_id, :integer
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table "people_reminders"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue