Sha256: 64be478cf12456629ba3e9a3e964e683b52f5b942ebb72c2ba2dbf18a4a6acff

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true
# rubocop:todo all

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

9 entries across 9 versions & 2 rubygems

Version Path
mongo-2.21.0 spec/mongo/query_cache_middleware_spec.rb
mongo-2.20.1 spec/mongo/query_cache_middleware_spec.rb
mogno-2.20.0 spec/mongo/query_cache_middleware_spec.rb
mogno-1.0.0 spec/mongo/query_cache_middleware_spec.rb
mongo-2.20.0 spec/mongo/query_cache_middleware_spec.rb
mongo-2.19.3 spec/mongo/query_cache_middleware_spec.rb
mongo-2.19.2 spec/mongo/query_cache_middleware_spec.rb
mongo-2.19.1 spec/mongo/query_cache_middleware_spec.rb
mongo-2.19.0 spec/mongo/query_cache_middleware_spec.rb