activesupport_cache_database 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0c184beea3e358d5a6b2a23d082b0dea1d17a0ed8ab5ca91aeda9984a439b99
4
- data.tar.gz: 055a6e394e11e576b8a64c7ab6bdd75f687648f76bb6148283e6a9ef788ade1f
3
+ metadata.gz: c3b2183683fc6cb4ec9bb735da8fed61f9e057b894bfef685416dfb019d924ee
4
+ data.tar.gz: b493bb3f1a7aa74a27e87030fbefb98a3bf95cf98955bfbcf817382039776442
5
5
  SHA512:
6
- metadata.gz: 48746c696baa9602f5eede7df9f6b345702c85f15c4423ee5f5423f798cc9b453ddbd1e4c5eeeb86271cde9b208f2dc44515beb4fca7c10f608cead14243468a
7
- data.tar.gz: 2428c1fc89ff9b5a98f6a379a5f2e4af86e3bf8d9e4ce8a766123bd9d2acf2c99899c4c47011f30449eb4f17be4214b2b646db54e45193bf623e315028c2a74f
6
+ metadata.gz: 1ce1549296de2188bbfa524c8745844bb150d0df44e0d1472a617d716279deafe758b13b7c577dba84c00697b4aeca8fe8048bc96936fd2e17021accdc03777a
7
+ data.tar.gz: ae967fdb27b3597c4c1bc7ed58e57c6f4a59795a63dfc1df44caaae3b60ac3b53698df40131e8c17a0520202187e43e606a4f1cdb0471aaed0c1a7e4a1af6aab
@@ -7,13 +7,16 @@ on:
7
7
  branches: [main]
8
8
 
9
9
  jobs:
10
- ruby:
10
+ test:
11
11
  runs-on: ubuntu-latest
12
12
  strategy:
13
13
  matrix:
14
- ruby-version: ["2.6", "2.7", "3.0"]
14
+ ruby-version: ["2.7", "3.0", "3.1"]
15
+ gemfiles: ["Gemfile", "Gemfile.rails6"]
16
+ env:
17
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
15
18
  steps:
16
- - uses: actions/checkout@v2
19
+ - uses: actions/checkout@v3
17
20
  - uses: ruby/setup-ruby@v1
18
21
  with:
19
22
  ruby-version: ${{ matrix.ruby-version }}
data/.rubocop.yml CHANGED
@@ -5,7 +5,7 @@ inherit_mode:
5
5
  merge:
6
6
  - Exclude
7
7
  AllCops:
8
- TargetRubyVersion: "2.6"
8
+ TargetRubyVersion: "2.7"
9
9
 
10
10
  Security/MarshalLoad:
11
11
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,82 +1,81 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activesupport_cache_database (0.2.1)
5
- activerecord (>= 5.0)
6
- activesupport (>= 5.0)
4
+ activesupport_cache_database (0.3.0)
5
+ activerecord (>= 6.0)
6
+ activesupport (>= 6.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (6.1.3.2)
12
- activesupport (= 6.1.3.2)
13
- activerecord (6.1.3.2)
14
- activemodel (= 6.1.3.2)
15
- activesupport (= 6.1.3.2)
16
- activesupport (6.1.3.2)
11
+ activemodel (7.0.3.1)
12
+ activesupport (= 7.0.3.1)
13
+ activerecord (7.0.3.1)
14
+ activemodel (= 7.0.3.1)
15
+ activesupport (= 7.0.3.1)
16
+ activesupport (7.0.3.1)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
18
  i18n (>= 1.6, < 2)
19
19
  minitest (>= 5.1)
20
20
  tzinfo (~> 2.0)
21
- zeitwerk (~> 2.3)
22
21
  ast (2.4.2)
23
- concurrent-ruby (1.1.8)
24
- diff-lcs (1.4.4)
25
- i18n (1.8.10)
22
+ concurrent-ruby (1.1.10)
23
+ diff-lcs (1.5.0)
24
+ i18n (1.11.0)
26
25
  concurrent-ruby (~> 1.0)
27
- minitest (5.14.4)
28
- mysql2 (0.5.3)
29
- parallel (1.20.1)
30
- parser (3.0.1.1)
26
+ json (2.6.2)
27
+ minitest (5.16.2)
28
+ mysql2 (0.5.4)
29
+ parallel (1.22.1)
30
+ parser (3.1.2.0)
31
31
  ast (~> 2.4.1)
32
- pg (1.2.3)
33
- rainbow (3.0.0)
34
- rake (13.0.3)
35
- regexp_parser (2.1.1)
32
+ pg (1.4.1)
33
+ rainbow (3.1.1)
34
+ rake (13.0.6)
35
+ regexp_parser (2.5.0)
36
36
  rexml (3.2.5)
37
- rspec (3.10.0)
38
- rspec-core (~> 3.10.0)
39
- rspec-expectations (~> 3.10.0)
40
- rspec-mocks (~> 3.10.0)
41
- rspec-core (3.10.1)
42
- rspec-support (~> 3.10.0)
43
- rspec-expectations (3.10.1)
37
+ rspec (3.11.0)
38
+ rspec-core (~> 3.11.0)
39
+ rspec-expectations (~> 3.11.0)
40
+ rspec-mocks (~> 3.11.0)
41
+ rspec-core (3.11.0)
42
+ rspec-support (~> 3.11.0)
43
+ rspec-expectations (3.11.0)
44
44
  diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.10.0)
