cached_resource 7.2.0 → 9.0.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 +4 -4
- data/lib/cached_resource/cached_resource.rb +2 -2
- data/lib/cached_resource/caching.rb +48 -28
- data/lib/cached_resource/configuration.rb +17 -15
- data/lib/cached_resource/version.rb +1 -1
- data/lib/cached_resource.rb +10 -10
- metadata +80 -27
- data/.github/workflows/ruby.yml +0 -109
- data/.gitignore +0 -7
- data/.rspec +0 -3
- data/FUNDING.json +0 -7
- data/Gemfile +0 -29
- data/LICENSE +0 -20
- data/README.md +0 -208
- data/Rakefile +0 -7
- data/cached_resource.gemspec +0 -28
- data/gemfiles/4.2.gemfile +0 -6
- data/gemfiles/5.0.gemfile +0 -3
- data/gemfiles/5.1.gemfile +0 -3
- data/gemfiles/6.0.gemfile +0 -3
- data/gemfiles/6.1.gemfile +0 -3
- data/gemfiles/7.0.gemfile +0 -3
- data/spec/cached_resource/cached_resource_spec.rb +0 -29
- data/spec/cached_resource/caching_spec.rb +0 -594
- data/spec/cached_resource/configuration_spec.rb +0 -235
- data/spec/spec_helper.rb +0 -13
@@ -1,235 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "CachedResource::Configuration" do
|
4
|
-
|
5
|
-
let(:configuration) { CachedResource::Configuration.new }
|
6
|
-
let(:default_logger) { defined?(ActiveSupport::Logger) ? ActiveSupport::Logger : ActiveSupport::BufferedLogger }
|
7
|
-
|
8
|
-
describe "by default" do
|
9
|
-
it "should be enabled" do
|
10
|
-
configuration.enabled.should == true
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should have a cache expiry of 1 week" do
|
14
|
-
configuration.ttl.should == 604800
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should disable collection synchronization" do
|
18
|
-
configuration.collection_synchronize.should == false
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should default to :all for collection arguments" do
|
22
|
-
configuration.collection_arguments.should == [:all]
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should cache collections" do
|
26
|
-
configuration.cache_collections == true
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "outside a Rails environment" do
|
30
|
-
it "should be logging to a buffered logger attached to a NilIO" do
|
31
|
-
configuration.logger.class.should == default_logger
|
32
|
-
# ActiveSupport switched around the log destination variables
|
33
|
-
# Check if either are what we expect to be compatible
|
34
|
-
old_as = configuration.logger.instance_variable_get(:@log).class == NilIO
|
35
|
-
new_as = configuration.logger.instance_variable_get(:@log_dest).class == NilIO
|
36
|
-
newer_as = configuration.logger.instance_variable_get(:@logdev).instance_variable_get(:@dev).class == NilIO
|
37
|
-
(old_as || new_as || newer_as).should == true
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should cache responses in a memory store" do
|
41
|
-
configuration.cache.class.should == ActiveSupport::Cache::MemoryStore
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "inside a Rails environment" do
|
46
|
-
before(:each) do
|
47
|
-
Rails = OpenStruct.new(:logger => "logger", :cache => "cache")
|
48
|
-
load "cached_resource/configuration.rb"
|
49
|
-
end
|
50
|
-
|
51
|
-
after(:each) do
|
52
|
-
# remove the rails constant and unbind the
|
53
|
-
# cache and logger from the configuration
|
54
|
-
# defaults
|
55
|
-
Object.send(:remove_const, :Rails)
|
56
|
-
load "cached_resource/configuration.rb"
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should be logging to the rails logger" do
|
60
|
-
configuration.logger.should == "logger"
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should cache responses in a memory store" do
|
64
|
-
configuration.cache.should == "cache"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "when initialized through cached resource" do
|
70
|
-
before(:each) do
|
71
|
-
class Foo < ActiveResource::Base
|
72
|
-
cached_resource :ttl => 1,
|
73
|
-
:race_condition_ttl => 5,
|
74
|
-
:cache => "cache",
|
75
|
-
:logger => "logger",
|
76
|
-
:enabled => false,
|
77
|
-
:collection_synchronize => true,
|
78
|
-
:collection_arguments => [:every],
|
79
|
-
:custom => "irrelevant",
|
80
|
-
:cache_collections => true
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
after(:each) do
|
85
|
-
Object.send(:remove_const, :Foo)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should relfect the specified options" do
|
89
|
-
cr = Foo.cached_resource
|
90
|
-
cr.ttl.should == 1
|
91
|
-
expect(cr.race_condition_ttl).to eq(5)
|
92
|
-
cr.cache.should == "cache"
|
93
|
-
cr.logger.should == "logger"
|
94
|
-
cr.enabled.should == false
|
95
|
-
cr.collection_synchronize.should == true
|
96
|
-
cr.collection_arguments.should == [:every]
|
97
|
-
cr.custom.should == "irrelevant"
|
98
|
-
cr.cache_collections.should == true
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# re-evaluate
|
103
|
-
describe "when multiple are initialized through cached resource" do
|
104
|
-
before(:each) do
|
105
|
-
class Foo < ActiveResource::Base
|
106
|
-
cached_resource
|
107
|
-
end
|
108
|
-
|
109
|
-
class Bar < ActiveResource::Base
|
110
|
-
cached_resource
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
after(:each) do
|
115
|
-
Object.send(:remove_const, :Foo)
|
116
|
-
Object.send(:remove_const, :Bar)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "they should have different configuration objects" do
|
120
|
-
Foo.cached_resource.object_id.should_not == Bar.cached_resource.object_id
|
121
|
-
end
|
122
|
-
|
123
|
-
it "they should have the same attributes" do
|
124
|
-
Foo.cached_resource.instance_variable_get(:@table).should == Bar.cached_resource.instance_variable_get(:@table)
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "when cached resource is inherited" do
|
130
|
-
before(:each) do
|
131
|
-
class Bar < ActiveResource::Base
|
132
|
-
cached_resource :ttl => 1,
|
133
|
-
:race_condition_ttl => 5,
|
134
|
-
:cache => "cache",
|
135
|
-
:logger => "logger",
|
136
|
-
:enabled => false,
|
137
|
-
:collection_synchronize => true,
|
138
|
-
:collection_arguments => [:every],
|
139
|
-
:custom => "irrelevant",
|
140
|
-
:cache_collections => true
|
141
|
-
end
|
142
|
-
|
143
|
-
class Foo < Bar
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
after(:each) do
|
148
|
-
Object.send(:remove_const, :Foo)
|
149
|
-
Object.send(:remove_const, :Bar)
|
150
|
-
end
|
151
|
-
|
152
|
-
it "it should make sure each subclass has the same configuration" do
|
153
|
-
Bar.cached_resource.object_id.should == Foo.cached_resource.object_id
|
154
|
-
end
|
155
|
-
|
156
|
-
end
|
157
|
-
|
158
|
-
describe "when cached resource is inherited and then overriden" do
|
159
|
-
before(:each) do
|
160
|
-
class Bar < ActiveResource::Base
|
161
|
-
cached_resource :ttl => 1,
|
162
|
-
:race_condition_ttl => 5,
|
163
|
-
:cache => "cache",
|
164
|
-
:logger => "logger",
|
165
|
-
:enabled => false,
|
166
|
-
:collection_synchronize => true,
|
167
|
-
:collection_arguments => [:every],
|
168
|
-
:custom => "irrelevant",
|
169
|
-
:cache_collections => true
|
170
|
-
end
|
171
|
-
|
172
|
-
class Foo < Bar
|
173
|
-
# override the superclasses configuration
|
174
|
-
self.cached_resource = CachedResource::Configuration.new(:ttl => 60)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
after(:each) do
|
179
|
-
Object.send(:remove_const, :Foo)
|
180
|
-
Object.send(:remove_const, :Bar)
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should have the specified options" do
|
184
|
-
Foo.cached_resource.ttl.should == 60
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should have the default options for anything unspecified" do
|
188
|
-
cr = Foo.cached_resource
|
189
|
-
cr.cache.class.should == ActiveSupport::Cache::MemoryStore
|
190
|
-
cr.logger.class.should == default_logger
|
191
|
-
cr.enabled.should == true
|
192
|
-
cr.collection_synchronize.should == false
|
193
|
-
cr.collection_arguments.should == [:all]
|
194
|
-
cr.custom.should == nil
|
195
|
-
cr.ttl_randomization.should == false
|
196
|
-
cr.ttl_randomization_scale.should == (1..2)
|
197
|
-
cr.cache_collections.should == true
|
198
|
-
expect(cr.race_condition_ttl).to eq(86400)
|
199
|
-
end
|
200
|
-
|
201
|
-
end
|
202
|
-
|
203
|
-
# At the moment, not too keen on implementing some fancy
|
204
|
-
# randomness validator.
|
205
|
-
describe "when ttl randomization is enabled" do
|
206
|
-
before(:each) do
|
207
|
-
@ttl = 1
|
208
|
-
configuration.ttl = @ttl
|
209
|
-
configuration.ttl_randomization = true
|
210
|
-
configuration.send(:sample_range, 1..2, @ttl)
|
211
|
-
# next ttl: 1.72032449344216
|
212
|
-
end
|
213
|
-
|
214
|
-
it "it should produce a random ttl between ttl and ttl * 2" do
|
215
|
-
generated_ttl = configuration.generate_ttl
|
216
|
-
generated_ttl.should_not == 10
|
217
|
-
(@ttl..(2 * @ttl)).should include(generated_ttl)
|
218
|
-
end
|
219
|
-
|
220
|
-
describe "when a ttl randomization scale is set" do
|
221
|
-
before(:each) do
|
222
|
-
@lower = 0.5
|
223
|
-
@upper = 1
|
224
|
-
configuration.ttl_randomization_scale = @lower..@upper
|
225
|
-
# next ttl 0.860162246721079
|
226
|
-
end
|
227
|
-
|
228
|
-
it "should produce a random ttl between ttl * lower bound and ttl * upper bound" do
|
229
|
-
lower = @ttl * @lower
|
230
|
-
upper = @ttl * @upper
|
231
|
-
(lower..upper).should include(configuration.generate_ttl)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
require 'active_resource'
|
4
|
-
require 'active_support'
|
5
|
-
require 'active_support/time'
|
6
|
-
|
7
|
-
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
8
|
-
require 'cached_resource'
|
9
|
-
|
10
|
-
RSpec.configure do |config|
|
11
|
-
# nada
|
12
|
-
end
|
13
|
-
|