Sha256: d0aa7804c30e4759db31572d90645294d0b3ea0e278ffc13cbada89e32932aa2

Contents?: true

Size: 1.9 KB

Versions: 25

Compression:

Stored size: 1.9 KB

Contents

require File.join(File.dirname(__FILE__), 'abstract_unit')

if ActiveRecord::Base.connection.supports_migrations? 
  class Thing < ActiveRecord::Base
    attr_accessor :version
    acts_as_versioned
  end

  class MigrationTest < ActiveSupport::TestCase
    self.use_transactional_fixtures = false
    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
        
    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
  end
end

Version data entries

25 entries across 25 versions & 6 rubygems

Version Path
rtiss_acts_as_versioned-0.8.2 test/migration_test.rb
rtiss_acts_as_versioned-0.7.9 test/migration_test.rb
rtiss_acts_as_versioned-0.7.8 test/migration_test.rb
rtiss_acts_as_versioned-0.7.7 test/migration_test.rb
rtiss_acts_as_versioned-0.7.6 test/migration_test.rb
rtiss_acts_as_versioned-0.8.1 test/migration_test.rb
rtiss_acts_as_versioned-0.7.5 test/migration_test.rb
rtiss_acts_as_versioned-0.8.0 test/migration_test.rb
rtiss_acts_as_versioned-0.7.4 test/migration_test.rb
rtiss_acts_as_versioned-0.6.2 test/migration_test.rb
rtiss_acts_as_versioned-0.7.3 test/migration_test.rb
rtiss_acts_as_versioned-0.7.2 test/migration_test.rb
freerange_acts_as_versioned-1.0.0 test/migration_test.rb
imagine_cms-3.0.0.beta6 vendor/gems/acts_as_versioned/test/migration_test.rb
imagine_cms-3.0.0.beta5 vendor/gems/acts_as_versioned/test/migration_test.rb
imagine_cms-3.0.0.beta4 vendor/gems/acts_as_versioned/test/migration_test.rb
freerange_acts_as_versioned-0.8.2 test/migration_test.rb
freerange_acts_as_versioned-0.8.1 test/migration_test.rb
freerange_acts_as_versioned-0.8.0 test/migration_test.rb
imagine_cms-3.0.0.beta3 vendor/gems/acts_as_versioned/test/migration_test.rb