46
- rspec-mocks (3.10.2)
45
+ rspec-support (~> 3.11.0)
46
+ rspec-mocks (3.11.1)
47
47
  diff-lcs (>= 1.2.0, < 2.0)
48
- rspec-support (~> 3.10.0)
49
- rspec-support (3.10.2)
50
- rubocop (1.16.0)
48
+ rspec-support (~> 3.11.0)
49
+ rspec-support (3.11.0)
50
+ rubocop (1.31.2)
51
+ json (~> 2.3)
51
52
  parallel (~> 1.10)
52
- parser (>= 3.0.0.0)
53
+ parser (>= 3.1.0.0)
53
54
  rainbow (>= 2.2.2, < 4.0)
54
55
  regexp_parser (>= 1.8, < 3.0)
55
- rexml
56
- rubocop-ast (>= 1.7.0, < 2.0)
56
+ rexml (>= 3.2.5, < 4.0)
57
+ rubocop-ast (>= 1.18.0, < 2.0)
57
58
  ruby-progressbar (~> 1.7)
58
59
  unicode-display_width (>= 1.4.0, < 3.0)
59
- rubocop-ast (1.7.0)
60
- parser (>= 3.0.1.1)
60
+ rubocop-ast (1.19.1)
61
+ parser (>= 3.1.1.0)
61
62
  rubocop-bsm (0.6.0)
62
63
  rubocop (~> 1.0)
63
64
  rubocop-performance
64
65
  rubocop-rake
65
66
  rubocop-rspec
66
- rubocop-performance (1.11.3)
67
+ rubocop-performance (1.14.2)
67
68
  rubocop (>= 1.7.0, < 2.0)
68
69
  rubocop-ast (>= 0.4.0)
69
- rubocop-rake (0.5.1)
70
- rubocop
71
- rubocop-rspec (2.3.0)
70
+ rubocop-rake (0.6.0)
72
71
  rubocop (~> 1.0)
73
- rubocop-ast (>= 1.1.0)
72
+ rubocop-rspec (2.12.1)
73
+ rubocop (~> 1.31)
74
74
  ruby-progressbar (1.11.0)
75
- sqlite3 (1.4.2)
75
+ sqlite3 (1.4.4)
76
76
  tzinfo (2.0.4)
77
77
  concurrent-ruby (~> 1.0)
78
- unicode-display_width (2.0.0)
79
- zeitwerk (2.4.2)
78
+ unicode-display_width (2.2.0)
80
79
 
81
80
  PLATFORMS
82
81
  ruby
@@ -92,4 +91,4 @@ DEPENDENCIES
92
91
  sqlite3
93
92
 
94
93
  BUNDLED WITH
