cached_resource 2.3.1 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,7 @@ module CachedResource
36
36
  object = find_without_cache(*arguments)
37
37
  cache_collection_synchronize(object, *arguments) if cached_resource.collection_synchronize
38
38
  cache_write(key, object)
39
- object
39
+ cache_read(key)
40
40
  end
41
41
 
42
42
  # If this is a pure, unadulterated "all" request
@@ -82,7 +82,11 @@ module CachedResource
82
82
  def cache_read(key)
83
83
  key = cache_key(Array(key)) unless key.is_a? String
84
84
  object = cached_resource.cache.read(key).try do |cache|
85
- cache.dup.tap { |o| o.instance_variable_set(:@persisted, cache.persisted?) if cache.respond_to?(:persisted?) }
85
+ if cache.is_a? Enumerable
86
+ cache.map { |record| full_dup(record) }
87
+ else
88
+ full_dup(cache)
89
+ end
86
90
  end
87
91
  object && cached_resource.logger.info("#{CachedResource::Configuration::LOGGER_PREFIX} READ #{key}")
88
92
  object
@@ -102,6 +106,14 @@ module CachedResource
102
106
  "#{name.parameterize.gsub("-", "/")}/#{arguments.join('/')}".downcase
103
107
  end
104
108
 
109
+ # Make a full duplicate of an ActiveResource record.
110
+ # Currently just dups the record then copies the persisted state.
111
+ def full_dup(record)
112
+ record.dup.tap do |o|
113
+ o.instance_variable_set(:@persisted, record.persisted?)
114
+ end
115
+ end
116
+
105
117
  end
106
118
  end
107
119
  end
@@ -1,3 +1,3 @@
1
1
  module CachedResource
2
- VERSION = "2.3.1"
2
+ VERSION = "2.3.2"
3
3
  end
@@ -96,6 +96,66 @@ describe CachedResource do
96
96
  ActiveResource::HttpMock.requests.length.should == 2
97
97
  end
98
98
 
99
+ it "should not return a frozen object on first request" do
100
+ result1 = Thing.find(1)
101
+ result1.should_not be_frozen
102
+ end
103
+
104
+ it "should not return frozen object on a subsequent request" do
105
+ result1 = Thing.find(1)
106
+ result2 = Thing.find(1)
107
+ result2.should_not be_frozen
108
+ end
109
+
110
+ it "should not freeze first requested object on a subsequent request" do
111
+ result1 = Thing.find(1)
112
+ result2 = Thing.find(1)
113
+ result1.should_not be_frozen
114
+ end
115
+
116
+ shared_examples "collection_freezing" do
117
+ it "should not return a frozen collection on first request" do
118
+ Thing.cached_resource.cache.clear
119
+ collection1 = Thing.all
120
+ collection1.should_not be_frozen
121
+ end
122
+
123
+ it "should not return a frozen collection on a subsequent request" do
124
+ Thing.cached_resource.cache.clear
125
+ collection1 = Thing.all
126
+ collection2 = Thing.all
127
+ collection2.should_not be_frozen
128
+ end
129
+
130
+ it "should not freeze first requested collection on a subsequent request" do
131
+ Thing.cached_resource.cache.clear
132
+ result1 = Thing.all
133
+ result2 = Thing.all
134
+ result1.should_not be_frozen
135
+ end
136
+
137
+ it "should not return frozen members on first request" do
138
+ Thing.cached_resource.cache.clear
139
+ collection1 = Thing.all
140
+ collection1.first.should_not be_frozen
141
+ end
142
+
143
+ it "should not return frozen members on a subsequent request" do
144
+ Thing.cached_resource.cache.clear
145
+ collection1 = Thing.all
146
+ collection2 = Thing.all
147
+ collection2.first.should_not be_frozen
148
+ end
149
+
150
+ it "should not freeze members on a subsequent request" do
151
+ Thing.cached_resource.cache.clear
152
+ collection1 = Thing.all
153
+ member1 = Thing.find(1)
154
+ collection1.first.should_not be_frozen
155
+ end
156
+
157
+ end
158
+
99
159
  describe "when collection synchronize is enabled" do
100
160
  before(:each) do
101
161
  Thing.cached_resource.cache.clear
@@ -111,6 +171,8 @@ describe CachedResource do
111
171
  Thing.all
112
172
  end
113
173
 
174
+ include_examples "collection_freezing"
175
+
114
176
  it "should write cache entries for its members" do
115
177
  result = Thing.find(1)
116
178
  # only the all request should have been made
@@ -210,6 +272,8 @@ describe CachedResource do
210
272
  Thing.all
211
273
  end
212
274
 
275
+ include_examples "collection_freezing"
276
+
213
277
  it "should not write cache entries for its members" do
214
278
  result = Thing.find(1)
215
279
  # both the all in the before each and this request should have been made
metadata CHANGED
@@ -1,101 +1,102 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cached_resource
3
- version: !ruby/object:Gem::Version
4
- hash: 1
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.3.2
5
5
  prerelease:
6
- segments:
7
- - 2
8
- - 3
9
- - 1
10
- version: 2.3.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Andrew Chan
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-05-20 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-06-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: activeresource
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activeresource
32
+ requirement: !ruby/object:Gem::Requirement
38
33
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
46
38
  type: :runtime
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: activesupport
50
39
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
52
49
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
60
54
  type: :runtime
61
- version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- name: nilio
64
55
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
66
57
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: nilio
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
74
70
  type: :runtime
75
- version_requirements: *id004
76
- - !ruby/object:Gem::Dependency
77
- name: rspec
78
71
  prerelease: false
79
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
80
73
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
88
86
  type: :development
89
- version_requirements: *id005
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
90
94
  description: Enables request-based caching for ActiveResource
91
95
  email: email@suspi.net
92
96
  executables: []
93
-
94
97
  extensions: []
95
-
96
98
  extra_rdoc_files: []
97
-
98
- files:
99
+ files:
99
100
  - .gitignore
100
101
  - .rspec
101
102
  - .travis.yml
@@ -114,38 +115,35 @@ files:
114
115
  - spec/spec_helper.rb
115
116
  homepage: http://github.com/Ahsizara/cached_resource
116
117
  licenses: []
117
-
118
118
  post_install_message:
119
119
  rdoc_options: []
120
-
121
- require_paths:
120
+ require_paths:
122
121
  - lib
123
- required_ruby_version: !ruby/object:Gem::Requirement
122
+ required_ruby_version: !ruby/object:Gem::Requirement
124
123
  none: false
125
- requirements:
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- hash: 3
129
- segments:
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ segments:
130
129
  - 0
131
- version: "0"
132
- required_rubygems_version: !ruby/object:Gem::Requirement
130
+ hash: -1173904428179810862
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
132
  none: false
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- hash: 3
138
- segments:
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ segments:
139
138
  - 0
140
- version: "0"
139
+ hash: -1173904428179810862
141
140
  requirements: []
142
-
143
141
  rubyforge_project:
144
- rubygems_version: 1.8.11
142
+ rubygems_version: 1.8.24
145
143
  signing_key:
146
144
  specification_version: 3
147
145
  summary: Caching for ActiveResource
148
- test_files:
146
+ test_files:
149
147
  - spec/cached_resource/caching_spec.rb
150
148
  - spec/cached_resource/configuration_spec.rb
151
149
  - spec/spec_helper.rb