Sha256: 83008f90510fd6207ec5f70bd7ec026b771d44eb5bdfe91f251cce63c0dee8f3

Contents?: true

Size: 1.64 KB

Versions: 17

Compression:

Stored size: 1.64 KB

Contents

shared_examples_for "a baza indexes driver" do
  let(:driver) { constant.new }
  let(:db) { driver.db }
  let(:test_table) do
    db.tables.create(
      "test",
      columns: [
        {name: "id", type: :int, autoincr: true, primarykey: true},
        {name: "text", type: :varchar},
        {name: "email", type: :varchar}
      ],
      indexes: [
        :text,
        {name: :email, unique: true, columns: [:email]},
        {name: :two_columns, columns: [:text, :email]}
      ]
    )
    db.tables[:test]
  end

  before do
    driver.before
  end

  after do
    driver.after
  end

  it "renames indexes for renamed tables" do
    # Load up columns to make them set table-name.
    test_table.indexes.each do |name, index|
    end

    test_table.create_indexes([{name: "index_on_text", columns: [:text]}])
    test_table.rename("test2")
    test_table.index("index_on_text").rename("index_on_text2")

    table = db.tables[:test2]
    index = table.index(:index_on_text2)
    expect(index.table.name).to eq "test2"
  end

  it "raises an error when an index isn't found" do
    expect do
      test_table.index("index_that_doesnt_exist")
    end.to raise_error(Baza::Errors::IndexNotFound)
  end

  describe Baza::Index do
    describe "#unique?" do
      it "returns true when it is unique" do
        expect(test_table.index("email").unique?).to eq true
      end

      it "returns false when it isn't unique" do
        expect(test_table.index("text").unique?).to eq false
      end
    end

    describe "#columns" do
      it "returns the correct columns" do
        expect(test_table.index("two_columns").columns).to eq %w(text email)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
baza-0.0.38 spec/support/driver_indexes_collection.rb
baza-0.0.37 spec/support/driver_indexes_collection.rb
baza-0.0.36 spec/support/driver_indexes_collection.rb
baza-0.0.35 spec/support/driver_indexes_collection.rb
baza-0.0.34 spec/support/driver_indexes_collection.rb
baza-0.0.33 spec/support/driver_indexes_collection.rb
baza-0.0.32 spec/support/driver_indexes_collection.rb
baza-0.0.31 spec/support/driver_indexes_collection.rb
baza-0.0.30 spec/support/driver_indexes_collection.rb
baza-0.0.29 spec/support/driver_indexes_collection.rb
baza-0.0.28 spec/support/driver_indexes_collection.rb
baza-0.0.27 spec/support/driver_indexes_collection.rb
baza-0.0.26 spec/support/driver_indexes_collection.rb
baza-0.0.25 spec/support/driver_indexes_collection.rb
baza-0.0.24 spec/support/driver_indexes_collection.rb
baza-0.0.23 spec/support/driver_indexes_collection.rb
baza-0.0.22 spec/support/driver_indexes_collection.rb