Mercurial > hg > soundsoftware-site
comparison vendor/plugins/engines/test/unit/.svn/text-base/migration_test.rb.svn-base @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
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 |