record-cache 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/record_cache/base.rb +4 -4
- data/lib/record_cache/datastore/active_record_30.rb +1 -1
- data/lib/record_cache/datastore/active_record_31.rb +1 -1
- data/lib/record_cache/datastore/active_record_32.rb +2 -2
- data/lib/record_cache/datastore/active_record_40.rb +445 -0
- data/lib/record_cache/datastore/active_record_41.rb +446 -0
- data/lib/record_cache/strategy/full_table_cache.rb +1 -1
- data/lib/record_cache/strategy/util.rb +20 -3
- data/lib/record_cache/version.rb +1 -1
- data/spec/db/create-record-cache-db_and_user.sql +5 -0
- data/spec/db/database.yml +7 -0
- data/spec/db/schema.rb +9 -15
- data/spec/initializers/backward_compatibility.rb +32 -0
- data/spec/lib/active_record/visitor_spec.rb +1 -1
- data/spec/lib/base_spec.rb +2 -2
- data/spec/lib/dispatcher_spec.rb +1 -1
- data/spec/lib/multi_read_spec.rb +1 -1
- data/spec/lib/query_spec.rb +1 -1
- data/spec/lib/statistics_spec.rb +1 -1
- data/spec/lib/strategy/base_spec.rb +39 -39
- data/spec/lib/strategy/full_table_cache_spec.rb +18 -18
- data/spec/lib/strategy/index_cache_spec.rb +58 -52
- data/spec/lib/strategy/query_cache_spec.rb +1 -1
- data/spec/lib/strategy/unique_index_on_id_cache_spec.rb +57 -45
- data/spec/lib/strategy/unique_index_on_string_cache_spec.rb +47 -45
- data/spec/lib/strategy/util_spec.rb +49 -43
- data/spec/lib/version_store_spec.rb +1 -1
- data/spec/models/apple.rb +1 -2
- data/spec/spec_helper.rb +16 -7
- data/spec/support/matchers/hit_cache_matcher.rb +1 -1
- data/spec/support/matchers/miss_cache_matcher.rb +1 -1
- data/spec/support/matchers/use_cache_matcher.rb +1 -1
- metadata +63 -17
- data/spec/support/after_commit.rb +0 -73
@@ -19,7 +19,13 @@ module RecordCache
|
|
19
19
|
record = serialized[CLASS_KEY].constantize.allocate
|
20
20
|
attributes = serialized[ATTRIBUTES_KEY]
|
21
21
|
record.class.serialized_attributes.keys.each do |attribute|
|
22
|
-
|
22
|
+
if attributes[attribute].respond_to?(:unserialize)
|
23
|
+
if attributes[attribute].method(:unserialize).arity > 0
|
24
|
+
attributes[attribute] = attributes[attribute].unserialize(attributes[attribute].value)
|
25
|
+
else
|
26
|
+
attributes[attribute] = attributes[attribute].unserialize
|
27
|
+
end
|
28
|
+
end
|
23
29
|
end
|
24
30
|
record.init_with('attributes' => attributes)
|
25
31
|
record
|
@@ -27,15 +33,26 @@ module RecordCache
|
|
27
33
|
|
28
34
|
# Filter the cached records in memory
|
29
35
|
# only simple x = y or x IN (a,b,c) can be handled
|
36
|
+
# string comparison is case insensitive
|
30
37
|
# Example:
|
31
38
|
# RecordCache::Strategy::Util.filter!(Apple.all, :price => [0.49, 0.59, 0.69], :name => "Green Apple")
|
32
39
|
def filter!(records, wheres)
|
33
40
|
wheres.each_pair do |attr, value|
|
34
41
|
attr = attr.to_sym
|
35
42
|
if value.is_a?(Array)
|
36
|
-
|
43
|
+
where_values = Set.new(value.first.respond_to?(:downcase) ? value.map(&:downcase) : value)
|
44
|
+
records.to_a.select! do |record|
|
45
|
+
attribute_value = record.send(attr)
|
46
|
+
attribute_value = attribute_value.downcase if attribute_value.respond_to?(:downcase)
|
47
|
+
where_values.include?(attribute_value)
|
48
|
+
end
|
37
49
|
else
|
38
|
-
|
50
|
+
where_value = value.respond_to?(:downcase) ? value.downcase : value
|
51
|
+
records.to_a.select! do |record|
|
52
|
+
attribute_value = record.send(attr)
|
53
|
+
attribute_value = attribute_value.downcase if attribute_value.respond_to?(:downcase)
|
54
|
+
attribute_value == where_value
|
55
|
+
end
|
39
56
|
end
|
40
57
|
end
|
41
58
|
end
|
data/lib/record_cache/version.rb
CHANGED
data/spec/db/database.yml
CHANGED
data/spec/db/schema.rb
CHANGED
@@ -1,52 +1,46 @@
|
|
1
|
-
ActiveRecord::Schema.define :
|
1
|
+
ActiveRecord::Schema.define version: 0 do
|
2
2
|
|
3
|
-
create_table :people, :
|
4
|
-
t.integer :id
|
3
|
+
create_table :people, force: true do |t|
|
5
4
|
t.string :name
|
6
5
|
t.date :birthday
|
7
6
|
t.float :height
|
8
7
|
end
|
9
8
|
|
10
|
-
create_table :stores, :
|
11
|
-
t.integer :id
|
9
|
+
create_table :stores, force: true do |t|
|
12
10
|
t.string :name
|
13
11
|
t.integer :owner_id
|
14
12
|
end
|
15
13
|
|
16
|
-
create_table :people_stores, :
|
14
|
+
create_table :people_stores, id: false, force: true do |t|
|
17
15
|
t.integer :person_id
|
18
16
|
t.string :store_id
|
19
17
|
end
|
20
18
|
|
21
|
-
create_table :apples, :
|
22
|
-
t.integer :id
|
19
|
+
create_table :apples, force: true do |t|
|
23
20
|
t.string :name
|
24
21
|
t.integer :store_id
|
25
22
|
t.integer :person_id
|
26
23
|
end
|
27
24
|
|
28
|
-
create_table :bananas, :
|
29
|
-
t.integer :id
|
25
|
+
create_table :bananas, force: true do |t|
|
30
26
|
t.string :name
|
31
27
|
t.integer :store_id
|
32
28
|
t.integer :person_id
|
33
29
|
end
|
34
30
|
|
35
|
-
create_table :pears, :
|
36
|
-
t.integer :id
|
31
|
+
create_table :pears, force: true do |t|
|
37
32
|
t.string :name
|
38
33
|
t.integer :store_id
|
39
34
|
t.integer :person_id
|
40
35
|
end
|
41
36
|
|
42
|
-
create_table :addresses, :
|
43
|
-
t.integer :id
|
37
|
+
create_table :addresses, force: true do |t|
|
44
38
|
t.string :name
|
45
39
|
t.integer :store_id
|
46
40
|
t.string :location
|
47
41
|
end
|
48
42
|
|
49
|
-
create_table :languages, :
|
43
|
+
create_table :languages, force: true do |t|
|
50
44
|
t.string :name
|
51
45
|
t.string :locale
|
52
46
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
if ActiveRecord::VERSION::MAJOR < 4
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class Base
|
5
|
+
class << self
|
6
|
+
# generic find_by introduced in Rails 4
|
7
|
+
def find_by(*args)
|
8
|
+
where(*args).first
|
9
|
+
rescue RangeError
|
10
|
+
nil
|
11
|
+
end unless method_defined? :find_by
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ActiveSupport
|
17
|
+
module Dependencies
|
18
|
+
module Loadable
|
19
|
+
# load without arguments in Rails 4 is similar to +to_a+ in Rails 3
|
20
|
+
def load_with_default(*args)
|
21
|
+
if self.respond_to?(:to_a)
|
22
|
+
self.to_a
|
23
|
+
else
|
24
|
+
self.load_without_default(*args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
alias_method_chain :load, :default
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'ActiveRecord Visitor' do
|
4
|
+
RSpec.describe 'ActiveRecord Visitor' do
|
5
5
|
|
6
6
|
def find_visit_methods(visitor_class)
|
7
7
|
(visitor_class.instance_methods + visitor_class.private_instance_methods).select{ |method| method.to_s =~ /^visit_Arel_/ }.sort.uniq
|
data/spec/lib/base_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe RecordCache::Base do
|
4
|
+
RSpec.describe RecordCache::Base do
|
5
5
|
|
6
6
|
it "should run a block in enabled mode" do
|
7
7
|
RecordCache::Base.disable!
|
@@ -18,4 +18,4 @@ describe RecordCache::Base do
|
|
18
18
|
RecordCache::Base.logger = nil
|
19
19
|
expect(RecordCache::Base.logger).to eq(::ActiveRecord::Base.logger)
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
data/spec/lib/dispatcher_spec.rb
CHANGED
data/spec/lib/multi_read_spec.rb
CHANGED
data/spec/lib/query_spec.rb
CHANGED
data/spec/lib/statistics_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe RecordCache::Statistics do
|
3
|
+
RSpec.describe RecordCache::Statistics do
|
4
4
|
before(:each) do
|
5
5
|
# remove active setting from other tests
|
6
6
|
RecordCache::Statistics.send(:remove_instance_variable, :@active) if RecordCache::Statistics.instance_variable_get(:@active)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe RecordCache::Strategy::Base do
|
4
|
+
RSpec.describe RecordCache::Strategy::Base do
|
5
5
|
|
6
6
|
it "should force implementation of self.parse method" do
|
7
7
|
module RecordCache
|
@@ -46,54 +46,54 @@ describe RecordCache::Strategy::Base do
|
|
46
46
|
|
47
47
|
context "filter" do
|
48
48
|
it "should apply filter on :id cache hits" do
|
49
|
-
expect{ @apples = Apple.where(:id => [1,2]).where(:name => "Adams Apple 1").
|
50
|
-
expect(@apples).to eq([Apple.
|
49
|
+
expect{ @apples = Apple.where(:id => [1,2]).where(:name => "Adams Apple 1").load }.to use_cache(Apple).on(:id)
|
50
|
+
expect(@apples).to eq([Apple.find_by(name: "Adams Apple 1")])
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "should apply filter on index cache hits" do
|
54
|
-
expect{ @apples = Apple.where(:store_id => 1).where(:name => "Adams Apple 1").
|
55
|
-
expect(@apples).to eq([Apple.
|
54
|
+
expect{ @apples = Apple.where(:store_id => 1).where(:name => "Adams Apple 1").load }.to use_cache(Apple).on(:store_id)
|
55
|
+
expect(@apples).to eq([Apple.find_by(name: "Adams Apple 1")])
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should return empty array when filter does not match any record" do
|
59
|
-
expect{ @apples = Apple.where(:store_id => 1).where(:name => "Adams Apple Pie").
|
59
|
+
expect{ @apples = Apple.where(:store_id => 1).where(:name => "Adams Apple Pie").load }.to use_cache(Apple).on(:store_id)
|
60
60
|
expect(@apples).to be_empty
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should filter on text" do
|
64
|
-
expect{ @apples = Apple.where(:id => [1,2]).where(:name => "Adams Apple 1").
|
65
|
-
expect(@apples).to eq([Apple.
|
64
|
+
expect{ @apples = Apple.where(:id => [1,2]).where(:name => "Adams Apple 1").load }.to use_cache(Apple).on(:id)
|
65
|
+
expect(@apples).to eq([Apple.find_by(name: "Adams Apple 1")])
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should filter on integers" do
|
69
|
-
expect{ @apples = Apple.where(:id => [1,2,8,9]).where(:store_id => 2).
|
69
|
+
expect{ @apples = Apple.where(:id => [1,2,8,9]).where(:store_id => 2).load }.to use_cache(Apple).on(:id)
|
70
70
|
expect(@apples.map(&:id).sort).to eq([8,9])
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should filter on dates" do
|
74
|
-
expect{ @people = Person.where(:id => [1,2,3]).where(:birthday => Date.civil(1953,11,11)).
|
74
|
+
expect{ @people = Person.where(:id => [1,2,3]).where(:birthday => Date.civil(1953,11,11)).load }.to use_cache(Person).on(:id)
|
75
75
|
expect(@people.size).to eq(1)
|
76
76
|
expect(@people.first.name).to eq("Blue")
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should filter on floats" do
|
80
|
-
expect{ @people = Person.where(:id => [1,2,3]).where(:height => 1.75).
|
80
|
+
expect{ @people = Person.where(:id => [1,2,3]).where(:height => 1.75).load }.to use_cache(Person).on(:id)
|
81
81
|
expect(@people.size).to eq(2)
|
82
82
|
expect(@people.map(&:name).sort).to eq(["Blue", "Cris"])
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should filter on arrays" do
|
86
|
-
expect{ @apples = Apple.where(:id => [1,2,8,9]).where(:store_id => [2, 4]).
|
86
|
+
expect{ @apples = Apple.where(:id => [1,2,8,9]).where(:store_id => [2, 4]).load }.to use_cache(Apple).on(:id)
|
87
87
|
expect(@apples.map(&:id).sort).to eq([8,9])
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
it "should filter on multiple fields" do
|
91
91
|
# make sure two apples exist with the same name
|
92
92
|
@apple = Apple.find(8)
|
93
93
|
@apple.name = Apple.find(9).name
|
94
94
|
@apple.save!
|
95
95
|
|
96
|
-
expect{ @apples = Apple.where(:id => [1,2,3,8,9,10]).where(:store_id => 2).where(:name => @apple.name).
|
96
|
+
expect{ @apples = Apple.where(:id => [1,2,3,8,9,10]).where(:store_id => 2).where(:name => @apple.name).load }.to use_cache(Apple).on(:id)
|
97
97
|
expect(@apples.size).to eq(2)
|
98
98
|
expect(@apples.map(&:name)).to eq([@apple.name, @apple.name])
|
99
99
|
expect(@apples.map(&:id).sort).to eq([8,9])
|
@@ -103,94 +103,94 @@ describe RecordCache::Strategy::Base do
|
|
103
103
|
|
104
104
|
context "sort" do
|
105
105
|
it "should apply sort on :id cache hits" do
|
106
|
-
expect{ @people = Person.where(:id => [1,2,3]).order("name DESC").
|
106
|
+
expect{ @people = Person.where(:id => [1,2,3]).order("name DESC").load }.to use_cache(Person).on(:id)
|
107
107
|
expect(@people.map(&:name)).to eq(["Cris", "Blue", "Adam"])
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should apply sort on index cache hits" do
|
111
|
-
expect{ @apples = Apple.where(:store_id => 1).order("person_id ASC").
|
111
|
+
expect{ @apples = Apple.where(:store_id => 1).order("person_id ASC").load }.to use_cache(Apple).on(:store_id)
|
112
112
|
expect(@apples.map(&:person_id)).to eq([nil, nil, 4, 4, 5])
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
it "should default to ASC" do
|
116
|
-
expect{ @apples = Apple.where(:store_id => 1).order("person_id").
|
116
|
+
expect{ @apples = Apple.where(:store_id => 1).order("person_id").load }.to use_cache(Apple).on(:store_id)
|
117
117
|
expect(@apples.map(&:person_id)).to eq([nil, nil, 4, 4, 5])
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should apply sort nil first for ASC" do
|
121
|
-
expect{ @apples = Apple.where(:store_id => 1).order("person_id ASC").
|
121
|
+
expect{ @apples = Apple.where(:store_id => 1).order("person_id ASC").load }.to use_cache(Apple).on(:store_id)
|
122
122
|
expect(@apples.map(&:person_id)).to eq([nil, nil, 4, 4, 5])
|
123
123
|
end
|
124
124
|
|
125
125
|
it "should apply sort nil last for DESC" do
|
126
|
-
expect{ @apples = Apple.where(:store_id => 1).order("person_id DESC").
|
126
|
+
expect{ @apples = Apple.where(:store_id => 1).order("person_id DESC").load }.to use_cache(Apple).on(:store_id)
|
127
127
|
expect(@apples.map(&:person_id)).to eq([5, 4, 4, nil, nil])
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should sort ascending on text" do
|
131
|
-
expect{ @people = Person.where(:id => [1,2,3,4]).order("name ASC").
|
131
|
+
expect{ @people = Person.where(:id => [1,2,3,4]).order("name ASC").load }.to use_cache(Person).on(:id)
|
132
132
|
expect(@people.map(&:name)).to eq(["Adam", "Blue", "Cris", "Fry"])
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should sort descending on text" do
|
136
|
-
expect{ @people = Person.where(:id => [1,2,3,4]).order("name DESC").
|
136
|
+
expect{ @people = Person.where(:id => [1,2,3,4]).order("name DESC").load }.to use_cache(Person).on(:id)
|
137
137
|
expect(@people.map(&:name)).to eq(["Fry", "Cris", "Blue", "Adam"])
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should sort ascending on integers" do
|
141
|
-
expect{ @people = Person.where(:id => [1,2,3,4]).order("id ASC").
|
141
|
+
expect{ @people = Person.where(:id => [1,2,3,4]).order("id ASC").load }.to use_cache(Person).on(:id)
|
142
142
|
expect(@people.map(&:id)).to eq([1,2,3,4])
|
143
143
|
end
|
144
144
|
|
145
145
|
it "should sort descending on integers" do
|
146
|
-
expect{ @people = Person.where(:id => [1,2,3,4]).order("id DESC").
|
146
|
+
expect{ @people = Person.where(:id => [1,2,3,4]).order("id DESC").load }.to use_cache(Person).on(:id)
|
147
147
|
expect(@people.map(&:id)).to eq([4,3,2,1])
|
148
148
|
end
|
149
149
|
|
150
150
|
it "should sort ascending on dates" do
|
151
|
-
expect{ @people = Person.where(:id => [1,2,3,4]).order("birthday ASC").
|
151
|
+
expect{ @people = Person.where(:id => [1,2,3,4]).order("birthday ASC").load }.to use_cache(Person).on(:id)
|
152
152
|
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)])
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should sort descending on dates" do
|
156
|
-
expect{ @people = Person.where(:id => [1,2,3,4]).order("birthday DESC").
|
156
|
+
expect{ @people = Person.where(:id => [1,2,3,4]).order("birthday DESC").load }.to use_cache(Person).on(:id)
|
157
157
|
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)])
|
158
158
|
end
|
159
159
|
|
160
160
|
it "should sort ascending on float" do
|
161
|
-
expect{ @people = Person.where(:id => [1,2,3,4]).order("height ASC").
|
161
|
+
expect{ @people = Person.where(:id => [1,2,3,4]).order("height ASC").load }.to use_cache(Person).on(:id)
|
162
162
|
expect(@people.map(&:height)).to eq([1.69, 1.75, 1.75, 1.83])
|
163
163
|
end
|
164
164
|
|
165
165
|
it "should sort descending on float" do
|
166
|
-
expect{ @people = Person.where(:id => [1,2,3,4]).order("height DESC").
|
166
|
+
expect{ @people = Person.where(:id => [1,2,3,4]).order("height DESC").load }.to use_cache(Person).on(:id)
|
167
167
|
expect(@people.map(&:height)).to eq([1.83, 1.75, 1.75, 1.69])
|
168
168
|
end
|
169
169
|
|
170
170
|
it "should sort on multiple fields (ASC + ASC)" do
|
171
|
-
expect{ @people = Person.where(:id => [2,3,4,5]).order("height ASC, id ASC").
|
171
|
+
expect{ @people = Person.where(:id => [2,3,4,5]).order("height ASC, id ASC").load }.to use_cache(Person).on(:id)
|
172
172
|
expect(@people.map(&:height)).to eq([1.69, 1.75, 1.75, 1.91])
|
173
173
|
expect(@people.map(&:id)).to eq([4, 2, 3, 5])
|
174
174
|
end
|
175
175
|
|
176
176
|
it "should sort on multiple fields (ASC + DESC)" do
|
177
|
-
expect{ @people = Person.where(:id => [2,3,4,5]).order("height ASC, id DESC").
|
177
|
+
expect{ @people = Person.where(:id => [2,3,4,5]).order("height ASC, id DESC").load }.to use_cache(Person).on(:id)
|
178
178
|
expect(@people.map(&:height)).to eq([1.69, 1.75, 1.75, 1.91])
|
179
179
|
expect(@people.map(&:id)).to eq([4, 3, 2, 5])
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should sort on multiple fields (DESC + ASC)" do
|
183
|
-
expect{ @people = Person.where(:id => [2,3,4,5]).order("height DESC, id ASC").
|
183
|
+
expect{ @people = Person.where(:id => [2,3,4,5]).order("height DESC, id ASC").load }.to use_cache(Person).on(:id)
|
184
184
|
expect(@people.map(&:height)).to eq([1.91, 1.75, 1.75, 1.69])
|
185
185
|
expect(@people.map(&:id)).to eq([5, 2, 3, 4])
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should sort on multiple fields (DESC + DESC)" do
|
189
|
-
expect{ @people = Person.where(:id => [2,3,4,5]).order("height DESC, id DESC").
|
189
|
+
expect{ @people = Person.where(:id => [2,3,4,5]).order("height DESC, id DESC").load }.to use_cache(Person).on(:id)
|
190
190
|
expect(@people.map(&:height)).to eq([1.91, 1.75, 1.75, 1.69])
|
191
191
|
expect(@people.map(&:id)).to eq([5, 3, 2, 4])
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
it "should use mysql style collation" do
|
195
195
|
ids = []
|
196
196
|
ids << Person.create!(:name => "ċedriĉ 3").id # latin other special
|
@@ -207,23 +207,23 @@ describe RecordCache::Strategy::Base do
|
|
207
207
|
ids << Person.create!(:name => "čedriĉ ꜩ Last").id # latin special, with latin non-collateable
|
208
208
|
|
209
209
|
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"]
|
210
|
-
expect{ @people = Person.where(:id => ids).order("name ASC").
|
210
|
+
expect{ @people = Person.where(:id => ids).order("name ASC").load }.to hit_cache(Person).on(:id).times(ids.size)
|
211
211
|
expect(@people.map(&:name)).to eq(names_asc)
|
212
212
|
|
213
|
-
expect{ @people = Person.where(:id => ids).order("name DESC").
|
213
|
+
expect{ @people = Person.where(:id => ids).order("name DESC").load }.to hit_cache(Person).on(:id).times(ids.size)
|
214
214
|
expect(@people.map(&:name)).to eq(names_asc.reverse)
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
218
|
it "should combine filter and sort" do
|
219
|
-
expect{ @people = Person.where(:id => [1,2,3]).where(:height => 1.75).order("name DESC").
|
219
|
+
expect{ @people = Person.where(:id => [1,2,3]).where(:height => 1.75).order("name DESC").load }.to use_cache(Person).on(:id)
|
220
220
|
expect(@people.size).to eq(2)
|
221
221
|
expect(@people.map(&:name)).to eq(["Cris", "Blue"])
|
222
222
|
|
223
|
-
expect{ @people = Person.where(:id => [1,2,3]).where(:height => 1.75).order("name").
|
223
|
+
expect{ @people = Person.where(:id => [1,2,3]).where(:height => 1.75).order("name").load }.to hit_cache(Person).on(:id).times(3)
|
224
224
|
expect(@people.map(&:name)).to eq(["Blue", "Cris"])
|
225
225
|
end
|
226
|
-
|
226
|
+
|
227
227
|
context "NotImplementedError" do
|
228
228
|
before(:each) do
|
229
229
|
@invalid_strategy = RecordCache::Strategy::Base.new(Object, nil, nil, {:key => "key"})
|