Sha256: 82fe5885675ae2d2a092eb547e5d4238b2544af39efad3a1a26d764051aae2af

Contents?: true

Size: 1.28 KB

Versions: 17

Compression:

Stored size: 1.28 KB

Contents

shared_examples_for "a baza foreign keys driver" do
  let(:driver) { constant.new }
  let(:db) { driver.db }
  let(:posts_table) do
    db.tables.create(
      "posts",
      columns: [
        {name: "id", type: :int, autoincr: true, primarykey: true},
        {name: "user_id", type: :int},
        {name: "text", type: :varchar}
      ]
    )
    db.tables[:posts]
  end
  let(:users_table) do
    db.tables.create(
      "users",
      columns: [
        {name: "id", type: :int, autoincr: true, primarykey: true},
        {name: "email", type: :varchar}
      ]
    )
    db.tables[:users]
  end
  let(:users_id_column) { users_table.column("id") }
  let(:user_id_foreign_key) do
    posts_table.column("user_id").create_foreign_key(
      column: users_id_column,
      name: "test_column_key"
    )
    posts_table.foreign_key("test_column_key")
  end

  before do
    driver.before
  end

  after do
    driver.after
  end

  it "creates foreign keys" do
    user_id_foreign_key

    expect(posts_table.foreign_keys.length).to eq 1
    expect(posts_table.foreign_key("test_column_key").name).to eq "test_column_key"
  end

  it "destroys foreign keys" do
    user_id_foreign_key.drop

    expect { posts_table.foreign_key("test_column_key") }.to raise_error(Baza::Errors::ForeignKeyNotFound)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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