record-cache 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/lib/record_cache.rb +2 -1
- data/lib/record_cache/base.rb +63 -22
- data/lib/record_cache/datastore/active_record.rb +5 -3
- data/lib/record_cache/datastore/active_record_30.rb +95 -38
- data/lib/record_cache/datastore/active_record_31.rb +157 -54
- data/lib/record_cache/datastore/active_record_32.rb +444 -0
- data/lib/record_cache/dispatcher.rb +47 -47
- data/lib/record_cache/multi_read.rb +14 -1
- data/lib/record_cache/query.rb +36 -25
- data/lib/record_cache/statistics.rb +5 -5
- data/lib/record_cache/strategy/base.rb +49 -19
- data/lib/record_cache/strategy/full_table_cache.rb +81 -0
- data/lib/record_cache/strategy/index_cache.rb +38 -36
- data/lib/record_cache/strategy/unique_index_cache.rb +130 -0
- data/lib/record_cache/strategy/util.rb +12 -12
- data/lib/record_cache/test/resettable_version_store.rb +2 -9
- data/lib/record_cache/version.rb +1 -1
- data/lib/record_cache/version_store.rb +23 -16
- data/spec/db/schema.rb +12 -0
- data/spec/db/seeds.rb +10 -0
- data/spec/lib/active_record/visitor_spec.rb +22 -0
- data/spec/lib/base_spec.rb +21 -0
- data/spec/lib/dispatcher_spec.rb +24 -46
- data/spec/lib/multi_read_spec.rb +6 -6
- data/spec/lib/query_spec.rb +43 -43
- data/spec/lib/statistics_spec.rb +28 -28
- data/spec/lib/strategy/base_spec.rb +98 -87
- data/spec/lib/strategy/full_table_cache_spec.rb +68 -0
- data/spec/lib/strategy/index_cache_spec.rb +112 -69
- data/spec/lib/strategy/query_cache_spec.rb +83 -0
- data/spec/lib/strategy/unique_index_on_id_cache_spec.rb +317 -0
- data/spec/lib/strategy/unique_index_on_string_cache_spec.rb +168 -0
- data/spec/lib/strategy/util_spec.rb +67 -49
- data/spec/lib/version_store_spec.rb +22 -41
- data/spec/models/address.rb +9 -0
- data/spec/models/apple.rb +1 -1
- data/spec/models/banana.rb +21 -2
- data/spec/models/language.rb +5 -0
- data/spec/models/person.rb +1 -1
- data/spec/models/store.rb +2 -1
- data/spec/spec_helper.rb +7 -4
- data/spec/support/after_commit.rb +2 -0
- data/spec/support/matchers/hit_cache_matcher.rb +10 -6
- data/spec/support/matchers/log.rb +45 -0
- data/spec/support/matchers/miss_cache_matcher.rb +10 -6
- data/spec/support/matchers/use_cache_matcher.rb +10 -6
- metadata +156 -161
- data/lib/record_cache/strategy/id_cache.rb +0 -93
- data/lib/record_cache/strategy/request_cache.rb +0 -49
- data/spec/lib/strategy/id_cache_spec.rb +0 -168
- data/spec/lib/strategy/request_cache_spec.rb +0 -85
@@ -1,61 +1,72 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe RecordCache::Strategy::Util do
|
5
5
|
|
6
6
|
it "should serialize a record (currently Active Record only)" do
|
7
|
-
subject.serialize(Banana.find(1)).
|
7
|
+
expect(subject.serialize(Banana.find(1))).to eq({:a=>{"name"=>"Blue Banana 1", "id"=>1, "store_id"=>2, "person_id"=>4}, :c=>"Banana"})
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should deserialize a record (currently Active Record only)" do
|
11
|
-
subject.deserialize({:a=>{"name"=>"Blue Banana 1", "id"=>1, "store_id"=>2, "person_id"=>4}, :c=>"Banana"}).
|
11
|
+
expect(subject.deserialize({:a=>{"name"=>"Blue Banana 1", "id"=>1, "store_id"=>2, "person_id"=>4}, :c=>"Banana"})).to eq(Banana.find(1))
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should call the after_finalize and after_find callbacks when deserializing a record" do
|
15
|
+
record = subject.deserialize({:a=>{"name"=>"Blue Banana 1", "id"=>1, "store_id"=>2, "person_id"=>4}, :c=>"Banana"})
|
16
|
+
expect(record.logs.sort).to eq(["after_find", "after_initialize"])
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not be a new record nor have changed attributes after deserializing a record" do
|
20
|
+
record = subject.deserialize({:a=>{"id"=>1}, :c=>"Banana"})
|
21
|
+
expect(record.new_record?).to be_falsey
|
22
|
+
expect(record.changed_attributes).to be_empty
|
12
23
|
end
|
13
24
|
|
14
25
|
context "filter" do
|
15
26
|
it "should apply filter" do
|
16
27
|
apples = Apple.where(:id => [1,2]).all
|
17
28
|
subject.filter!(apples, :name => "Adams Apple 1")
|
18
|
-
apples.
|
29
|
+
expect(apples).to eq([Apple.find_by_name("Adams Apple 1")])
|
19
30
|
end
|
20
|
-
|
31
|
+
|
21
32
|
it "should return empty array when filter does not match any record" do
|
22
33
|
apples = Apple.where(:id => [1,2]).all
|
23
34
|
subject.filter!(apples, :name => "Adams Apple Pie")
|
24
|
-
apples.
|
35
|
+
expect(apples).to be_empty
|
25
36
|
end
|
26
37
|
|
27
38
|
it "should filter on text" do
|
28
39
|
apples = Apple.where(:id => [1,2]).all
|
29
40
|
subject.filter!(apples, :name => "Adams Apple 1")
|
30
|
-
apples.
|
41
|
+
expect(apples).to eq([Apple.find_by_name("Adams Apple 1")])
|
31
42
|
end
|
32
43
|
|
33
44
|
it "should filter on integers" do
|
34
45
|
apples = Apple.where(:id => [1,2,8,9]).all
|
35
46
|
subject.filter!(apples, :store_id => 2)
|
36
|
-
apples.map(&:id).sort.
|
47
|
+
expect(apples.map(&:id).sort).to eq([8,9])
|
37
48
|
end
|
38
49
|
|
39
50
|
it "should filter on dates" do
|
40
51
|
people = Person.where(:id => [1,2,3]).all
|
41
52
|
subject.filter!(people, :birthday => Date.civil(1953,11,11))
|
42
|
-
people.size.
|
43
|
-
people.first.name.
|
53
|
+
expect(people.size).to eq(1)
|
54
|
+
expect(people.first.name).to eq("Blue")
|
44
55
|
end
|
45
56
|
|
46
57
|
it "should filter on floats" do
|
47
58
|
people = Person.where(:id => [1,2,3]).all
|
48
59
|
subject.filter!(people, :height => 1.75)
|
49
|
-
people.size.
|
50
|
-
people.map(&:name).sort.
|
60
|
+
expect(people.size).to eq(2)
|
61
|
+
expect(people.map(&:name).sort).to eq(["Blue", "Cris"])
|
51
62
|
end
|
52
63
|
|
53
64
|
it "should filter on arrays" do
|
54
65
|
apples = Apple.where(:id => [1,2,8,9])
|
55
66
|
subject.filter!(apples, :store_id => [2, 4])
|
56
|
-
apples.map(&:id).sort.
|
67
|
+
expect(apples.map(&:id).sort).to eq([8,9])
|
57
68
|
end
|
58
|
-
|
69
|
+
|
59
70
|
it "should filter on multiple fields" do
|
60
71
|
# make sure two apples exist with the same name
|
61
72
|
apple = Apple.find(8)
|
@@ -64,9 +75,16 @@ describe RecordCache::Strategy::Util do
|
|
64
75
|
|
65
76
|
apples = Apple.where(:id => [1,2,3,8,9,10]).all
|
66
77
|
subject.filter!(apples, :store_id => [2, 4], :name => apple.name)
|
67
|
-
apples.size.
|
68
|
-
apples.map(&:name).
|
69
|
-
apples.map(&:id).sort.
|
78
|
+
expect(apples.size).to eq(2)
|
79
|
+
expect(apples.map(&:name)).to eq([apple.name, apple.name])
|
80
|
+
expect(apples.map(&:id).sort).to eq([8,9])
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should filter with more than 2 and conditions" do
|
84
|
+
# this construction leads to a arel object with 3 Equality Nodes within a single And Node
|
85
|
+
apples = Apple.where(:store_id => [1,2]).where(:store_id => 1, :person_id => nil).all
|
86
|
+
expect(apples.size).to eq(2)
|
87
|
+
expect(apples.map(&:id).sort).to eq([1,2])
|
70
88
|
end
|
71
89
|
|
72
90
|
end
|
@@ -75,138 +93,138 @@ describe RecordCache::Strategy::Util do
|
|
75
93
|
it "should accept a Symbol as a sort order" do
|
76
94
|
people = Person.where(:id => [1,2,3]).all
|
77
95
|
subject.sort!(people, :name)
|
78
|
-
people.map(&:name).
|
96
|
+
expect(people.map(&:name)).to eq(["Adam", "Blue", "Cris"])
|
79
97
|
end
|
80
98
|
|
81
99
|
it "should accept a single Array as a sort order" do
|
82
100
|
people = Person.where(:id => [1,2,3]).all
|
83
101
|
subject.sort!(people, [:name, false])
|
84
|
-
people.map(&:name).
|
102
|
+
expect(people.map(&:name)).to eq(["Cris", "Blue", "Adam"])
|
85
103
|
end
|
86
104
|
|
87
105
|
it "should accept multiple Symbols as a sort order" do
|
88
106
|
people = Person.where(:id => [2,3,4,5]).all
|
89
107
|
subject.sort!(people, :height, :id)
|
90
|
-
people.map(&:height).
|
91
|
-
people.map(&:id).
|
108
|
+
expect(people.map(&:height)).to eq([1.69, 1.75, 1.75, 1.91])
|
109
|
+
expect(people.map(&:id)).to eq([4, 2, 3, 5])
|
92
110
|
end
|
93
111
|
|
94
112
|
it "should accept a mix of Symbols and Arrays as a sort order" do
|
95
113
|
people = Person.where(:id => [2,3,4,5]).all
|
96
114
|
subject.sort!(people, [:height, false], :id)
|
97
|
-
people.map(&:height).
|
98
|
-
people.map(&:id).
|
115
|
+
expect(people.map(&:height)).to eq([1.91, 1.75, 1.75, 1.69])
|
116
|
+
expect(people.map(&:id)).to eq([5, 2, 3, 4])
|
99
117
|
end
|
100
118
|
|
101
119
|
it "should accept multiple Arrays as a sort order" do
|
102
120
|
people = Person.where(:id => [2,3,4,5]).all
|
103
121
|
subject.sort!(people, [:height, false], [:id, false])
|
104
|
-
people.map(&:height).
|
105
|
-
people.map(&:id).
|
122
|
+
expect(people.map(&:height)).to eq([1.91, 1.75, 1.75, 1.69])
|
123
|
+
expect(people.map(&:id)).to eq([5, 3, 2, 4])
|
106
124
|
end
|
107
125
|
|
108
126
|
it "should accept an Array with Arrays as a sort order (default used by record cache)" do
|
109
127
|
people = Person.where(:id => [2,3,4,5]).all
|
110
128
|
subject.sort!(people, [[:height, false], [:id, false]])
|
111
|
-
people.map(&:height).
|
112
|
-
people.map(&:id).
|
129
|
+
expect(people.map(&:height)).to eq([1.91, 1.75, 1.75, 1.69])
|
130
|
+
expect(people.map(&:id)).to eq([5, 3, 2, 4])
|
113
131
|
end
|
114
132
|
|
115
133
|
it "should order nil first for ASC" do
|
116
134
|
apples = Apple.where(:store_id => 1).all
|
117
135
|
subject.sort!(apples, [:person_id, true])
|
118
|
-
apples.map(&:person_id).
|
136
|
+
expect(apples.map(&:person_id)).to eq([nil, nil, 4, 4, 5])
|
119
137
|
end
|
120
138
|
|
121
139
|
it "should order nil last for DESC" do
|
122
140
|
apples = Apple.where(:store_id => 1).all
|
123
141
|
subject.sort!(apples, [:person_id, false])
|
124
|
-
apples.map(&:person_id).
|
142
|
+
expect(apples.map(&:person_id)).to eq([5, 4, 4, nil, nil])
|
125
143
|
end
|
126
144
|
|
127
145
|
it "should order ascending on text" do
|
128
146
|
people = Person.where(:id => [1,2,3,4]).all
|
129
147
|
subject.sort!(people, [:name, true])
|
130
|
-
people.map(&:name).
|
148
|
+
expect(people.map(&:name)).to eq(["Adam", "Blue", "Cris", "Fry"])
|
131
149
|
end
|
132
150
|
|
133
151
|
it "should order descending on text" do
|
134
152
|
people = Person.where(:id => [1,2,3,4]).all
|
135
153
|
subject.sort!(people, [:name, false])
|
136
|
-
people.map(&:name).
|
154
|
+
expect(people.map(&:name)).to eq(["Fry", "Cris", "Blue", "Adam"])
|
137
155
|
end
|
138
156
|
|
139
157
|
it "should order ascending on integers" do
|
140
158
|
people = Person.where(:id => [4,2,1,3]).all
|
141
159
|
subject.sort!(people, [:id, true])
|
142
|
-
people.map(&:id).
|
160
|
+
expect(people.map(&:id)).to eq([1,2,3,4])
|
143
161
|
end
|
144
162
|
|
145
163
|
it "should order descending on integers" do
|
146
164
|
people = Person.where(:id => [4,2,1,3]).all
|
147
165
|
subject.sort!(people, [:id, false])
|
148
|
-
people.map(&:id).
|
166
|
+
expect(people.map(&:id)).to eq([4,3,2,1])
|
149
167
|
end
|
150
168
|
|
151
169
|
it "should order ascending on dates" do
|
152
170
|
people = Person.where(:id => [1,2,3,4]).all
|
153
171
|
subject.sort!(people, [:birthday, true])
|
154
|
-
people.map(&:birthday).
|
172
|
+
expect(people.map(&:birthday)).to eq([Date.civil(1953,11,11), Date.civil(1975,03,20), Date.civil(1975,03,20), Date.civil(1985,01,20)])
|
155
173
|
end
|
156
174
|
|
157
175
|
it "should order descending on dates" do
|
158
176
|
people = Person.where(:id => [1,2,3,4]).all
|
159
177
|
subject.sort!(people, [:birthday, false])
|
160
|
-
people.map(&:birthday).
|
178
|
+
expect(people.map(&:birthday)).to eq([Date.civil(1985,01,20), Date.civil(1975,03,20), Date.civil(1975,03,20), Date.civil(1953,11,11)])
|
161
179
|
end
|
162
180
|
|
163
181
|
it "should order ascending on float" do
|
164
182
|
people = Person.where(:id => [1,2,3,4]).all
|
165
183
|
subject.sort!(people, [:height, true])
|
166
|
-
people.map(&:height).
|
184
|
+
expect(people.map(&:height)).to eq([1.69, 1.75, 1.75, 1.83])
|
167
185
|
end
|
168
186
|
|
169
187
|
it "should order descending on float" do
|
170
188
|
people = Person.where(:id => [1,2,3,4]).all
|
171
189
|
subject.sort!(people, [:height, false])
|
172
|
-
people.map(&:height).
|
190
|
+
expect(people.map(&:height)).to eq([1.83, 1.75, 1.75, 1.69])
|
173
191
|
end
|
174
192
|
|
175
193
|
it "should order on multiple fields (ASC + ASC)" do
|
176
194
|
people = Person.where(:id => [2,3,4,5]).all
|
177
195
|
subject.sort!(people, [:height, true], [:id, true])
|
178
|
-
people.map(&:height).
|
179
|
-
people.map(&:id).
|
196
|
+
expect(people.map(&:height)).to eq([1.69, 1.75, 1.75, 1.91])
|
197
|
+
expect(people.map(&:id)).to eq([4, 2, 3, 5])
|
180
198
|
end
|
181
199
|
|
182
200
|
it "should order on multiple fields (ASC + DESC)" do
|
183
201
|
people = Person.where(:id => [2,3,4,5]).all
|
184
202
|
subject.sort!(people, [:height, true], [:id, false])
|
185
|
-
people.map(&:height).
|
186
|
-
people.map(&:id).
|
203
|
+
expect(people.map(&:height)).to eq([1.69, 1.75, 1.75, 1.91])
|
204
|
+
expect(people.map(&:id)).to eq([4, 3, 2, 5])
|
187
205
|
end
|
188
206
|
|
189
207
|
it "should order on multiple fields (DESC + ASC)" do
|
190
208
|
people = Person.where(:id => [2,3,4,5]).all
|
191
209
|
subject.sort!(people, [:height, false], [:id, true])
|
192
|
-
people.map(&:height).
|
193
|
-
people.map(&:id).
|
210
|
+
expect(people.map(&:height)).to eq([1.91, 1.75, 1.75, 1.69])
|
211
|
+
expect(people.map(&:id)).to eq([5, 2, 3, 4])
|
194
212
|
end
|
195
213
|
|
196
214
|
it "should order on multiple fields (DESC + DESC)" do
|
197
215
|
people = Person.where(:id => [2,3,4,5]).all
|
198
216
|
subject.sort!(people, [:height, false], [:id, false])
|
199
|
-
people.map(&:height).
|
200
|
-
people.map(&:id).
|
217
|
+
expect(people.map(&:height)).to eq([1.91, 1.75, 1.75, 1.69])
|
218
|
+
expect(people.map(&:id)).to eq([5, 3, 2, 4])
|
201
219
|
end
|
202
|
-
|
220
|
+
|
203
221
|
it "should use mysql style collation" do
|
204
222
|
ids = []
|
205
223
|
ids << Person.create!(:name => "ċedriĉ 3").id # latin other special
|
206
224
|
ids << Person.create!(:name => "a cedric").id # first in ascending order
|
207
225
|
ids << Person.create!(:name => "čedriĉ 4").id # latin another special
|
208
226
|
ids << Person.create!(:name => "ćedriĉ Last").id # latin special lowercase
|
209
|
-
ids << Person.create!(:name => "sedric 1").id # second to last latin in ascending order
|
227
|
+
ids << Person.create!(:name => "sedric 1").id # second to last latin in ascending order
|
210
228
|
ids << Person.create!(:name => "Cedric 2").id # ascii uppercase
|
211
229
|
ids << Person.create!(:name => "čedriĉ คฉ Almost last cedric").id # latin special, with non-latin
|
212
230
|
ids << Person.create!(:name => "Sedric 2").id # last latin in ascending order
|
@@ -218,10 +236,10 @@ describe RecordCache::Strategy::Util do
|
|
218
236
|
names_asc = ["1 cedric", "a cedric", "cedric 1", "Cedric 2", "ċedriĉ 3", "čedriĉ 4", "ćedriĉ Last", "čedriĉ คฉ Almost last cedric", "čedriĉ ꜩ Last", "sedric 1", "Sedric 2", "คฉ Really last"]
|
219
237
|
people = Person.where(:id => ids).all
|
220
238
|
subject.sort!(people, [:name, true])
|
221
|
-
people.map(&:name).
|
239
|
+
expect(people.map(&:name)).to eq(names_asc)
|
222
240
|
|
223
241
|
subject.sort!(people, [:name, false])
|
224
|
-
people.map(&:name).
|
242
|
+
expect(people.map(&:name)).to eq(names_asc.reverse)
|
225
243
|
end
|
226
244
|
end
|
227
245
|
|
@@ -9,95 +9,76 @@ describe RecordCache::VersionStore do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should only accept ActiveSupport cache stores" do
|
12
|
-
|
12
|
+
expect{ RecordCache::VersionStore.new(Object.new) }.to raise_error("Store Object must respond to write")
|
13
13
|
end
|
14
14
|
|
15
15
|
context "current" do
|
16
16
|
it "should retrieve the current version" do
|
17
|
-
@version_store.current("key1").
|
17
|
+
expect(@version_store.current("key1")).to eq(1000)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should retrieve nil for unknown keys" do
|
21
|
-
@version_store.current("unknown_key").
|
21
|
+
expect(@version_store.current("unknown_key")).to be_nil
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context "current_multi" do
|
26
26
|
it "should retrieve all versions" do
|
27
|
-
@version_store.current_multi({:id1 => "key1", :id2 => "key2"}).
|
27
|
+
expect(@version_store.current_multi({:id1 => "key1", :id2 => "key2"})).to eq({:id1 => 1000, :id2 => 2000})
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should return nil for unknown keys" do
|
31
|
-
@version_store.current_multi({:id1 => "key1", :key3 => "unknown_key"}).
|
31
|
+
expect(@version_store.current_multi({:id1 => "key1", :key3 => "unknown_key"})).to eq({:id1 => 1000, :key3 => nil})
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should use read_multi on the underlying store" do
|
35
|
-
|
36
|
-
@version_store.current_multi({:id1 => "key1", :id2 => "key2"}).
|
35
|
+
allow(@version_store.store).to receive(:read_multi).with(/key[12]/, /key[12]/) { {"key1" => 5, "key2" => 6} }
|
36
|
+
expect(@version_store.current_multi({:id1 => "key1", :id2 => "key2"})).to eq({:id1 => 5, :id2 => 6})
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
context "renew" do
|
41
41
|
it "should renew the version" do
|
42
|
-
@version_store.current("key1").
|
42
|
+
expect(@version_store.current("key1")).to eq(1000)
|
43
43
|
@version_store.renew("key1")
|
44
|
-
@version_store.current("key1").
|
44
|
+
expect(@version_store.current("key1")).to_not eq(1000)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should renew the version for unknown keys" do
|
48
|
-
@version_store.current("unknown_key").
|
48
|
+
expect(@version_store.current("unknown_key")).to be_nil
|
49
49
|
@version_store.renew("unknown_key")
|
50
|
-
@version_store.current("unknown_key").
|
50
|
+
expect(@version_store.current("unknown_key")).to_not be_nil
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should write to the debug log" do
|
54
|
-
|
55
|
-
mock(RecordCache::Base.logger).debug(/Version Store: renew key1: nil => \d+/)
|
56
|
-
@version_store.renew("key1")
|
57
|
-
stub(RecordCache::Base.logger).debug?{ false } # to prevent the ResettableVersionStore from logging in +after(:each)+
|
54
|
+
expect{ @version_store.renew("key1") }.to log(:debug, /Version Store: renew key1: nil => \d+/)
|
58
55
|
end
|
59
56
|
end
|
60
57
|
|
58
|
+
# deprecated
|
61
59
|
context "increment" do
|
62
|
-
it "should increment the version" do
|
63
|
-
@version_store.current("key1").should == 1000
|
64
|
-
@version_store.increment("key1")
|
65
|
-
@version_store.current("key1").should == 1001
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should renew the version on increment for unknown keys" do
|
69
|
-
# do not use unknown_key as the version store retains the value after this spec
|
70
|
-
@version_store.current("unknown_key").should == nil
|
71
|
-
@version_store.renew("unknown_key")
|
72
|
-
@version_store.current("unknown_key").should_not == nil
|
73
|
-
end
|
74
60
|
|
75
61
|
it "should write to the debug log" do
|
76
|
-
|
77
|
-
mock(RecordCache::Base.logger).debug("Version Store: incremented key1: 1000 => 1001")
|
78
|
-
@version_store.increment("key1")
|
79
|
-
stub(RecordCache::Base.logger).debug?{ false } # to prevent the ResettableVersionStore from logging in +after(:each)+
|
62
|
+
expect{ @version_store.increment("key1") }.to log(:debug, /increment is deprecated, use renew instead/)
|
80
63
|
end
|
64
|
+
|
81
65
|
end
|
82
66
|
|
83
67
|
context "delete" do
|
84
68
|
it "should delete the version" do
|
85
|
-
@version_store.current("key1").
|
86
|
-
@version_store.delete("key1").
|
87
|
-
@version_store.current("key1").
|
69
|
+
expect(@version_store.current("key1")).to eq(1000)
|
70
|
+
expect(@version_store.delete("key1")).to be_truthy
|
71
|
+
expect(@version_store.current("key1")).to be_nil
|
88
72
|
end
|
89
73
|
|
90
74
|
it "should not raise an error when deleting the version for unknown keys" do
|
91
|
-
@version_store.current("unknown_key").
|
92
|
-
@version_store.delete("unknown_key").
|
93
|
-
@version_store.current("unknown_key").
|
75
|
+
expect(@version_store.current("unknown_key")).to be_nil
|
76
|
+
expect(@version_store.delete("unknown_key")).to be_falsey
|
77
|
+
expect(@version_store.current("unknown_key")).to be_nil
|
94
78
|
end
|
95
79
|
|
96
80
|
it "should write to the debug log" do
|
97
|
-
|
98
|
-
mock(RecordCache::Base.logger).debug("Version Store: deleted key1")
|
99
|
-
@version_store.delete("key1")
|
100
|
-
stub(RecordCache::Base.logger).debug?{ false } # to prevent the ResettableVersionStore from logging in +after(:each)+
|
81
|
+
expect{ @version_store.delete("key1") }.to log(:debug, %(Version Store: deleted key1))
|
101
82
|
end
|
102
83
|
end
|
103
84
|
|
data/spec/models/apple.rb
CHANGED
data/spec/models/banana.rb
CHANGED
@@ -1,8 +1,27 @@
|
|
1
1
|
class Banana < ActiveRecord::Base
|
2
|
-
|
2
|
+
|
3
3
|
cache_records :store => :local, :index => [:person_id]
|
4
4
|
|
5
5
|
belongs_to :store
|
6
6
|
belongs_to :person
|
7
|
-
|
7
|
+
|
8
|
+
after_initialize :do_after_initialize
|
9
|
+
after_find :do_after_find
|
10
|
+
|
11
|
+
def logs
|
12
|
+
@logs ||= []
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def do_after_initialize
|
18
|
+
self.logs << "after_initialize"
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def do_after_find
|
23
|
+
self.logs << "after_find"
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
8
27
|
end
|