Sha256: 46499696a6088a995db72fdd6710874154dcff15bcebe4deec2f226f3b7e408b

Contents?: true

Size: 925 Bytes

Versions: 32

Compression:

Stored size: 925 Bytes

Contents

require 'spec_helper'

describe Cuboid::Support::Cache::Preference do
    it_behaves_like 'cache'

    it 'prunes itself by removing entries returned by the given block' do
        subject.max_size = 3

        subject.prefer { :k2 }

        k = [ :k, :k2, :k3, :k4 ]
        subject[k[0]] = '1'
        subject[k[1]] = '2'
        subject[k[2]] = '3'
        subject[k[3]] = '4'
        expect(subject.size).to eq(3)

        expect(k.map { |key| subject[key] }.count( nil )).to eq(1)

        subject.clear
    end

    it 'does not remove entries which are not preferred even if the max size has been exceeded' do
        subject.prefer { :k2 }

        k = [ :k, :k2, :k3, :k4 ]

        subject.max_size = 1
        subject[k[0]]  = '1'
        subject[k[1]] = '3'
        subject[k[2]] = '4'
        expect(subject.size).to eq(2)

        expect(k[0...3].map { |key| subject[key] }.count( nil )).to eq(1)
    end

end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
cuboid-0.2.11 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.10 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.9 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.8 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.7 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.6 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.5 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.4.2 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.4.1 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.4 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.3 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.2 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2.1 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.2 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.1.9.1 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.1.9 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.1.8 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.1.7 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.1.6.1 spec/cuboid/support/cache/preference_spec.rb
cuboid-0.1.6 spec/cuboid/support/cache/preference_spec.rb