scoped_cache_keys 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/scoped_cache_keys.rb +0 -5
- data/lib/scoped_cache_keys/version.rb +1 -1
- data/spec/scoped_cache_keys_spec.rb +0 -34
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/lib/scoped_cache_keys.rb
CHANGED
@@ -10,11 +10,6 @@ module ScopedCacheKeys
|
|
10
10
|
Rails.cache.delete(build_scoped_cache_key(scope))
|
11
11
|
end
|
12
12
|
|
13
|
-
def touch_if_necessary
|
14
|
-
raise "#{self.class} has no updated_at" unless respond_to? :updated_at=
|
15
|
-
touch if updated_at < 1.second.ago
|
16
|
-
end
|
17
|
-
|
18
13
|
private
|
19
14
|
|
20
15
|
def build_scoped_cache_key(*scopes)
|
@@ -60,38 +60,4 @@ describe ScopedCacheKeys do
|
|
60
60
|
}.to_not change{ user.scoped_cache_key(:foo) }
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
64
|
-
describe "#touch_if_necessary" do
|
65
|
-
context "with a model that has updated_at" do
|
66
|
-
let(:model) do
|
67
|
-
user = User.create!
|
68
|
-
user.update_attribute(:updated_at, 1.month.ago)
|
69
|
-
user
|
70
|
-
end
|
71
|
-
|
72
|
-
it "increments updated_at" do
|
73
|
-
expect{
|
74
|
-
model.touch_if_necessary
|
75
|
-
}.to change{ model.reload.updated_at.to_i }
|
76
|
-
end
|
77
|
-
|
78
|
-
it "does not update updated_at if it thinks the model is fresh" do
|
79
|
-
model.touch_if_necessary
|
80
|
-
expect{
|
81
|
-
model.class.update(model.id, :updated_at => 1.month.ago)
|
82
|
-
model.touch_if_necessary
|
83
|
-
}.to change{ model.reload.updated_at.to_i }
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "with a model that does not have updated_at" do
|
88
|
-
let(:model){ Product.create! }
|
89
|
-
|
90
|
-
it "raises" do
|
91
|
-
expect{
|
92
|
-
model.touch_if_necessary
|
93
|
-
}.to raise_error
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
63
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scoped_cache_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Grosser
|