Sha256: 993fd460fbb6f78cebd53ffe7731a1e1eecb5136015e534fae8d8bde5f7db0ca

Contents?: true

Size: 1.4 KB

Versions: 56

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

56 entries across 56 versions & 1 rubygems

Version Path
volt-0.9.7.pre8 spec/utils/generic_pool_spec.rb
volt-0.9.7.pre7 spec/utils/generic_pool_spec.rb
volt-0.9.7.pre6 spec/utils/generic_pool_spec.rb
volt-0.9.7.pre5 spec/utils/generic_pool_spec.rb
volt-0.9.7.pre3 spec/utils/generic_pool_spec.rb
volt-0.9.7.pre2 spec/utils/generic_pool_spec.rb
volt-0.9.6 spec/utils/generic_pool_spec.rb
volt-0.9.6.pre3 spec/utils/generic_pool_spec.rb
volt-0.9.6.pre2 spec/utils/generic_pool_spec.rb
volt-0.9.6.pre1 spec/utils/generic_pool_spec.rb
volt-0.9.5 spec/utils/generic_pool_spec.rb
volt-0.9.5.pre12 spec/utils/generic_pool_spec.rb
volt-0.9.5.pre11 spec/utils/generic_pool_spec.rb
volt-0.9.5.pre9 spec/utils/generic_pool_spec.rb
volt-0.9.5.pre8 spec/utils/generic_pool_spec.rb
volt-0.9.5.pre7 spec/utils/generic_pool_spec.rb
volt-0.9.5.pre6 spec/utils/generic_pool_spec.rb
volt-0.9.5.pre5 spec/utils/generic_pool_spec.rb
volt-0.9.5.pre4 spec/utils/generic_pool_spec.rb
volt-0.9.5.pre3 spec/utils/generic_pool_spec.rb