Sha256: 139fe9845e22cc4cb402208f6fb3778a76fc434a2b5901882504cc1009382ecc

Contents?: true

Size: 1.73 KB

Versions: 19

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'

describe Typhoeus::Request::Cacheable do
  let(:cache) { MemoryCache.new }
  let(:options) { {} }
  let(:request) { Typhoeus::Request.new("http://localhost:3001", options) }
  let(:response) { Typhoeus::Response.new }

  before { Typhoeus::Config.cache = cache }
  after { Typhoeus::Config.cache = false }

  describe "#response=" do
    context "when cache activated" do
      context "when request new" do
        it "caches response" do
          request.response = response
          expect(cache.memory[request]).to be
        end

        it "doesn't set cached on response" do
          request.response = response
          expect(request.response.cached?).to be_falsey
        end
      end

      context "when request in memory" do
        before { cache.memory[request] = response }

        it "finishes request" do
          expect(request).to receive(:finish).with(response)
          request.run
        end

        it "sets cached to true for response" do
          request.run
          expect(request.response.cached?).to be_truthy
        end
      end
    end
  end

  describe "#run" do
    context "when cache activated" do
      context "when request new" do
        it "fetches response" do
          expect(request.response).to_not be(response)
        end
      end

      context "when request in memory" do
        before { cache.memory[request] = response }

        it "finishes request" do
          expect(request).to receive(:finish).with(response)
          request.run
        end
      end
    end
  end

  describe "#cache_ttl" do
    context "when option[:cache_ttl]" do
      let(:options) { {:cache_ttl => 1} }

      it "returns" do
        expect(request.cache_ttl).to be(1)
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 5 rubygems

Version Path
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/typhoeus-1.3.0/spec/typhoeus/request/cacheable_spec.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/typhoeus-1.3.0/spec/typhoeus/request/cacheable_spec.rb
color_me_shop-1.0.0 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.3.0/spec/typhoeus/request/cacheable_spec.rb
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/typhoeus-1.3.0/spec/typhoeus/request/cacheable_spec.rb
typhoeus-1.3.0 spec/typhoeus/request/cacheable_spec.rb
typhoeus-1.1.2 spec/typhoeus/request/cacheable_spec.rb
typhoeus-1.1.1 spec/typhoeus/request/cacheable_spec.rb
typhoeus-1.1.0 spec/typhoeus/request/cacheable_spec.rb
typhoeus-1.0.2 spec/typhoeus/request/cacheable_spec.rb
typhoeus-1.0.1 spec/typhoeus/request/cacheable_spec.rb
typhoeus-1.0.0 spec/typhoeus/request/cacheable_spec.rb
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/typhoeus-0.8.0/spec/typhoeus/request/cacheable_spec.rb
typhoeus-0.8.0 spec/typhoeus/request/cacheable_spec.rb
typhoeus-0.7.3 spec/typhoeus/request/cacheable_spec.rb
typhoeus-0.7.2 spec/typhoeus/request/cacheable_spec.rb
typhoeus-0.7.1 spec/typhoeus/request/cacheable_spec.rb
typhoeus-0.7.0 spec/typhoeus/request/cacheable_spec.rb
typhoeus-0.7.0.pre1 spec/typhoeus/request/cacheable_spec.rb
typhoeus-0.6.9 spec/typhoeus/request/cacheable_spec.rb