Sha256: eff078655ae20c410d48bd779497faf8146bcf32131cbdb828aa2d059e86bdc9

Contents?: true

Size: 1.4 KB

Versions: 6836

Compression:

Stored size: 1.4 KB

Contents

require 'redis'
require 'typhoeus/cache/redis'
require 'spec_helper'

describe Typhoeus::Cache::Redis do
  let(:redis) { instance_double(Redis) }
  let(:cache) { Typhoeus::Cache::Redis.new(redis) }

  let(:base_url) { "localhost:3001" }
  let(:request) { Typhoeus::Request.new(base_url, {:method => :get}) }
  let(:response) { Typhoeus::Response.new(:response_code => 0, :return_code => 0, :mock => true) }
  let(:serialized_response) { Marshal.dump(response) }

  describe "#set" do
    it "sends the serialized request to Redis" do
      expect(redis).to receive(:set).with(request.cache_key, serialized_response)
      expect(redis).to_not receive(:expire).with(request.cache_key, request.cache_ttl)

      cache.set(request, response)
    end
  end

  describe "#get" do
    it "returns nil when the key is not in Redis" do
      expect(redis).to receive(:get).with(request.cache_key).and_return(nil)

      expect(cache.get(request)).to be_nil
    end

    it "returns the cached response when the key is in Redis" do
      expect(redis).to receive(:get).with(request.cache_key).and_return(serialized_response)

      result = cache.get(request)
      expect(result).to_not be_nil
      expect(result.response_code).to eq(response.response_code)
      expect(result.return_code).to eq(response.return_code)
      expect(result.headers).to eq(response.headers)
      expect(result.body).to eq(response.body)
    end
  end
end

Version data entries

6,836 entries across 6,833 versions & 27 rubygems

Version Path
ory-client-0.0.1.alpha31 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-client-0.0.1.alpha30 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-client-0.0.1.alpha29 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-client-0.0.1.alpha28 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-client-0.0.1.alpha27 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-client-0.0.1.alpha24 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-client-0.0.1.alpha23 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-kratos-client-0.8.0.alpha2 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-client-0.0.1.alpha21 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-keto-client-0.7.0.alpha1 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-keto-client-0.7.0.alpha0 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-kratos-client-0.7.6.alpha7 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-kratos-client-0.7.6.alpha6 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-kratos-client-0.7.6.alpha5 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-kratos-client-0.7.6.alpha4 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-kratos-client-0.7.6.alpha3 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-kratos-client-0.7.6.alpha1 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
ory-kratos-client-0.7.5.alpha2 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
cloudsmith-api-0.57.1 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb
mfk_openapi_ruby_client-1.0.0 vendor/bundle/ruby/2.7.0/gems/typhoeus-1.4.0/spec/typhoeus/cache/redis_spec.rb