95
- 2.1.4
94
+ 2.3.16
data/Gemfile.rails6 ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'activesupport', '~> 6.1'
5
+ gem 'activerecord', '~> 6.1'
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ activesupport_cache_database (0.3.0)
5
+ activerecord (>= 5.0)
6
+ activesupport (>= 5.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (6.1.6.1)
12
+ activesupport (= 6.1.6.1)
13
+ activerecord (6.1.6.1)
14
+ activemodel (= 6.1.6.1)
15
+ activesupport (= 6.1.6.1)
16
+ activesupport (6.1.6.1)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ zeitwerk (~> 2.3)
22
+ ast (2.4.2)
23
+ concurrent-ruby (1.1.10)
24
+ diff-lcs (1.5.0)
25
+ i18n (1.11.0)
26
+ concurrent-ruby (~> 1.0)
27
+ json (2.6.2)
28
+ minitest (5.16.2)
29
+ mysql2 (0.5.4)
30
+ parallel (1.22.1)
31
+ parser (3.1.2.0)
32
+ ast (~> 2.4.1)
33
+ pg (1.4.1)
34
+ rainbow (3.1.1)
35
+ rake (13.0.6)
36
+ regexp_parser (2.5.0)
37
+ rexml (3.2.5)
38
+ rspec (3.11.0)
39
+ rspec-core (~> 3.11.0)
40
+ rspec-expectations (~> 3.11.0)
41
+ rspec-mocks (~> 3.11.0)
42
+ rspec-core (3.11.0)
43
+ rspec-support (~> 3.11.0)
44
+ rspec-expectations (3.11.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.11.0)
47
+ rspec-mocks (3.11.1)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.11.0)
50
+ rspec-support (3.11.0)
51
+ rubocop (1.31.2)
52
+ json (~> 2.3)
53
+ parallel (~> 1.10)
54
+ parser (>= 3.1.0.0)
55
+ rainbow (>= 2.2.2, < 4.0)
56
+ regexp_parser (>= 1.8, < 3.0)
57
+ rexml (>= 3.2.5, < 4.0)
58
+ rubocop-ast (>= 1.18.0, < 2.0)
59
+ ruby-progressbar (~> 1.7)
60
+ unicode-display_width (>= 1.4.0, < 3.0)
61
+ rubocop-ast (1.19.1)
62
+ parser (>= 3.1.1.0)
63
+ rubocop-bsm (0.6.0)
64
+ rubocop (~> 1.0)
65
+ rubocop-performance
66
+ rubocop-rake
67
+ rubocop-rspec
68
+ rubocop-performance (1.14.2)
69
+ rubocop (>= 1.7.0, < 2.0)
70
+ rubocop-ast (>= 0.4.0)
71
+ rubocop-rake (0.6.0)
72
+ rubocop (~> 1.0)
73
+ rubocop-rspec (2.12.1)
74
+ rubocop (~> 1.31)
75
+ ruby-progressbar (1.11.0)
76
+ sqlite3 (1.4.4)
77
+ tzinfo (2.0.4)
78
+ concurrent-ruby (~> 1.0)
79
+ unicode-display_width (2.2.0)
80
+ zeitwerk (2.6.0)
81
+
82
+ PLATFORMS
83
+ x86_64-linux
84
+
85
+ DEPENDENCIES
86
+ activerecord (~> 6.1)
87
+ activesupport (~> 6.1)
88
+ activesupport_cache_database!
89
+ bundler
90
+ mysql2
91
+ pg
92
+ rake
93
+ rspec
94
+ rubocop-bsm
95
+ sqlite3
96
+
97
+ BUNDLED WITH
98
+ 2.3.16
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'activesupport_cache_database'
3
- s.version = '0.2.1'
3
+ s.version = '0.3.0'
4
4
  s.authors = ['Black Square Media Ltd']
5
5
  s.email = ['info@blacksquaremedia.com']
6
6
  s.summary = %(ActiveSupport::Cache::Store implementation backed by ActiveRecord.)
@@ -9,12 +9,11 @@ Gem::Specification.new do |s|
9
9
  s.license = 'Apache-2.0'
10
10
 
11
11
  s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^spec/}) }
12
- s.test_files = `git ls-files -z -- spec/*`.split("\x0")
13
12
  s.require_paths = ['lib']
14
- s.required_ruby_version = '>= 2.6'
13
+ s.required_ruby_version = '>= 2.7'
15
14
 
