Sha256: aae6779eafa77579bf621889c066cc153f032096a5484d513cfab763bb5c05bb

Contents?: true

Size: 1.85 KB

Versions: 34

Compression:

Stored size: 1.85 KB

Contents

require 'spec'
require 'ruby_ext'
require "#{File.dirname __FILE__}/../../lib/mongo_mapper_ext"
require "#{File.dirname __FILE__}/../../lib/mongo_mapper_ext/spec_helper"


describe "MongoMapper Migration" do
  Migration = MongoMapper::Migration  
  
  before :all do
    MongoMapper.db_config = {
      'global' => {'name' => 'global_test'},
      'accounts' => {'name' => "accounts_test"}
    }
    
    class ::Sample
      include MongoMapper::Document
      use_database :global

      key :name, String
    end
    
    Migration.logger = nil
  end

  after :all do
    Object.send :remove_const, :Sample if Object.const_defined? :Sample
  end
  
  before :each do
    Migration.definitions.clear
  end
  
  it "Shouldn't update if versions are the same" do
    Migration.update(:global, 0).should be_false
  end
  
  it "migration should provide access to current database" do
    Sample.count.should == 0    
    Migration.define :global, 1 do |m|
      m.up do |db|
        Sample.create :name => 'name'
        coll = db.collection 'samples'
        coll.find.count.should == 1
      end
    end
  
    Migration.update(:global, 1).should be_true    
    Sample.count.should == 1
  end

  it "increase_db_version" do
    Sample.count.should == 0
    Migration.define :global, 1 do |m|
      m.up{Sample.create :name => 'name'}
    end
  
    Migration.update(:global, 1).should be_true    
    Sample.count.should == 1
    Migration.metadata(MongoMapper.databases[:global]).should == 1
  end

  it "decrease_db_version" do    
    Migration.define :global, 1 do |m|
      m.up{Sample.create :name => 'name'}
      m.down{Sample.destroy_all}
    end
    Migration.update(:global, 1).should be_true
    Sample.count.should == 1
  
    Migration.update(:global, 0).should be_true
    Sample.count.should == 0
    Migration.metadata(MongoMapper.databases[:global]).should == 0
  end
    
end

Version data entries

34 entries across 31 versions & 2 rubygems

Version Path
crystal-ext-0.0.3 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
crystal-ext-0.0.3 lib/rails_ext/spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
crystal-ext-0.0.2 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
crystal-ext-0.0.2 lib/rails_ext/spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
crystal-ext-0.0.1 lib/rails_ext/spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
crystal-ext-0.0.1 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.29 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.28 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.27 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.25 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.24 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.23 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.22 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.21 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.20 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.19 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.18 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.17 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.16 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
rails-ext-0.3.15 spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb