Sha256: 528ae3ab185e08cfc77261db823813a6c2c205c74b9bcb4cb39861460ebf9ad2

Contents?: true

Size: 954 Bytes

Versions: 13

Compression:

Stored size: 954 Bytes

Contents

# frozen_string_literal: true
# encoding: utf-8

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 "enableds 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

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

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
mongoid-7.1.11 spec/mongoid/query_cache_middleware_spec.rb
mongoid-7.1.10 spec/mongoid/query_cache_middleware_spec.rb
mongoid-7.1.9 spec/mongoid/query_cache_middleware_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/spec/mongoid/query_cache_middleware_spec.rb
mongoid-7.1.8 spec/mongoid/query_cache_middleware_spec.rb
mongoid-7.1.7 spec/mongoid/query_cache_middleware_spec.rb
mongoid-7.1.6 spec/mongoid/query_cache_middleware_spec.rb
mongoid-7.1.5 spec/mongoid/query_cache_middleware_spec.rb
mongoid-7.1.4 spec/mongoid/query_cache_middleware_spec.rb
mongoid-7.1.2 spec/mongoid/query_cache_middleware_spec.rb
mongoid-7.1.1 spec/mongoid/query_cache_middleware_spec.rb
mongoid-7.1.0 spec/mongoid/query_cache_middleware_spec.rb
mongoid-7.1.0.rc0 spec/mongoid/query_cache_middleware_spec.rb