16
- s.add_dependency 'activerecord', '>= 5.0'
17
- s.add_dependency 'activesupport', '>= 5.0'
15
+ s.add_dependency 'activerecord', '>= 6.0'
16
+ s.add_dependency 'activesupport', '>= 6.0'
18
17
 
19
18
  s.add_development_dependency 'bundler'
20
19
  s.add_development_dependency 'mysql2'
@@ -23,4 +22,5 @@ Gem::Specification.new do |s|
23
22
  s.add_development_dependency 'rspec'
24
23
  s.add_development_dependency 'rubocop-bsm'
25
24
  s.add_development_dependency 'sqlite3'
25
+ s.metadata['rubygems_mfa_required'] = 'true'
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport_cache_database
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Black Square Media Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-02 00:00:00.000000000 Z
11
+ date: 2022-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '6.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '5.0'
40
+ version: '6.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -149,6 +149,8 @@ files:
149
149
  - ".rubocop.yml"
150
150
  - Gemfile
151
151
  - Gemfile.lock
152
+ - Gemfile.rails6
153
+ - Gemfile.rails6.lock
152
154
  - LICENSE
153
155
  - README.md
154
156
  - Rakefile
@@ -157,12 +159,11 @@ files:
157
159
  - lib/active_support/cache/database_store/migration.rb
158
160
  - lib/active_support/cache/database_store/model.rb
159
161
  - lib/activesupport_cache_database.rb
160
- - spec/active_support/cache/database_store_spec.rb
161
- - spec/spec_helper.rb
162
162
  homepage: https://github.com/bsm/activesupport-cache-database
163
163
  licenses:
164
164
  - Apache-2.0
165
- metadata: {}
165
+ metadata:
166
+ rubygems_mfa_required: 'true'
166
167
  post_install_message:
167
168
  rdoc_options: []
168
169
  require_paths:
@@ -171,17 +172,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
172
  requirements:
172
173
  - - ">="
173
174
  - !ruby/object:Gem::Version
174
- version: '2.6'
175
+ version: '2.7'
175
176
  required_rubygems_version: !ruby/object:Gem::Requirement
176
177
  requirements:
177
178
  - - ">="
178
179
  - !ruby/object:Gem::Version
179
180
  version: '0'
180
181
  requirements: []
181
- rubygems_version: 3.1.4
182
+ rubygems_version: 3.3.7
182
183
  signing_key:
183
184
  specification_version: 4
184
185
  summary: ActiveSupport::Cache::Store implementation backed by ActiveRecord.
