To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 8b / 8b0c72afd0d7787739416aa1510d0e28d12a95ed.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (1.99 KB)

1
require File.dirname(__FILE__) + '/../test_helper'
2
require 'rails_generator'
3
require 'rails_generator/scripts/generate'
4

    
5
class MigrationsTest < Test::Unit::TestCase
6
  
7
  @@migration_dir = "#{RAILS_ROOT}/db/migrate"
8

    
9
  def setup
10
    ActiveRecord::Migration.verbose = false
11
    Engines.plugins[:test_migration].migrate(0)
12
  end
13
  
14
  def teardown
15
    FileUtils.rm_r(@@migration_dir) if File.exist?(@@migration_dir)
16
  end
17
  
18
  def test_engine_migrations_can_run_down
19
    assert !table_exists?('tests'), ActiveRecord::Base.connection.tables.inspect
20
    assert !table_exists?('others'), ActiveRecord::Base.connection.tables.inspect
21
    assert !table_exists?('extras'), ActiveRecord::Base.connection.tables.inspect
22
  end
23
    
24
  def test_engine_migrations_can_run_up
25
    Engines.plugins[:test_migration].migrate(3)
26
    assert table_exists?('tests')
27
    assert table_exists?('others')
28
    assert table_exists?('extras')
29
  end
30
  
31
  def test_engine_migrations_can_upgrade_incrementally
32
    Engines.plugins[:test_migration].migrate(1)
33
    assert table_exists?('tests')
34
    assert !table_exists?('others')
35
    assert !table_exists?('extras')
36
    assert_equal 1, Engines::Plugin::Migrator.current_version(Engines.plugins[:test_migration])
37
    
38
    
39
    Engines.plugins[:test_migration].migrate(2)
40
    assert table_exists?('others')
41
    assert_equal 2, Engines::Plugin::Migrator.current_version(Engines.plugins[:test_migration])
42
    
43
    
44
    Engines.plugins[:test_migration].migrate(3)
45
    assert table_exists?('extras')
46
    assert_equal 3, Engines::Plugin::Migrator.current_version(Engines.plugins[:test_migration])
47
  end
48
    
49
  def test_generator_creates_plugin_migration_file
50
    Rails::Generator::Scripts::Generate.new.run(['plugin_migration', 'test_migration'], :quiet => true)
51
    assert migration_file, "migration file is missing"
52
  end
53
  
54
  private
55
  
56
  def table_exists?(table)
57
    ActiveRecord::Base.connection.tables.include?(table)
58
  end
59
  
60
  def migration_file
61
    Dir["#{@@migration_dir}/*test_migration_to_version_3.rb"][0]
62
  end
63
end