Sha256: c4163211046f995f8687a3d516dd4b179e6a20a5efc7eef7e919f71e1c8ea657

Contents?: true

Size: 982 Bytes

Versions: 1

Compression:

Stored size: 982 Bytes

Contents

require 'spec_helper'

RSpec.describe OptimizelyServerSide::Cache do

  describe 'singleton' do

    it 'should be a singleton instance' do
      expect(described_class.instance).to equal(described_class.instance)
    end
  end


  describe '#cache_store_instance' do

    it 'should be a instance of Activesupport memory store' do
      expect(described_class.instance.cache_store_instance).to be_kind_of(ActiveSupport::Cache::MemoryStore)
    end

  end

  describe '.fetch' do

    before do
      stub_request(:get, "https://cdn.optimizely.com/json/5960232316.json")
      .to_return(body: '{"experiments": [{"status": "running"}]}',status: 200)
    end

    it 'should return the config from API and cache it' do
      expect(
        described_class.fetch('key') do
          JSON.parse(OptimizelyServerSide::DatafileFetcher.datafile, symbolize_names: true)
        end
      ).to eq(
        {
          experiments: [{status: "running"}]
        }
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
optimizely_server_side-0.0.3 spec/optimizely_server_side/cache_spec.rb