Class: MigrationTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/plugins/acts_as_versioned/test/migration_test.rb

Instance Method Summary collapse

Instance Method Details

#teardownObject


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/plugins/acts_as_versioned/test/migration_test.rb', line 11

def teardown
  if ActiveRecord::Base.connection.respond_to?(:initialize_schema_information)
    ActiveRecord::Base.connection.initialize_schema_information
    ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0"
  else
    ActiveRecord::Base.connection.initialize_schema_migrations_table
    ActiveRecord::Base.connection.assume_migrated_upto_version(0)
  end
  
  Thing.connection.drop_table "things" rescue nil
  Thing.connection.drop_table "thing_versions" rescue nil
  Thing.reset_column_information
end

#test_versioned_migrationObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/plugins/acts_as_versioned/test/migration_test.rb', line 25

def test_versioned_migration
  assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' }
  # take 'er up
  ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/')
  t = Thing.create :title => 'blah blah', :price => 123.45, :type => 'Thing'
  assert_equal 1, t.versions.size
  
  # check that the price column has remembered its value correctly
  assert_equal t.price,  t.versions.first.price
  assert_equal t.title,  t.versions.first.title
  assert_equal t[:type], t.versions.first[:type]
  
  # make sure that the precision of the price column has been preserved
  assert_equal 7, Thing::Version.columns.find{|c| c.name == "price"}.precision
  assert_equal 2, Thing::Version.columns.find{|c| c.name == "price"}.scale

  # now lets take 'er back down
  ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/')
  assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' }
end