File: static_cache_cache_spec.rb

package info (click to toggle)
ruby-sequel 5.41.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,548 kB
  • sloc: ruby: 104,241; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download | duplicates (3)
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
require_relative "spec_helper"

describe "static_cache_cache plugin" do
  before do
    @db = Sequel.mock
    @db.fetch = [{:id=>1, :name=>'A'}, {:id=>2, :name=>'B'}]
    @c = Class.new(Sequel::Model(@db[:t]))
    def @c.name; 'Foo' end
    @c.columns :id, :name
    @file = "spec/files/static_cache_cache-spec-#{$$}.cache"
  end
  after do
    File.delete(@file) if File.file?(@file)
  end

  it "should allow dumping and loading static cache rows from a cache file" do
    @c.plugin :static_cache_cache, @file
    @db.sqls
    @c.plugin :static_cache
    @db.sqls.must_equal ['SELECT * FROM t']
    @c.all.must_equal [@c.load(:id=>1, :name=>'A'), @c.load(:id=>2, :name=>'B')]

    @c.dump_static_cache_cache

    @db.fetch = []
    c = Class.new(Sequel::Model(@db[:t]))
    def c.name; 'Foo' end
    c.columns :id, :name
    @c.plugin :static_cache_cache, @file
    @db.sqls
    @c.plugin :static_cache
    @db.sqls.must_be_empty
    @c.all.must_equal [@c.load(:id=>1, :name=>'A'), @c.load(:id=>2, :name=>'B')]
  end
end