Sha256: ac66cfa7864207ebef1d27f6b729f5dcec288ebd859bf348552404a35671235f

Contents?: true

Size: 868 Bytes

Versions: 11

Compression:

Stored size: 868 Bytes

Contents

require 'spec_helper'

describe 'Gris::CacheKey' do
  it 'raises an error when cache_key is called on a blank object' do
    @foo = CacheKeyHelper.new
    expect { @foo.cache_key }.to raise_error(NotImplementedError)
  end

  it 'returns a value for cache_key' do
    @foo = CacheKeyHelper.new(id: SecureRandom.random_number(500))
    expect(@foo.cache_key).to eq("cache_key_helper/#{@foo.id}")
  end

  it 'returns a value for cache_key_for' do
    id = SecureRandom.random_number(500)
    expect(CacheKeyHelper.cache_key_for(id)).to eq("cache_key_helper/#{id}")
  end

  it 'uses the cache for cached_find' do
    id = SecureRandom.random_number(500)
    foo = CacheKeyHelper.cached_find(id)
    expect(foo.id).to eq(id)
    allow(Gris.cache).to receive(:fetch).and_return('cached-result')
    expect(CacheKeyHelper.cached_find(id)).to eq('cached-result')
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gris-0.3.8 spec/cache_key_spec.rb
gris-0.3.7 spec/cache_key_spec.rb
gris-0.3.6 spec/cache_key_spec.rb
gris-0.3.4 spec/cache_key_spec.rb
gris-0.3.3 spec/cache_key_spec.rb
gris-0.3.2 spec/cache_key_spec.rb
gris-0.3.1 spec/cache_key_spec.rb
gris-0.3.0 spec/cache_key_spec.rb
gris-0.2.4 spec/cache_key_spec.rb
gris-0.2.3 spec/cache_key_spec.rb
gris-0.2.2 spec/cache_key_spec.rb