Sha256: 3b441905ec7915ab60a61789783213ba2fd680c1b65b0927c8fc5c014cea9992

Contents?: true

Size: 1.61 KB

Versions: 18

Compression:

Stored size: 1.61 KB

Contents

require "active_record"
require_relative "../active_record/models/user"

shared_examples_for "an active record driver" do
  let(:driver) { constant.new(type_translation: true) }
  let(:db) { driver.db }
  let(:db_with_type_translation) { constant.new(type_translation: true, debug: false).db }
  let(:row) do
    test_table.insert(text: "Kasper", number: 30, float: 4.5)
    db.select(:test, text: "Kasper").fetch
  end
  let(:test_table) do
    db.tables.create(
      "test",
      columns: [
        {name: "id", type: :int, autoincr: true, primarykey: true},
        {name: "text", type: :varchar},
        {name: "number", type: :int, default: 0},
        {name: "float", type: :float, default: 0.0}
      ]
    )
    db.tables[:test]
  end

  before do
    driver.before

    db.tables.create(
      "users",
      columns: [
        {name: "id", type: :int, autoincr: true, primarykey: true},
        {name: "email", type: :varchar}
      ],
      indexes: [
        {name: "index_on_email", columns: ["email"], unique: true}
      ]
    )
  end

  after do
    driver.after
  end

  it "saves models through baza" do
    user = User.new(email: "test@example.com")
    expect(user.valid?).to eq true
    db.driver.save_model!(user, update_on_duplicate_key: true)
    expect(user.persisted?).to eq true
    expect(user.id).to eq 1
    expect(user.email).to eq "test@example.com"
  end

  it "upserts" do
    user1 = User.new(email: "test@example.com")
    db.driver.save_model!(user1)

    user2 = User.new(email: "test@example.com")
    db.driver.save_model!(user2, update_on_duplicate_key: true)

    expect(user2.id).to eq user1.id
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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