cached_enumeration 2.0.1 → 2.1.0
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 +7 -7
- data/cached_enumeration.gemspec +1 -3
- data/lib/cached_enumeration/version.rb +1 -1
- data/spec/lib/association_spec.rb +2 -2
- data/spec/lib/cached_enumeration_spec.rb +51 -51
- data/spec/spec_helper.rb +0 -1
- metadata +79 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 762f263592f84d596f9aa2ecec54a39cf4004322
|
4
|
+
data.tar.gz: de7d357cc9c67fdf7cc1148977e35d516b1c2d8c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 13e7afddd458f163181c2b848c976c5374e80e41862775343725ce1ebc767d04047db575f37904ab936d903718cb09279280e86b8e5b442e9cafa0628a426306
|
7
|
+
data.tar.gz: d9bc25c0ead3780447145195aa56f78ff045444c6a65b2c587c29975a717abc3b94fa2b31e181076d483627ceeae35ece5471bc614a1122f83915ea4db8e4054
|
data/cached_enumeration.gemspec
CHANGED
@@ -22,9 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec","~> 3.1"
|
24
24
|
spec.add_development_dependency "sqlite3","1.3.8"
|
25
|
-
|
26
|
-
# spec.add_development_dependency "rubinius-debugger"
|
27
|
-
spec.add_dependency "activerecord","~> 4.1"
|
25
|
+
spec.add_dependency "activerecord","~> 4.1.0"
|
28
26
|
|
29
27
|
end
|
30
28
|
|
@@ -51,8 +51,8 @@ describe 'association caching' do
|
|
51
51
|
him
|
52
52
|
him.reload #to empty the assoc cache
|
53
53
|
|
54
|
-
Gender.connection.
|
55
|
-
him.gender.name.
|
54
|
+
expect(Gender.connection).not_to receive(:exec_query)
|
55
|
+
expect(him.gender.name).to eq('male')
|
56
56
|
end
|
57
57
|
|
58
58
|
=begin
|
@@ -27,13 +27,13 @@ describe 'simple caching' do
|
|
27
27
|
|
28
28
|
context "cache_enumeration?" do
|
29
29
|
it "should return the rigth value" do
|
30
|
-
@klass.
|
30
|
+
expect(@klass).not_to be_cache_enumeration
|
31
31
|
@klass.cache_enumeration.cache!
|
32
|
-
@klass.
|
32
|
+
expect(@klass).to be_cache_enumeration
|
33
33
|
end
|
34
34
|
it "should not cache if not activated" do
|
35
35
|
@klass.all
|
36
|
-
@klass.
|
36
|
+
expect(@klass).not_to be_cache_enumeration
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -45,29 +45,29 @@ describe 'simple caching' do
|
|
45
45
|
|
46
46
|
it "should fire db queries if all is modified" do
|
47
47
|
@klass.cache_enumeration.cache!
|
48
|
-
@klass.connection.
|
49
|
-
@klass.where("name in ('one','two')").all.size.
|
48
|
+
expect(@klass.connection).to receive(:exec_query).and_call_original
|
49
|
+
expect(@klass.where("name in ('one','two')").all.size).to eq(2)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should fire db queries if all has parameters' do
|
53
53
|
@klass.cache_enumeration.cache!
|
54
54
|
#@klass.connection.should_receive(:exec_query)..and_call_original
|
55
|
-
@klass.where("name = 'one'").all.size.
|
55
|
+
expect(@klass.where("name = 'one'").all.size).to eq(1)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should fire db queries if all with parameters is used through find(:all)' do
|
59
59
|
@klass.cache_enumeration.cache!
|
60
|
-
@klass.connection.
|
61
|
-
@klass.where("name = 'one'").all.size.
|
60
|
+
expect(@klass.connection).to receive(:exec_query).and_call_original
|
61
|
+
expect(@klass.where("name = 'one'").all.size).to eq(1)
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should fire db queries if all with select parameter is used through find(:all)' do
|
65
65
|
@klass.cache_enumeration.cache!
|
66
|
-
@klass.connection.
|
66
|
+
expect(@klass.connection).to receive(:exec_query).and_call_original
|
67
67
|
entry = @klass.select("id, name").all.first
|
68
|
-
|
68
|
+
expect {
|
69
69
|
entry.other
|
70
|
-
}.
|
70
|
+
}.to raise_error(ActiveModel::MissingAttributeError, 'missing attribute: other')
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
@@ -75,40 +75,40 @@ describe 'simple caching' do
|
|
75
75
|
context 'first' do
|
76
76
|
it 'should find the first entry' do
|
77
77
|
@klass.cache_enumeration.cache!
|
78
|
-
@klass.first.
|
78
|
+
expect(@klass.first).to eq(one)
|
79
79
|
end
|
80
80
|
it 'should allwo string order (and use cache)' do
|
81
81
|
@klass.cache_enumeration(:order => "other").cache!
|
82
|
-
@klass.connection.
|
82
|
+
expect(@klass.connection).not_to receive(:exec_query)
|
83
83
|
|
84
|
-
@klass.order('other').first.
|
84
|
+
expect(@klass.order('other').first).to eq(three)
|
85
85
|
end
|
86
86
|
it 'should allow hash condition (and use cache)' do
|
87
87
|
@klass.cache_enumeration.cache!
|
88
|
-
@klass.connection.
|
88
|
+
expect(@klass.connection).not_to receive(:exec_query)
|
89
89
|
|
90
|
-
@klass.where(:name => 'three').first.
|
90
|
+
expect(@klass.where(:name => 'three').first).to eq(three)
|
91
91
|
end
|
92
92
|
it 'should allow string conditions (and ask db)' do
|
93
93
|
@klass.cache_enumeration.cache!
|
94
|
-
@klass.connection.
|
95
|
-
@klass.where("other = 'drei'").first.
|
94
|
+
expect(@klass.connection).to receive(:exec_query).and_call_original
|
95
|
+
expect(@klass.where("other = 'drei'").first).to eq(three)
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'should allow hash conditions in first (and use cache)' do
|
99
99
|
@klass.cache_enumeration.cache!
|
100
|
-
@klass.connection.
|
101
|
-
@klass.where(:name => 'three' ).first.
|
100
|
+
expect(@klass.connection).not_to receive(:exec_query)
|
101
|
+
expect(@klass.where(:name => 'three' ).first).to eq(three)
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should allow conditions for first (and use db)' do
|
105
105
|
@klass.cache_enumeration.cache!
|
106
|
-
@klass.connection.
|
107
|
-
@klass.where("other = 'drei'").first.
|
106
|
+
expect(@klass.connection).to receive(:exec_query).and_call_original
|
107
|
+
expect(@klass.where("other = 'drei'").first).to eq(three)
|
108
108
|
end
|
109
109
|
it 'should allow conditions for first (and use db)' do
|
110
110
|
@klass.cache_enumeration.cache!
|
111
|
-
@klass.connection.
|
111
|
+
expect(@klass.connection).to receive(:exec_query).and_call_original
|
112
112
|
expect(@klass.where("name = 'three'").first).not_to be_nil
|
113
113
|
end
|
114
114
|
end
|
@@ -120,40 +120,40 @@ describe 'simple caching' do
|
|
120
120
|
|
121
121
|
it 'should find objects providing id' do
|
122
122
|
@klass.cache_enumeration.cache!
|
123
|
-
@klass.connection.
|
123
|
+
expect(@klass.connection).not_to receive(:exec_query)
|
124
124
|
|
125
|
-
@klass.find(one.id).id.
|
126
|
-
@klass.find(one.id).frozen?().
|
127
|
-
@klass.find([one.id])[0].id.
|
128
|
-
@klass.find([]).size.
|
125
|
+
expect(@klass.find(one.id).id).to eq(one.id)
|
126
|
+
expect(@klass.find(one.id).frozen?()).to eq(true)
|
127
|
+
expect(@klass.find([one.id])[0].id).to eq(one.id)
|
128
|
+
expect(@klass.find([]).size).to eq(0)
|
129
129
|
|
130
|
-
|
131
|
-
|
130
|
+
expect { @klass.find(0) }.to raise_error(ActiveRecord::RecordNotFound)
|
131
|
+
expect { @klass.find(nil) }.to raise_error(ActiveRecord::RecordNotFound)
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should find an array of object ids (and hit cache)" do
|
135
135
|
@klass.cache_enumeration.cache!
|
136
|
-
@klass.connection.
|
136
|
+
expect(@klass.connection).not_to receive(:exec_query)
|
137
137
|
|
138
|
-
@klass.find([one.id, three.id]).collect { |item| item.id }.
|
138
|
+
expect(@klass.find([one.id, three.id]).collect { |item| item.id }).to eq([one.id, three.id])
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'should find_by' do
|
142
142
|
@klass.cache_enumeration.cache!
|
143
|
-
@klass.connection.
|
143
|
+
expect(@klass.connection).not_to receive(:exec_query)
|
144
144
|
|
145
|
-
@klass.find_by(:id => one.id).id.
|
146
|
-
@klass.find_by(:id => one.id.to_s).id.
|
147
|
-
@klass.find_by(:id => 0).
|
145
|
+
expect(@klass.find_by(:id => one.id).id).to eq(one.id)
|
146
|
+
expect(@klass.find_by(:id => one.id.to_s).id).to eq(one.id)
|
147
|
+
expect(@klass.find_by(:id => 0)).to be_nil
|
148
148
|
end
|
149
149
|
|
150
150
|
it 'should find objects by_name' do
|
151
151
|
one
|
152
152
|
@klass.cache_enumeration.cache!
|
153
|
-
@klass.connection.
|
153
|
+
expect(@klass.connection).not_to receive(:exec_query)
|
154
154
|
|
155
|
-
@klass.find_by(:name => 'one').id.
|
156
|
-
@klass.find_by(:name => 'no such name').
|
155
|
+
expect(@klass.find_by(:name => 'one').id).to eq(one.id)
|
156
|
+
expect(@klass.find_by(:name => 'no such name')).to be_nil
|
157
157
|
end
|
158
158
|
|
159
159
|
end
|
@@ -161,43 +161,43 @@ describe 'simple caching' do
|
|
161
161
|
context "multiple keys" do
|
162
162
|
it 'it should store by multiple keys (hashing)' do
|
163
163
|
@klass.cache_enumeration(:hashed => ['id', 'other', 'name']).cache!
|
164
|
-
@klass.connection.
|
165
|
-
@klass.find_by(:other => 'eins').id.
|
166
|
-
@klass.find_by(:name => 'one').id.
|
164
|
+
expect(@klass.connection).not_to receive(:exec_query)
|
165
|
+
expect(@klass.find_by(:other => 'eins').id).to eq(one.id)
|
166
|
+
expect(@klass.find_by(:name => 'one').id).to eq(one.id)
|
167
167
|
end
|
168
168
|
end
|
169
169
|
context "sorting of all" do
|
170
170
|
it 'should sort by option' do
|
171
171
|
@klass.cache_enumeration(:order => 'name').cache!
|
172
|
-
@klass.connection.
|
172
|
+
expect(@klass.connection).not_to receive(:exec_query)
|
173
173
|
|
174
|
-
@klass.order("name").all.collect { |item| item.id }.
|
174
|
+
expect(@klass.order("name").all.collect { |item| item.id }).to eq([one.id, three.id, two.id])
|
175
175
|
end
|
176
176
|
|
177
177
|
end
|
178
178
|
context "constantize" do
|
179
179
|
it "should constantize name by default" do
|
180
|
-
@klass.cache_enumeration.options[:constantize].
|
180
|
+
expect(@klass.cache_enumeration.options[:constantize]).to eq('name')
|
181
181
|
end
|
182
182
|
it "should without no preloading" do
|
183
183
|
|
184
184
|
@klass.cache_enumeration
|
185
|
-
@klass::ONE.id.
|
185
|
+
expect(@klass::ONE.id).to eq(one.id)
|
186
186
|
end
|
187
187
|
|
188
188
|
it 'should constantize other fields' do
|
189
189
|
@klass.cache_enumeration(:constantize => 'other').cache!
|
190
|
-
@klass.cache_enumeration.options[:constantize].
|
191
|
-
@klass.connection.
|
190
|
+
expect(@klass.cache_enumeration.options[:constantize]).to eq('other')
|
191
|
+
expect(@klass.connection).not_to receive(:exec_query)
|
192
192
|
|
193
|
-
@klass::EINS.id.
|
193
|
+
expect(@klass::EINS.id).to eq(one.id)
|
194
194
|
end
|
195
195
|
|
196
196
|
it "should contantize by lambda" do
|
197
197
|
@klass.cache_enumeration(:constantize => lambda { |model| model.other }).cache!
|
198
|
-
@klass.connection.
|
198
|
+
expect(@klass.connection).not_to receive(:exec_query)
|
199
199
|
|
200
|
-
@klass::EINS.id.
|
200
|
+
expect(@klass::EINS.id).to eq(one.id)
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
data/spec/spec_helper.rb
CHANGED
@@ -14,7 +14,6 @@ require 'cached_enumeration'
|
|
14
14
|
require 'logger'
|
15
15
|
#ActiveRecord::Base.logger=Logger.new(STDOUT)
|
16
16
|
RSpec.configure do |config|
|
17
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
18
17
|
config.run_all_when_everything_filtered = true
|
19
18
|
config.filter_run :focus
|
20
19
|
|
metadata
CHANGED
@@ -1,77 +1,92 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cached_enumeration
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Peter Schrammel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2015-08-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
|
-
|
17
|
-
|
18
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
19
17
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version:
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
22
20
|
type: :development
|
23
|
-
version_requirements: *id001
|
24
|
-
- !ruby/object:Gem::Dependency
|
25
|
-
name: rake
|
26
21
|
prerelease: false
|
27
|
-
|
28
|
-
requirements:
|
29
|
-
-
|
30
|
-
-
|
31
|
-
|
32
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
33
34
|
type: :development
|
34
|
-
version_requirements: *id002
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
37
35
|
prerelease: false
|
38
|
-
|
39
|
-
requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
40
45
|
- - ~>
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version:
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
43
48
|
type: :development
|
44
|
-
version_requirements: *id003
|
45
|
-
- !ruby/object:Gem::Dependency
|
46
|
-
name: sqlite3
|
47
49
|
prerelease: false
|
48
|
-
|
49
|
-
requirements:
|
50
|
-
- -
|
51
|
-
- !ruby/object:Gem::Version
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
52
61
|
version: 1.3.8
|
53
62
|
type: :development
|
54
|
-
version_requirements: *id004
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: activerecord
|
57
63
|
prerelease: false
|
58
|
-
|
59
|
-
requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.8
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
60
73
|
- - ~>
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version:
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.1.0
|
63
76
|
type: :runtime
|
64
|
-
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.1.0
|
65
83
|
description: Cache nonchanging ActiveRecord models in memory
|
66
|
-
email:
|
84
|
+
email:
|
67
85
|
- peter.schrammel@experteer.com
|
68
86
|
executables: []
|
69
|
-
|
70
87
|
extensions: []
|
71
|
-
|
72
88
|
extra_rdoc_files: []
|
73
|
-
|
74
|
-
files:
|
89
|
+
files:
|
75
90
|
- .gitignore
|
76
91
|
- .travis.yml
|
77
92
|
- Gemfile
|
@@ -85,31 +100,31 @@ files:
|
|
85
100
|
- spec/lib/association_spec.rb
|
86
101
|
- spec/lib/cached_enumeration_spec.rb
|
87
102
|
- spec/spec_helper.rb
|
88
|
-
homepage:
|
89
|
-
licenses:
|
103
|
+
homepage: ''
|
104
|
+
licenses:
|
90
105
|
- MIT
|
91
106
|
metadata: {}
|
92
|
-
|
93
107
|
post_install_message:
|
94
108
|
rdoc_options: []
|
95
|
-
|
96
|
-
require_paths:
|
109
|
+
require_paths:
|
97
110
|
- lib
|
98
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
-
|
101
|
-
|
102
|
-
|
103
|
-
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
104
121
|
requirements: []
|
105
|
-
|
106
122
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.4.8
|
108
124
|
signing_key:
|
109
125
|
specification_version: 4
|
110
126
|
summary: Cache nonchanging ActiveRecord models in memory
|
111
|
-
test_files:
|
127
|
+
test_files:
|
112
128
|
- spec/lib/association_spec.rb
|
113
129
|
- spec/lib/cached_enumeration_spec.rb
|
114
130
|
- spec/spec_helper.rb
|
115
|
-
has_rdoc:
|