Sha256: 1b2048773499f1b00099dc0a2b6954ec85c9c0afa521ef4a2cbacc78b386348c

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

require 'spec_helper.rb'

module MyApp
  class Application
  end
end

unless defined? ApiClient
  class ApiClient
    def self.column_names
      ["enabled"]
    end
  end
end

describe Stitches::ApiClientAccessWrapper do
  let(:api_client) {
    double(ApiClient, id: 42)
  }
  before do
    Stitches.configuration.reset_to_defaults!
  end
  describe '#fetch_by_key' do
    context "cache is disabled" do
      before do
        expect(ApiClient).to receive(:find_by).and_return(api_client).twice
      end

      it "fetchs object from db twice" do
        expect(described_class.fetch_for_key("123").id).to eq(42)
        expect(described_class.fetch_for_key("123").id).to eq(42)
      end
    end

    context "cache is configured" do
      before do
        Stitches.configure do |config|
          config.max_cache_ttl  = 5
          config.max_cache_size = 10
        end

        expect(ApiClient).to receive(:find_by).and_return(api_client).once
      end

      it "fetchs object from cache" do
        expect(described_class.fetch_for_key("123").id).to eq(42)
        # This should hit the cache
        expect(described_class.fetch_for_key("123").id).to eq(42)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
stitches-4.0.2 spec/api_client_access_wrapper_spec.rb
stitches-4.1.0RC2 spec/api_client_access_wrapper_spec.rb
stitches-4.0.1 spec/api_client_access_wrapper_spec.rb
stitches-4.0.0 spec/api_client_access_wrapper_spec.rb
stitches-4.0.0.RC1 spec/api_client_access_wrapper_spec.rb