Sha256: 18cf7d52130943acf0b0f6aab2aadede4d08d5cfe7d326b82c3013e3a06abc45

Contents?: true

Size: 955 Bytes

Versions: 4

Compression:

Stored size: 955 Bytes

Contents

require_relative '../spec_helper'

require 'dm-migrations/auto_migration'

module ::Blog
  class Article
    include DataMapper::Resource

    property :id, Serial
  end
end

describe DataMapper::Migrations do
  def capture_log(mod)
    original = mod.logger
    mod.logger = DataObjects::Logger.new(@log = StringIO.new, :debug)
    yield
  ensure
    @log.rewind
    @output = @log.readlines.map do |line|
      line.chomp.gsub(/\A.+?~ \(\d+\.?\d*\)\s+/, '')
    end

    mod.logger = original
  end

  supported_by :postgres do
    before :all do
      @model = Blog::Article
    end

    describe '#auto_upgrade' do
      it 'creates an index' do
        @model.auto_migrate!
        @property = @model.property(:name, String, index: true)
        @response = capture_log(DataObjects::Postgres) { @model.auto_upgrade! }
        expect(@output[-2]).to eq 'CREATE INDEX "index_blog_articles_name" ON "blog_articles" ("name")'
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sbf-dm-migrations-1.4.0 spec/integration/auto_upgrade_spec.rb
sbf-dm-migrations-1.4.0.beta.1 spec/integration/auto_upgrade_spec.rb
sbf-dm-migrations-1.3.0 spec/integration/auto_upgrade_spec.rb
sbf-dm-migrations-1.3.0.beta spec/integration/auto_upgrade_spec.rb