annotate .svn/pristine/f7/f78e5d10fa36c8cdc9c486adcff944bf87c87548.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 require File.join(File.dirname(__FILE__), 'abstract_unit')
Chris@909 2
Chris@909 3 if ActiveRecord::Base.connection.supports_migrations?
Chris@909 4 class Thing < ActiveRecord::Base
Chris@909 5 attr_accessor :version
Chris@909 6 acts_as_versioned
Chris@909 7 end
Chris@909 8
Chris@909 9 class MigrationTest < Test::Unit::TestCase
Chris@909 10 self.use_transactional_fixtures = false
Chris@909 11 def teardown
Chris@909 12 if ActiveRecord::Base.connection.respond_to?(:initialize_schema_information)
Chris@909 13 ActiveRecord::Base.connection.initialize_schema_information
Chris@909 14 ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0"
Chris@909 15 else
Chris@909 16 ActiveRecord::Base.connection.initialize_schema_migrations_table
Chris@909 17 ActiveRecord::Base.connection.assume_migrated_upto_version(0)
Chris@909 18 end
Chris@909 19
Chris@909 20 Thing.connection.drop_table "things" rescue nil
Chris@909 21 Thing.connection.drop_table "thing_versions" rescue nil
Chris@909 22 Thing.reset_column_information
Chris@909 23 end
Chris@909 24
Chris@909 25 def test_versioned_migration
Chris@909 26 assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' }
Chris@909 27 # take 'er up
Chris@909 28 ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/')
Chris@909 29 t = Thing.create :title => 'blah blah', :price => 123.45, :type => 'Thing'
Chris@909 30 assert_equal 1, t.versions.size
Chris@909 31
Chris@909 32 # check that the price column has remembered its value correctly
Chris@909 33 assert_equal t.price, t.versions.first.price
Chris@909 34 assert_equal t.title, t.versions.first.title
Chris@909 35 assert_equal t[:type], t.versions.first[:type]
Chris@909 36
Chris@909 37 # make sure that the precision of the price column has been preserved
Chris@909 38 assert_equal 7, Thing::Version.columns.find{|c| c.name == "price"}.precision
Chris@909 39 assert_equal 2, Thing::Version.columns.find{|c| c.name == "price"}.scale
Chris@909 40
Chris@909 41 # now lets take 'er back down
Chris@909 42 ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/')
Chris@909 43 assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' }
Chris@909 44 end
Chris@909 45 end
Chris@909 46 end