Skip to content

Commit

Permalink
stop depending on the filesystem for interleaved migration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 13, 2012
1 parent b932310 commit 8a3dcd7
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 84 deletions.
21 changes: 0 additions & 21 deletions activerecord/test/cases/migration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -572,27 +572,6 @@ def with_env_tz(new_tz = 'US/Eastern')
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
Expand Down
50 changes: 49 additions & 1 deletion activerecord/test/cases/migrator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

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')]
Expand Down Expand Up @@ -57,7 +82,7 @@ def test_finds_migrations_from_two_directories

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

Expand All @@ -80,5 +105,28 @@ def test_finds_pending_migrations
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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 8a3dcd7

Please sign in to comment.