Sha256: 8a2db459edea19ac15d5f4a77bc4070628f27cf396167d01523c1fd0631acee6

Contents?: true

Size: 1.4 KB

Versions: 15

Compression:

Stored size: 1.4 KB

Contents

require 'volt/utils/generic_pool'

class PoolTest < Volt::GenericPool
  def create(collection, query, other = nil)
    Object.new
  end
end

describe Volt::GenericPool do

  before do
    @pool_test = PoolTest.new
  end

  it 'should insert nested for fast lookup at a path' do
    item1 = @pool_test.lookup('_items', 'one')
    expect(@pool_test.instance_variable_get('@pool')).to eq('_items' => { 'one' => item1 })
  end

  it 'should retrieve the same item both times' do
    item1 = @pool_test.lookup('_items', {})
    item2 = @pool_test.lookup('_items', {})
    expect(item1.object_id).to eq(item2.object_id)
  end

  it 'should recreate after being removed' do
    item1 = @pool_test.lookup('_items', {})
    item2 = @pool_test.lookup('_items', {})
    expect(item1.object_id).to eq(item2.object_id)

    @pool_test.remove('_items', {})
    item3 = @pool_test.lookup('_items', {})
    expect(item3.object_id).to_not eq(item2.object_id)
  end

  it 'should remove all of the way down' do
    @pool_test.instance_variable_set('@pool', name: { ok: true }, yep: true)

    @pool_test.remove(:name, :ok)

    expect(@pool_test.instance_variable_get('@pool')).to eq(yep: true)
  end

  it 'should lookup all items at a path' do
    item1 = @pool_test.lookup('_items', '_some', name: 'bob')
    item2 = @pool_test.lookup('_items', '_some', name: 'jim')

    expect(@pool_test.lookup_all('_items', '_some')).to eq([item1, item2])
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
volt-0.8.27.beta2 spec/utils/generic_pool_spec.rb
volt-0.8.27.beta1 spec/utils/generic_pool_spec.rb
volt-0.8.26.beta1 spec/utils/generic_pool_spec.rb
volt-0.8.26 spec/utils/generic_pool_spec.rb
volt-0.8.24 spec/utils/generic_pool_spec.rb
volt-0.8.23 spec/utils/generic_pool_spec.rb
volt-0.8.22 spec/utils/generic_pool_spec.rb
volt-0.8.22.beta2 spec/utils/generic_pool_spec.rb
volt-0.8.22.beta1 spec/utils/generic_pool_spec.rb
volt-0.8.21 spec/utils/generic_pool_spec.rb
volt-0.8.20 spec/utils/generic_pool_spec.rb
volt-0.8.19 spec/utils/generic_pool_spec.rb
volt-0.8.18 spec/utils/generic_pool_spec.rb
volt-0.8.17 spec/utils/generic_pool_spec.rb
volt-0.8.16 spec/utils/generic_pool_spec.rb