Sha256: e342be665aabfef8d175292f5310977600f1646f329a45ecd6b3d31a42bf9c26

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

require 'helper'
require 'flipper/adapters/memory'
require 'flipper/adapters/redis_cache'
require 'flipper/spec/shared_adapter_specs'

RSpec.describe Flipper::Adapters::RedisCache do
  let(:client) do
    options = {}

    options[:url] = ENV['BOXEN_REDIS_URL'] if ENV['BOXEN_REDIS_URL']

    Redis.new(options)
  end

  let(:memory_adapter) { Flipper::Adapters::Memory.new }
  let(:cache)   { Redis.new(url: ENV.fetch('BOXEN_REDIS_URL', 'redis://localhost:6379')) }
  let(:adapter) { described_class.new(memory_adapter, cache) }
  let(:flipper) { Flipper.new(adapter) }

  subject { adapter }

  before do
    client.flushdb
  end

  it_should_behave_like 'a flipper adapter'

  describe '#remove' do
    it 'expires feature' do
      feature = flipper[:stats]
      adapter.get(feature)
      adapter.remove(feature)
      expect(cache.get(described_class.key_for(feature))).to be(nil)
    end
  end

  describe '#get_multi' do
    it 'warms uncached features' do
      stats = flipper[:stats]
      search = flipper[:search]
      other = flipper[:other]
      stats.enable
      search.enable

      adapter.get(stats)
      expect(cache.get(described_class.key_for(search))).to be(nil)
      expect(cache.get(described_class.key_for(other))).to be(nil)

      adapter.get_multi([stats, search, other])

      search_cache_value, other_cache_value = [search, other].map do |f|
        Marshal.load(cache.get(described_class.key_for(f)))
      end
      expect(search_cache_value[:boolean]).to eq('true')
      expect(other_cache_value[:boolean]).to be(nil)
    end
  end

  describe '#name' do
    it 'is redis_cache' do
      expect(subject.name).to be(:redis_cache)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flipper-redis-0.11.0.beta3 spec/flipper/adapters/redis_cache_spec.rb
flipper-redis-0.11.0.beta1 spec/flipper/adapters/redis_cache_spec.rb