Sha256: edef1efefe92c9d970f3d75f5f564c6ac80dd5395bb5791184050841e35a7775

Contents?: true

Size: 1002 Bytes

Versions: 16

Compression:

Stored size: 1002 Bytes

Contents

# frozen_string_literal: true

require "spec_helper"

describe Mongoid::QueryCache::Middleware do

  let :middleware do
    Mongoid::QueryCache::Middleware.new(app)
  end

  context "when not touching mongoid on the app" do

    let(:app) do
      ->(env) { @enabled = Mongoid::QueryCache.enabled?; [200, env, "app"] }
    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 on the app" do

    let(:app) do
      ->(env) {
        Band.all.to_a
        [200, env, "app"]
      }
    end

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

    context 'with driver query cache' do

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mongoid-8.1.7 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.1.6 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.0.8 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.1.5 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.1.4 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.0.7 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.1.3 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.1.2 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.0.6 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.1.1 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.0.5 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.1.0 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.0.4 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.0.3 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.0.2 spec/mongoid/query_cache_middleware_spec.rb
mongoid-8.0.1 spec/mongoid/query_cache_middleware_spec.rb