Sha256: 3a53733a8ce6ea2c5f51b447f3a6405c80a1c44dd363a153e5e712c20899df4f

Contents?: true

Size: 1.05 KB

Versions: 19

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require "spec_helper"

describe Mongo::QueryCache::Middleware do

  let :middleware do
    described_class.new(app)
  end

  context "when not touching query cache in the app" do

    let(:app) do
      lambda do |env|
        @enabled = Mongo::QueryCache.enabled?
        [200, env, "app"]
      end
    end

    it "returns success" do
      code, _ = middleware.call({})
      expect(code).to eq(200)
    end

    it "enables the query cache" do
      middleware.call({})
      expect(@enabled).to be true
    end
  end

  context "when querying in the app" do

    before do
      authorized_client['test'].insert_one(test: 1)
    end

    let(:app) do
      lambda do |env|
        authorized_client['test'].find
        [200, env, "app"]
      end
    end

    it "returns success" do
      code, _ = middleware.call({})
      expect(code).to eq(200)
    end

    it "cleans the query cache after it responds" do
      middleware.call({})
      expect(Mongo::QueryCache.send(:cache_table)).to be_empty
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/mongo/query_cache_middleware_spec.rb
mongo-2.17.4 spec/mongo/query_cache_middleware_spec.rb
mongo-2.18.3 spec/mongo/query_cache_middleware_spec.rb
mongo-2.18.2 spec/mongo/query_cache_middleware_spec.rb
mongo-2.17.3 spec/mongo/query_cache_middleware_spec.rb
mongo-2.18.1 spec/mongo/query_cache_middleware_spec.rb
mongo-2.18.0 spec/mongo/query_cache_middleware_spec.rb
mongo-2.17.2 spec/mongo/query_cache_middleware_spec.rb
mongo-2.16.3 spec/mongo/query_cache_middleware_spec.rb
mongo-2.18.0.beta1 spec/mongo/query_cache_middleware_spec.rb
mongo-2.16.2 spec/mongo/query_cache_middleware_spec.rb
mongo-2.17.1 spec/mongo/query_cache_middleware_spec.rb
mongo-2.16.1 spec/mongo/query_cache_middleware_spec.rb
mongo-2.17.0 spec/mongo/query_cache_middleware_spec.rb
mongo-2.16.0 spec/mongo/query_cache_middleware_spec.rb
mongo-2.15.1 spec/mongo/query_cache_middleware_spec.rb
mongo-2.16.0.alpha1 spec/mongo/query_cache_middleware_spec.rb
mongo-2.15.0 spec/mongo/query_cache_middleware_spec.rb
mongo-2.15.0.alpha spec/mongo/query_cache_middleware_spec.rb