185
- test_files:
186
- - spec/active_support/cache/database_store_spec.rb
187
- - spec/spec_helper.rb
186
+ test_files: []
@@ -1,329 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ActiveSupport::Cache::DatabaseStore do
4
- subject do
5
- described_class.new expires_in: 60
6
- end
7
-
8
- it 'reads and write strings' do
9
- expect(subject.write('foo', 'bar')).to be_truthy
10
- expect(subject.read('foo')).to eq('bar')
11
- end
12
-
13
- it 'reads and write hash' do
14
- expect(subject.write('foo', a: 'b')).to be_truthy
15
- expect(subject.read('foo')).to eq(a: 'b')
16
- end
17
-
18
- it 'reads and write integer' do
19
- expect(subject.write('foo', 1)).to be_truthy
20
- expect(subject.read('foo')).to eq(1)
21
- end
22
-
23
- it 'reads and write nil' do
24
- expect(subject.write('foo', nil)).to be_truthy
25
- expect(subject.read('foo')).to eq(nil)
26
- end
27
-
28
- it 'reads and write false' do
29
- expect(subject.write('foo', false)).to be_truthy
30
- expect(subject.read('foo')).to eq(false)
31
- end
32
-
33
- it 'overwrites' do
34
- expect(subject.write('foo', 'bar')).to be_truthy
35
- expect(subject.write('foo', 'baz')).to be_truthy
36
- expect(subject.read('foo')).to eq('baz')
37
- end
38
-
39
- it 'supports exist?' do
40
- subject.write('foo', 'bar')
41
- expect(subject).to exist('foo')
42
- expect(subject).not_to exist('bar')
43
- end
44
-
45
- it 'supports nil exist?' do
46
- subject.write('foo', nil)
47
- expect(subject).to exist('foo')
48
- end
49
-
50
- it 'supports delete' do
51
- subject.write('foo', 'bar')
52
- expect(subject).to exist('foo')
53
- expect(subject.delete('foo')).to be_truthy
54
- expect(subject).not_to exist('foo')
55
- end
56
-
57
- it 'supports expires_in' do
58
- time = Time.local(2008, 4, 24)
59
- allow(Time).to receive(:now).and_return(time)
60
-
61
- subject.write('foo', 'bar')
62
- expect(subject.read('foo')).to eq('bar')
63
-
64
- allow(Time).to receive(:now).and_return(time + 30)
65
- expect(subject.read('foo')).to eq('bar')
66
-
67
- allow(Time).to receive(:now).and_return(time + 61)
68
- expect(subject.read('foo')).to be_nil
69
- end
70
-
71
- it 'supports long keys' do
72
- key = 'x' * 255
73
- expect(subject.write(key, 'bar')).to be_truthy
74
- expect(subject.read(key)).to eq('bar')
75
- expect(subject.fetch(key)).to eq('bar')
76
- expect(subject.read(key[0..-2])).to be_nil
77
- expect(subject.read_multi(key)).to eq(key => 'bar')
78
- expect(subject.delete(key)).to be_truthy
79
-
80
- expect { subject.write("#{key}x", 'bar') }.to raise_error(ArgumentError, /exceeds the length limit/)
81
- expect { subject.read("#{key}x") }.to raise_error(ArgumentError, /exceeds the length limit/)
82
- end
83
-
84
- describe '#cleanup' do
85
- it 'deletes expired' do
86
- time = Time.now
87
- subject.write('foo', 'bar', expires_in: 10)
88
- subject.write('fud', 'biz', expires_in: 20)
89
-
90
- allow(Time).to receive(:now).and_return(time + 9)
91
- expect(subject.cleanup).to eq(0)
92
-
93
- allow(Time).to receive(:now).and_return(time + 19)
94
- expect(subject.cleanup).to eq(1)
95
- expect(subject.read('foo')).to be_nil
96
- expect(subject.read('fud')).to eq('biz')
97
- end
98
-
99
- it 'supports namespace' do
100
- time = Time.now
101
- subject.write('foo', 'bar', expires_in: 10, namespace: 'x')
102
- subject.write('foo', 'biz', expires_in: 10, namespace: 'y')
103
-
104
- allow(Time).to receive(:now).and_return(time + 11)
105
- expect(subject.count).to eq(0)
106
- expect(subject.count(all: true)).to eq(2)
107
-
108
- expect(subject.cleanup(namespace: 'x')).to eq(1)
109
- expect(subject.count).to eq(0)
110
- expect(subject.count(all: true)).to eq(1)
111
- end
112
- end
113
-
114
- describe '#clear' do
115
- it 'removes all entries' do
116
- subject.write('foo', 'bar')
117
- subject.write('fud', 'biz')
118
- expect(subject.clear).to be_truthy
119
- expect(subject.read('foo')).to be_nil
120
- expect(subject.read('fud')).to be_nil
121
- end
122
-
123
- it 'supports namespace' do
124
- subject.write('foo', 'bar', namespace: 'x')
125
- subject.write('foo', 'biz', namespace: 'y')
126
- expect(subject.count).to eq(2)
127
-
128
- expect(subject.clear(namespace: 'x')).to be_truthy
129
- expect(subject.count).to eq(1)
130
- end
131
- end
132
-
133
- describe '#fetch' do
134
- it 'supports cache hit' do
135
- subject.write('foo', 'bar')
136
- expect(subject).not_to receive(:write)
137
-
138
- expect(subject.fetch('foo') { 'baz' }).to eq('bar')
139
- end
140
-
141
- it 'supports cache miss' do
142
- expect(subject).to receive(:write).with('foo', 'baz', instance_of(Hash))
143
- expect(subject.fetch('foo') { 'baz' }).to eq('baz')
144
- end
145
-
146
- it 'passes key to block on cache miss' do
147
- cache_miss = false
148
- expect(subject.fetch('foo') {|key| cache_miss = true; key.length }).to eq(3)
149
- expect(cache_miss).to be_truthy
150
-
151
- cache_miss = false
152
- expect(subject.fetch('foo') {|key| cache_miss = true; key.length }).to eq(3)
153
- expect(cache_miss).to be_falsey
154
- end
155
-
156
- it 'supports forced cache miss' do
157
- subject.write('foo', 'bar')
158
- expect(subject).not_to receive(:read)
159
-
160
- expect(subject.fetch('foo', force: true) { 'baz' }).to eq('baz')
161
- end
162
-
163
- it 'supports nil values' do
164
- subject.write('foo', nil)
165
- expect(subject).not_to receive(:write)
166
-
167
- expect(subject.fetch('foo') { 'baz' }).to be_nil
168
- end
169
-
170
- it 'supports skip_nil option' do
171
- expect(subject).not_to receive(:write)
172
- expect(subject.fetch('foo', skip_nil: true) { nil }).to be_nil
173
- expect(subject).not_to exist('foo')
174
- end
175
-
176
- it 'supports forced cache miss with block' do
177
- subject.write('foo', 'bar')
178
- expect(subject.fetch('foo', force: true) { 'baz' }).to eq('baz')
179
- end
180
-
181
- it 'supports forced cache miss without block' do
182
- subject.write('foo', 'bar')
183
- expect { subject.fetch('foo', force: true) }.to raise_error(ArgumentError)
184
- expect(subject.read('foo')).to eq('bar')
185
- end
186
- end
187
-
188
- describe '#read_multi' do
189
- it 'supports read_multi' do
190
- subject.write('foo', 'bar')
191
- subject.write('fu', 'baz')
192
- subject.write('fud', 'biz')
193
- expect(subject.read_multi('foo', 'fu')).to eq('foo' => 'bar', 'fu' => 'baz')
194
- end
195
-
196
- it 'supports expires' do
197
- time = Time.now
198
- subject.write('foo', 'bar', expires_in: 10)
199
- subject.write('fu', 'baz')
200
- subject.write('fud', 'biz')
201
-
202
- allow(Time).to receive(:now).and_return(time + 11)
203
- expect(subject.read_multi('foo', 'fu')).to eq('fu' => 'baz')
204
- end
205
- end
206
-
207
- describe '#fetch_multi' do
208
- it 'supports fetch_multi' do
209
- subject.write('foo', 'bar')
210
- subject.write('fud', 'biz')
211
- values = subject.fetch_multi('foo', 'fu', 'fud') {|v| v * 2 }
212
-
213
- expect(values).to eq('foo' => 'bar', 'fu' => 'fufu', 'fud' => 'biz')
214
- expect(subject.read('fu')).to eq('fufu')
215
- end
216
-
217
- it 'supports without expires_in' do
218
- subject.write('foo', 'bar')
219
- subject.write('fud', 'biz')
220
- values = subject.fetch_multi('foo', 'fu', 'fud', expires_in: nil) {|v| v * 2 }
221
-
222
- expect(values).to eq('foo' => 'bar', 'fu' => 'fufu', 'fud' => 'biz')
223
- expect(subject.read('fu')).to eq('fufu')
224
- end
225
-
226
- it 'supports with objects' do
227
- cache_struct = Struct.new(:cache_key, :title)
228
- foo = cache_struct.new('foo', 'FOO!')
229
- bar = cache_struct.new('bar')
230
-
231
- subject.write('bar', 'BAM!')
232
- values = subject.fetch_multi(foo, bar, &:title)
233
- expect(values).to eq(foo => 'FOO!', bar => 'BAM!')
234
- end
235
-
236
- it 'supports ordered names' do
237
- subject.write('bam', 'BAM')
238
- values = subject.fetch_multi('foo', 'bar', 'bam', &:upcase)
239
- expect(values.keys).to eq(%w[foo bar bam])
240
- end
241
-
242
- it 'raises without block' do
243
- expect { subject.fetch_multi('foo') }.to raise_error(ArgumentError)
244
- end
245
- end
246
-
247
- describe 'cache key' do
248
- it 'supports cache keys' do
249
- obj = Object.new
250
- def obj.cache_key
251
- :foo
252
- end
253
- subject.write(obj, 'bar')
254
- expect(subject.read('foo')).to eq('bar')
255
- end
256
-
257
- it 'supports to_param keys' do
258
- obj = Class.new do
259
- def to_param
260
- 'foo'
261
- end
262
- end.new
263
- subject.write(obj, 'bar')
264
- expect(subject.read('foo')).to eq('bar')
265
- end
266
-
267
- it 'supports unversioned keys' do
268
- obj = Object.new
269
- def obj.cache_key
270
- :foo
271
- end
272
-
273
- def obj.cache_key_with_version
274
- 'foo-v1'
275
- end
276
- subject.write(obj, 'bar')
277
- expect(subject.read('foo')).to eq('bar')
278
- end
279
-
280
- it 'supports array keys' do
281
- subject.write([:fu, 'foo'], 'bar')
282
- expect(subject.read('fu/foo')).to eq('bar')
283
- end
284
-
285
- it 'supports hash keys' do
286
- subject.write({ foo: 1, fu: 2 }, 'bar')
287
- expect(subject.read('foo=1/fu=2')).to eq('bar')
288
- end
289
-
290
- it 'is case sensitive' do
291
- subject.write('foo', 'bar')
292
- expect(subject.read('FOO')).to be_nil
293
- end
294
- end
295
-
296
- describe 'with version' do
297
- it 'supports fetch/read' do
298
- subject.fetch('foo', version: 1) { 'bar' }
299
- expect(subject.read('foo', version: 1)).to eq('bar')
300
- expect(subject.read('foo', version: 2)).to be_nil
301
- end
302
-
303
- it 'supports write/read' do
304
- subject.write('foo', 'bar', version: 1)
305
- expect(subject.read('foo', version: 1)).to eq('bar')
306
- expect(subject.read('foo', version: 2)).to be_nil
307
- end
308
-
309
- it 'supports exists' do
310
- subject.write('foo', 'bar', version: 1)
311
- expect(subject).to exist('foo', version: 1)
312
- expect(subject).not_to exist('foo', version: 2)
313
- end
314
-
315
- it 'cache/versions keys' do
316
- m1v1 = ModelWithKeyAndVersion.new('model/1', 1)
317
- m1v2 = ModelWithKeyAndVersion.new('model/1', 2)
318
-
319
- subject.write(m1v1, 'bar')
320
- expect(subject.read(m1v1)).to eq('bar')
321
- expect(subject.read(m1v2)).to be_nil
322
- end
323
-
324
- it 'normalises' do
325
- subject.write('foo', 'bar', version: 1)
326
- expect(subject.read('foo', version: '1')).to eq('bar')
327
- end
328
- end
329
- end
data/spec/spec_helper.rb DELETED
@@ -1,30 +0,0 @@
1
- ENV['RACK_ENV'] ||= 'test'
2
-
3
- require 'rspec'
4
- require 'fileutils'
5
- require 'activesupport_cache_database'
6
-
7
- Time.zone_default = Time.find_zone!('UTC')
8
-
9
- database_url = ENV.fetch('DATABASE_URL') do
10
- path = File.expand_path('./test.sqlite3', __dir__)
11
- FileUtils.rm_f(path)
12
- "sqlite3://#{path}"
13
- end
14
- ActiveRecord::Base.configurations = { 'test' => { 'url' => database_url, 'pool' => 20 } }
15
-
16
- ActiveRecord::Base.establish_connection :test
17
- ActiveRecord::Base.connection.instance_eval do
18
- drop_table 'activesupport_cache_entries', if_exists: true
19
- end
20
- ActiveRecord::Migration.suppress_messages do
21
- ActiveSupport::Cache::DatabaseStore::Migration.migrate(:up)
22
- end
23
-
24
- RSpec.configure do |c|
25
- c.after do
26
- ActiveSupport::Cache::DatabaseStore::Model.truncate!
27
- end
28
- end
29
-
30
- ModelWithKeyAndVersion = Struct.new(:cache_key, :cache_version)