Sha256: 26f22518ca08bcf3421572ae8499916e3f7254cfc0f6146c964c73bfb57d583f

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

describe DataMigrate::DataMigrator do
  let(:subject) { DataMigrate::DataMigrator }
  let(:db_config) do
    {
      adapter: "sqlite3",
      database: "spec/db/test.db"
    }
  end

  describe :assure_data_schema_table do
    before do
      expect(subject).to receive(:db_config) { db_config }.at_least(:once)
      ActiveRecord::Base.establish_connection(db_config)
    end

    after do
      ActiveRecord::Migration.drop_table("data_migrations")
    end

    it do
      expect(
        ActiveRecord::Base.connection.table_exists?("data_migrations")
      ).to eq false
      subject.assure_data_schema_table
      expect(
        ActiveRecord::Base.connection.table_exists?("data_migrations")
      ).to eq true
    end
  end

  describe :schema_migrations_table_name do
    it "returns correct table name" do
      expect(subject.schema_migrations_table_name).to eq("data_migrations")
    end
  end

  describe :migrations_path do
    it "returns correct migrations path" do
      expect(subject.migrations_path).to eq("db/data")
    end
  end

  describe :match do
    context "when the file does not match" do
      it "returns nil" do
        expect(subject.match("not_a_data_migration_file")).to be_nil
      end
    end

    context "when the file matches" do
      it "returns a valid MatchData object" do
        match_data = subject.match("20091231235959_some_name.rb")

        expect(match_data[0]).to eq "20091231235959_some_name.rb"
        expect(match_data[1]).to eq "20091231235959"
        expect(match_data[2]).to eq "some_name"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
data_migrate-3.5.0 spec/data_migrate/data_migrator_spec.rb
data_migrate-3.4.0 spec/data_migrate/data_migrator_spec.rb
data_migrate-3.3.1 spec/data_migrate/data_migrator_spec.rb
data_migrate-3.3.0 spec/data_migrate/data_migrator_spec.rb