Skip to content

Commit

Permalink
use one based indexes for the mock migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 16, 2012
1 parent 867f504 commit b731593
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions activerecord/test/cases/migrator_test.rb
Expand Up @@ -160,11 +160,11 @@ def test_migrator_one_up
calls, migrations = sensors(3)

ActiveRecord::Migrator.new(:up, migrations, 1).migrate
assert_equal [[:up, 1], [:up, 2]], calls
assert_equal [[:up, 1]], calls
calls.clear

ActiveRecord::Migrator.new(:up, migrations, 2).migrate
assert_equal [[:up, 3]], calls
assert_equal [[:up, 2]], calls
end

def test_migrator_one_down
Expand All @@ -176,26 +176,26 @@ def test_migrator_one_down

ActiveRecord::Migrator.new(:down, migrations, 1).migrate

assert_equal [[:down, 3]], calls
assert_equal [[:down, 3], [:down, 2]], calls
end

def test_migrator_one_up_one_down
calls, migrations = sensors(3)

ActiveRecord::Migrator.new(:up, migrations, 1).migrate
assert_equal [[:up, 1], [:up, 2]], calls
assert_equal [[:up, 1]], calls
calls.clear

ActiveRecord::Migrator.new(:down, migrations, 0).migrate
assert_equal [[:down, 2]], calls
assert_equal [[:down, 1]], calls
end

def test_migrator_double_up
calls, migrations = sensors(3)
assert_equal(0, ActiveRecord::Migrator.current_version)

ActiveRecord::Migrator.new(:up, migrations, 1).migrate
assert_equal [[:up, 1], [:up, 2]], calls
assert_equal [[:up, 1]], calls
calls.clear

ActiveRecord::Migrator.new(:up, migrations, 1).migrate
Expand All @@ -208,11 +208,11 @@ def test_migrator_double_down
assert_equal(0, ActiveRecord::Migrator.current_version)

ActiveRecord::Migrator.new(:up, migrations, 1).run
assert_equal [[:up, 2]], calls
assert_equal [[:up, 1]], calls
calls.clear

ActiveRecord::Migrator.new(:down, migrations, 1).run
assert_equal [[:down, 2]], calls
assert_equal [[:down, 1]], calls
calls.clear

ActiveRecord::Migrator.new(:down, migrations, 1).run
Expand Down Expand Up @@ -250,12 +250,12 @@ def test_target_version_zero_should_run_only_once

# migrate up to 1
ActiveRecord::Migrator.new(:up, migrations, 1).migrate
assert_equal [[:up, 1], [:up, 2]], calls
assert_equal [[:up, 1]], calls
calls.clear

# migrate down to 0
ActiveRecord::Migrator.new(:down, migrations, 0).migrate
assert_equal [[:down, 2]], calls
assert_equal [[:down, 1]], calls
calls.clear

# migrate down to 0 again
Expand All @@ -267,19 +267,19 @@ def test_migrator_going_down_due_to_version_target
calls, migrator = migrator_class(3)

migrator.up("valid", 1)
assert_equal [[:up, 1], [:up, 2]], calls
assert_equal [[:up, 1]], calls
calls.clear

migrator.migrate("valid", 0)
assert_equal [[:down, 2]], calls
assert_equal [[:down, 1]], calls
calls.clear

migrator.migrate("valid")
assert_equal [[:up, 2], [:up, 3]], calls
assert_equal [[:up, 1], [:up, 2], [:up, 3]], calls
end

def test_migrator_rollback
_, migrator = migrator_class(4)
_, migrator = migrator_class(3)

migrator.migrate("valid")
assert_equal(3, ActiveRecord::Migrator.current_version)
Expand Down Expand Up @@ -330,8 +330,8 @@ def m(name, version, &block)
def sensors(count)
calls = []
migrations = count.times.map { |i|
m(nil, i) { |c,migration|
calls << [c, migration.version + 1]
m(nil, i + 1) { |c,migration|
calls << [c, migration.version]
}
}
[calls, migrations]
Expand Down

0 comments on commit b731593

Please sign in to comment.