File: query_cache_middleware_spec.rb

package info (click to toggle)
ruby-mongo 2.21.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,764 kB
  • sloc: ruby: 108,806; makefile: 5; sh: 2
file content (55 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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