mongoid-cached-json 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +58 -0
- data/lib/mongoid-cached-json/cached_json.rb +1 -1
- data/lib/mongoid-cached-json/version.rb +1 -1
- metadata +19 -19
data/README.md
CHANGED
@@ -170,6 +170,64 @@ Turning Caching Off
|
|
170
170
|
|
171
171
|
You can set `Mongoid::CachedJson.config.disable_caching = true`. It may be a good idea to set it to `ENV['DISABLE_JSON_CACHING']`, in case this turns out not to be The Solution To All Of Your Performance Problems (TM).
|
172
172
|
|
173
|
+
Testing JSON
|
174
|
+
------------
|
175
|
+
|
176
|
+
This library overrides `as_json`, hence testing JSON results can be done at model level.
|
177
|
+
|
178
|
+
``` ruby
|
179
|
+
describe "as_json" do
|
180
|
+
before :each do
|
181
|
+
@person = Person.create!({ :first => "John", :last => "Doe" })
|
182
|
+
end
|
183
|
+
it "returns name" do
|
184
|
+
@person.as_json({ :properties => :public })[:name].should== "John Doe"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
```
|
188
|
+
|
189
|
+
It's also common to test the results of the API using the [Pathy](https://github.com/twoism/pathy) library.
|
190
|
+
|
191
|
+
``` ruby
|
192
|
+
describe "as_json" do
|
193
|
+
before :each do
|
194
|
+
person = Person.create!({ :first => "John", :last => "Doe" })
|
195
|
+
end
|
196
|
+
it "returns name" do
|
197
|
+
get "/api/person/#{person.id}"
|
198
|
+
response.body.at_json_path("name").should == "John Doe"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
```
|
202
|
+
|
203
|
+
Testing Cache Invalidation
|
204
|
+
--------------------------
|
205
|
+
|
206
|
+
Cache is invalidated by calling `:expire_cached_json` on an instance.
|
207
|
+
|
208
|
+
``` ruby
|
209
|
+
describe "updating a person" do
|
210
|
+
before :each
|
211
|
+
@person = Person.create!({ :name => "John Doe" })
|
212
|
+
end
|
213
|
+
it "invalidates cache" do
|
214
|
+
@person.should_receive :expire_cached_json
|
215
|
+
@person.update_attributes!({ :name => "updated" }
|
216
|
+
end
|
217
|
+
end
|
218
|
+
```
|
219
|
+
You may also want to use [this RSpec matcher](https://github.com/dblock/mongoid-cached-json/blob/master/spec/support/matchers/invalidate.rb).
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
describe "updating a person" do
|
223
|
+
it "invalidates cache" do
|
224
|
+
lambda {
|
225
|
+
@person.update_attributes!({ :name => "updated" }
|
226
|
+
}.should invalidate @person
|
227
|
+
end
|
228
|
+
end
|
229
|
+
```
|
230
|
+
|
173
231
|
Contributing
|
174
232
|
------------
|
175
233
|
|
@@ -93,7 +93,7 @@ module Mongoid
|
|
93
93
|
|
94
94
|
# Cache key.
|
95
95
|
def cached_json_key(options, cached_class, cached_id)
|
96
|
-
base_class_name = cached_class.collection_name.singularize.camelize
|
96
|
+
base_class_name = cached_class.collection_name.to_s.singularize.camelize
|
97
97
|
"as_json/#{options[:version]}/#{base_class_name}/#{cached_id}/#{options[:properties]}/#{!!options[:is_top_level_json]}"
|
98
98
|
end
|
99
99
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-cached-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-05-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
18
|
-
requirement: &
|
18
|
+
requirement: &73269350 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *73269350
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mongoid
|
29
|
-
requirement: &
|
29
|
+
requirement: &73268700 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ! '>='
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: '0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *73268700
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: bson_ext
|
40
|
-
requirement: &
|
40
|
+
requirement: &73268300 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: '0'
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *73268300
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: hpricot
|
51
|
-
requirement: &
|
51
|
+
requirement: &73267850 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ! '>='
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: '0'
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *73267850
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: rspec
|
62
|
-
requirement: &
|
62
|
+
requirement: &73267400 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ~>
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: '2.5'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *73267400
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: bundler
|
73
|
-
requirement: &
|
73
|
+
requirement: &73267040 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ~>
|
@@ -78,10 +78,10 @@ dependencies:
|
|
78
78
|
version: '1.0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *73267040
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: jeweler
|
84
|
-
requirement: &
|
84
|
+
requirement: &73266670 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
87
|
- - ~>
|
@@ -89,10 +89,10 @@ dependencies:
|
|
89
89
|
version: '1.6'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
|
-
version_requirements: *
|
92
|
+
version_requirements: *73266670
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: yard
|
95
|
-
requirement: &
|
95
|
+
requirement: &73266290 !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
97
|
requirements:
|
98
98
|
- - ~>
|
@@ -100,7 +100,7 @@ dependencies:
|
|
100
100
|
version: '0.6'
|
101
101
|
type: :development
|
102
102
|
prerelease: false
|
103
|
-
version_requirements: *
|
103
|
+
version_requirements: *73266290
|
104
104
|
description: Cached-json is a DSL for describing JSON representations of Mongoid models.
|
105
105
|
email: dblock@dblock.org
|
106
106
|
executables: []
|
@@ -130,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
segments:
|
132
132
|
- 0
|
133
|
-
hash: -
|
133
|
+
hash: -353824433
|
134
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
135
|
none: false
|
136
136
|
requirements:
|