Sha256: 7332704b7049b9963e99f0a21adf83a7a64e218da1383ba9314fb0db983c9c59

Contents?: true

Size: 1.52 KB

Versions: 54

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

require_relative '../../../../lib/locomotive/steam/adapters/memory/dataset.rb'

describe Locomotive::Steam::Adapters::Memory::Dataset do

  let(:john) do
    {
      firstname: 'John',
      lastname: 'Doe',
      email: 'john@example.com',
      age: 24
    }
  end

  let(:jane) do
    {
      firstname: 'Jane',
      lastname: 'Doe',
      email: 'jane@example.com',
      age: 20
    }
  end

  let(:alex) do
    {
      firstname: 'Alex',
      lastname: 'Turam',
      email: 'alex@example.com',
      age: 26
    }
  end

  subject { Locomotive::Steam::Adapters::Memory::Dataset.new(:foo) } #(loader) }

  before do
    [john.to_hash, jane.to_hash, alex.to_hash].each do |record|
      subject.insert record
    end
  end

  describe '#all' do
    it { expect(subject.all).to eq [john.to_hash, jane.to_hash, alex.to_hash] }
  end

  describe '#find' do
    specify do
      expect(subject.find(john[:_id])).to eq(john.to_hash)
    end
  end

  describe '#update' do
    before do
      subject.update(jane.to_hash.merge(lastname: 'birkin'))
    end

    specify do
      expect(subject.find(jane[:_id]).fetch(:lastname)).to eq('birkin')
    end
  end

  describe '#exists?' do
    let(:dataset) { Locomotive::Steam::Adapters::Memory::Dataset.new(:dummy) }
    before do
      dataset.instance_variable_set('@records', { 1 => 'Record 1', 2 => 'Record 2' })
    end

    it { expect(dataset.exists?(2)).to eq true  }
    it { expect(dataset.exists?(3)).to eq false  }
    it { expect(dataset.exists?(nil)).to eq false  }

  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.rc9 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.rc8 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.rc6 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.rc4 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.rc3 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.rc2 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.rc1 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.pre.beta.3 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.pre.beta.2 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.pre.beta.1 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.pre.alpha.3 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.pre.alpha.2 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.pre.alpha.1 spec/unit/adapters/memory/dataset_spec.rb
locomotivecms_steam-1.0.0.pre.alpha spec/unit/adapters/memory/dataset_spec.rb