Sha256: 7ce29b6cdd16c54ed4d9d0059a5035fa511bf3ec5daaf11b18143b4dfcf377f0

Contents?: true

Size: 1.7 KB

Versions: 2

Compression:

Stored size: 1.7 KB

Contents

shared_examples_for "a baza indexes driver" do
  let(:constant){
    name = described_class.name.split("::").last
    const_name = "Info#{name.slice(0, 1).upcase}#{name.slice(1, name.length)}"
    require "#{File.dirname(__FILE__)}/../info_#{StringCases.camel_to_snake(name)}"
    raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
    Baza.const_get(const_name)
  }
  let(:driver){ constant.new }
  let(:db){ driver.db }
  let(:test_table){
    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]}
      ]
    })
    db.tables[:test]
  }

  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)
    index.table.name.should eq :test2
  end

  it "should raise an error when index is not found" do
    expect {
      test_table.index("index_that_doesnt_exist")
    }.to raise_error(Errno::ENOENT)
  end

  describe "#unique?" do
    it "returns true when it is unique" do
      test_table.index("email").unique?.should eq true
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
baza-0.0.17 spec/support/driver_indexes_collection.rb
baza-0.0.16 spec/support/driver_indexes_collection.rb