Sha256: c092d591aa30b35558e7e3293a7118f91434c277ec94471deda45e27c4717187

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require "key_vortex/record"
require "securerandom"

class SampleRecord < KeyVortex::Record
  field :sample, String, length: 10
end

class SampleRecordTwo < KeyVortex::Record
  field :sample, String, length: 10
end

require "rantly/rspec_extensions"

RSpec.shared_context "an adapter" do
  around(:each) do |s|
    property_of { string }.check(100) do |sample|
      @sample = sample
      s.run
    end
  end

  let(:store) do
    KeyVortex.new(
      subject,
      SampleRecord
    )
  end

  let(:record1) do
    SampleRecord.new(
      key: SecureRandom.uuid,
      sample: @sample
    )
  end

  let(:record2) do
    SampleRecordTwo.new(
      key: SecureRandom.uuid,
      sample: @sample
    )
  end

  it "stores and removes a key" do
    store.save(record)
    expect(store.find(record.key)).to eq(record)
    subject.remove(record.key)
    expect(store.find(record.key)).to be_nil
  end

  it "recreates the class that was provided" do
    store.save(record.key)
    expect(store.find(record.key)).to be_a(SampleRecord)
    store.save(record2)
    expect(store.find(record2.key)).to be_a(SampleRecordTwo)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
key_vortex-contract-0.2.1 lib/key_vortex/contract.rb