To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / vendor / plugins / acts_as_versioned / test / migration_test.rb @ 442:753f1380d6bc
History | View | Annotate | Download (1.9 KB)
| 1 |
require File.join(File.dirname(__FILE__), 'abstract_unit') |
|---|---|
| 2 |
|
| 3 |
if ActiveRecord::Base.connection.supports_migrations? |
| 4 |
class Thing < ActiveRecord::Base |
| 5 |
attr_accessor :version
|
| 6 |
acts_as_versioned |
| 7 |
end
|
| 8 |
|
| 9 |
class MigrationTest < Test::Unit::TestCase |
| 10 |
self.use_transactional_fixtures = false |
| 11 |
def teardown |
| 12 |
if ActiveRecord::Base.connection.respond_to?(:initialize_schema_information) |
| 13 |
ActiveRecord::Base.connection.initialize_schema_information |
| 14 |
ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0" |
| 15 |
else
|
| 16 |
ActiveRecord::Base.connection.initialize_schema_migrations_table |
| 17 |
ActiveRecord::Base.connection.assume_migrated_upto_version(0) |
| 18 |
end
|
| 19 |
|
| 20 |
Thing.connection.drop_table "things" rescue nil |
| 21 |
Thing.connection.drop_table "thing_versions" rescue nil |
| 22 |
Thing.reset_column_information
|
| 23 |
end
|
| 24 |
|
| 25 |
def test_versioned_migration |
| 26 |
assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' } |
| 27 |
# take 'er up
|
| 28 |
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/') |
| 29 |
t = Thing.create :title => 'blah blah', :price => 123.45, :type => 'Thing' |
| 30 |
assert_equal 1, t.versions.size
|
| 31 |
|
| 32 |
# check that the price column has remembered its value correctly
|
| 33 |
assert_equal t.price, t.versions.first.price |
| 34 |
assert_equal t.title, t.versions.first.title |
| 35 |
assert_equal t[:type], t.versions.first[:type] |
| 36 |
|
| 37 |
# make sure that the precision of the price column has been preserved
|
| 38 |
assert_equal 7, Thing::Version.columns.find{|c| c.name == "price"}.precision |
| 39 |
assert_equal 2, Thing::Version.columns.find{|c| c.name == "price"}.scale |
| 40 |
|
| 41 |
# now lets take 'er back down
|
| 42 |
ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/') |
| 43 |
assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' } |
| 44 |
end
|
| 45 |
end
|
| 46 |
end
|