mongoid-cached-json 1.6.0 → 1.7.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/.github/workflows/danger-comment.yml +11 -0
- data/.github/workflows/danger.yml +13 -0
- data/.github/workflows/test.yml +67 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +120 -67
- data/CHANGELOG.md +59 -65
- data/CONTRIBUTING.md +2 -0
- data/Dangerfile +5 -0
- data/Gemfile +14 -17
- data/README.md +94 -9
- data/UPGRADING.md +59 -0
- data/lib/mongoid-cached-json/cached_json.rb +61 -16
- data/lib/mongoid-cached-json/version.rb +1 -1
- data/spec/all_fields_spec.rb +47 -0
- data/spec/cache_version_spec.rb +58 -0
- data/spec/cached_json_spec.rb +20 -11
- data/spec/dalli_spec.rb +3 -4
- data/spec/field_cache_spec.rb +73 -0
- data/spec/model_cache_spec.rb +64 -0
- data/spec/mongoid_criteria_spec.rb +2 -1
- data/spec/spec_helper.rb +22 -0
- data/spec/support/json_employee.rb +1 -0
- data/spec/support/json_manager.rb +6 -1
- metadata +16 -8
- data/.travis.yml +0 -40
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Declaring all stored fields' do
|
|
4
|
+
before do
|
|
5
|
+
class AllFieldsDocument
|
|
6
|
+
include Mongoid::Document
|
|
7
|
+
include Mongoid::CachedJson
|
|
8
|
+
field :name
|
|
9
|
+
field :secret
|
|
10
|
+
|
|
11
|
+
def display_name
|
|
12
|
+
name.upcase
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
json_fields :all, secret: { properties: :all }, display_name: {}
|
|
16
|
+
field :added_later
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
after do
|
|
21
|
+
AllFieldsDocument.delete_all
|
|
22
|
+
Object.send(:remove_const, :AllFieldsDocument)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'expands fields at declaration time and adds computed fields' do
|
|
26
|
+
document = AllFieldsDocument.create!(name: 'example', secret: 'hidden', added_later: 'not declared')
|
|
27
|
+
expected = { _id: document.id, name: 'example', display_name: 'EXAMPLE' }
|
|
28
|
+
expect(document.as_json).to eq(expected)
|
|
29
|
+
expect([document].as_json).to eq([expected])
|
|
30
|
+
expect(document.as_json(properties: :all)).to eq(expected.merge(secret: 'hidden'))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'retains the normal field cache and invalidation behavior' do
|
|
34
|
+
document = AllFieldsDocument.create!(name: 'example')
|
|
35
|
+
document.as_json
|
|
36
|
+
document.name = 'unsaved'
|
|
37
|
+
expect(document.as_json[:name]).to eq('example')
|
|
38
|
+
document.save!
|
|
39
|
+
expect(document.as_json[:name]).to eq('unsaved')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'does not expose extra fields for ordinary explicit declarations' do
|
|
43
|
+
document = JsonFoobar.create!(foo: 'visible', bar: 'private')
|
|
44
|
+
expect(document.as_json).not_to have_key(:bar)
|
|
45
|
+
expect(document.as_json).not_to have_key(:_id)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Schema cache versions' do
|
|
4
|
+
before do
|
|
5
|
+
class VersionedDocument
|
|
6
|
+
include Mongoid::Document
|
|
7
|
+
include Mongoid::CachedJson
|
|
8
|
+
field :value
|
|
9
|
+
json_fields cache_version: 1, value: {}
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
after do
|
|
14
|
+
VersionedDocument.delete_all
|
|
15
|
+
Object.send(:remove_const, :VersionedDocument)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
[true, false].each do |bulk|
|
|
19
|
+
context "with bulk reads #{bulk}" do
|
|
20
|
+
before do
|
|
21
|
+
@store = ActiveSupport::Cache::MemoryStore.new
|
|
22
|
+
@store.singleton_class.send(:undef_method, :read_multi) unless bulk
|
|
23
|
+
Mongoid::CachedJson.config.cache = @store
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'separates new schema fragments without changing the API version' do
|
|
27
|
+
document = VersionedDocument.create!(value: 'old')
|
|
28
|
+
expect(document.as_json).to eq(value: 'old')
|
|
29
|
+
document.value = 'new'
|
|
30
|
+
expect(document.as_json).to eq(value: 'old')
|
|
31
|
+
VersionedDocument.cached_json_cache_version = 2
|
|
32
|
+
expect(document.as_json).to eq(value: 'new')
|
|
33
|
+
VersionedDocument.cached_json_cache_version = 1
|
|
34
|
+
expect(document.as_json).to eq(value: 'old')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'invalidates the current namespace on a model update' do
|
|
38
|
+
document = VersionedDocument.create!(value: 'old')
|
|
39
|
+
[1, 2].each do |version|
|
|
40
|
+
VersionedDocument.cached_json_cache_version = version
|
|
41
|
+
document.as_json
|
|
42
|
+
end
|
|
43
|
+
document.update_attributes!(value: 'new')
|
|
44
|
+
expect(document.as_json).to eq(value: 'new')
|
|
45
|
+
VersionedDocument.cached_json_cache_version = 1
|
|
46
|
+
expect(document.as_json).to eq(value: 'old')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'uses the schema version for child fragments too' do
|
|
50
|
+
document = VersionedDocument.create!(value: 'old')
|
|
51
|
+
options = { properties: :short, version: :unspecified, is_top_level_json: false }
|
|
52
|
+
key = VersionedDocument.cached_json_key(options, VersionedDocument, document.id)
|
|
53
|
+
expect(key).to end_with('/false/schema/1')
|
|
54
|
+
expect([document].as_json).to eq([{ value: 'old' }])
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/spec/cached_json_spec.rb
CHANGED
|
@@ -6,7 +6,7 @@ describe Mongoid::CachedJson do
|
|
|
6
6
|
expect(Mongoid::CachedJson::VERSION.to_f).to be > 0
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
[
|
|
9
|
+
[MEMCACHE_STORE, :memory_store].each do |cache_store|
|
|
10
10
|
context "#{cache_store}" do
|
|
11
11
|
before :each do
|
|
12
12
|
@cache = Mongoid::CachedJson::Config.cache
|
|
@@ -95,7 +95,7 @@ describe Mongoid::CachedJson do
|
|
|
95
95
|
3.times do
|
|
96
96
|
3.times do
|
|
97
97
|
manager_short_json = manager.as_json(properties: :short)
|
|
98
|
-
expect(manager_short_json.length).to eq(
|
|
98
|
+
expect(manager_short_json.length).to eq(3)
|
|
99
99
|
expect(manager_short_json[:name]).to eq('Boss')
|
|
100
100
|
expect(manager_short_json[:employees].member?(name: 'Peon')).to be_truthy
|
|
101
101
|
expect(manager_short_json[:employees].member?(name: 'Indentured servant')).to be_truthy
|
|
@@ -104,7 +104,7 @@ describe Mongoid::CachedJson do
|
|
|
104
104
|
end
|
|
105
105
|
3.times do
|
|
106
106
|
manager_public_json = manager.as_json(properties: :public)
|
|
107
|
-
expect(manager_public_json.length).to eq(
|
|
107
|
+
expect(manager_public_json.length).to eq(3)
|
|
108
108
|
expect(manager_public_json[:name]).to eq('Boss')
|
|
109
109
|
expect(manager_public_json[:employees].member?(name: 'Peon')).to be_truthy
|
|
110
110
|
expect(manager_public_json[:employees].member?(name: 'Indentured servant')).to be_truthy
|
|
@@ -113,7 +113,7 @@ describe Mongoid::CachedJson do
|
|
|
113
113
|
end
|
|
114
114
|
3.times do
|
|
115
115
|
manager_all_json = manager.as_json(properties: :all)
|
|
116
|
-
expect(manager_all_json.length).to eq(
|
|
116
|
+
expect(manager_all_json.length).to eq(4)
|
|
117
117
|
expect(manager_all_json[:name]).to eq('Boss')
|
|
118
118
|
expect(manager_all_json[:ssn]).to eq('123-45-6789')
|
|
119
119
|
expect(manager_all_json[:employees].member?(name: 'Peon', nickname: 'My Favorite')).to be_truthy
|
|
@@ -132,15 +132,15 @@ describe Mongoid::CachedJson do
|
|
|
132
132
|
manager = JsonManager.create!(name: 'JsonManager')
|
|
133
133
|
employee = manager.json_employees.create!(name: 'JsonEmployee')
|
|
134
134
|
3.times do
|
|
135
|
-
expect(manager.as_json(properties: :short)).to eq(name: 'JsonManager', employees: [{ name: 'JsonEmployee' }])
|
|
135
|
+
expect(manager.as_json(properties: :short)).to eq(name: 'JsonManager', employees: [{ name: 'JsonEmployee' }], has_left_handed_employee: false)
|
|
136
136
|
expect(employee.as_json(properties: :short)).to eq(name: 'JsonEmployee')
|
|
137
137
|
end
|
|
138
138
|
manager.name = 'New JsonManager'
|
|
139
139
|
manager.save
|
|
140
|
-
3.times { expect(manager.as_json(properties: :short)).to eq(name: 'New JsonManager', employees: [{ name: 'JsonEmployee' }]) }
|
|
140
|
+
3.times { expect(manager.as_json(properties: :short)).to eq(name: 'New JsonManager', employees: [{ name: 'JsonEmployee' }], has_left_handed_employee: false) }
|
|
141
141
|
employee.name = 'New JsonEmployee'
|
|
142
142
|
employee.save
|
|
143
|
-
3.times { expect(manager.as_json(properties: :short)).to eq(name: 'New JsonManager', employees: [{ name: 'New JsonEmployee' }]) }
|
|
143
|
+
3.times { expect(manager.as_json(properties: :short)).to eq(name: 'New JsonManager', employees: [{ name: 'New JsonEmployee' }], has_left_handed_employee: false) }
|
|
144
144
|
end
|
|
145
145
|
context 'reference_properties' do
|
|
146
146
|
it 'limits the json fields of a child relationship' do
|
|
@@ -220,6 +220,7 @@ describe Mongoid::CachedJson do
|
|
|
220
220
|
end
|
|
221
221
|
it 'should yield JSON without an instance of a child' do
|
|
222
222
|
p = SecretParent.create(name: 'Parent')
|
|
223
|
+
expect(p.as_json(properties: :short)).to eq(name: 'Parent', child: nil)
|
|
223
224
|
expect(p.as_json(properties: :all)[:child]).to be_nil
|
|
224
225
|
end
|
|
225
226
|
it 'should yield child JSON when as_json is called on the parent and hide_as_child_json_when returns false on an instance' do
|
|
@@ -230,8 +231,8 @@ describe Mongoid::CachedJson do
|
|
|
230
231
|
it 'should not yield child JSON when as_json is called on the parent and hide_as_child_json_when returns true on an instance' do
|
|
231
232
|
p = SecretParent.create(name: 'Parent')
|
|
232
233
|
p.create_sometimes_secret(should_tell_secret: false)
|
|
233
|
-
expect(p.as_json(properties: :short)).to eq(name: 'Parent'
|
|
234
|
-
expect(p.as_json(properties: :short)
|
|
234
|
+
expect(p.as_json(properties: :short)).to eq(name: 'Parent')
|
|
235
|
+
expect(p.as_json(properties: :short)).not_to have_key(:child)
|
|
235
236
|
end
|
|
236
237
|
end
|
|
237
238
|
context 'relationships with a multi-level hierarchy' do
|
|
@@ -353,9 +354,9 @@ describe Mongoid::CachedJson do
|
|
|
353
354
|
example = JsonFoobar.create(foo: 'FOO', baz: 'BAZ', bar: 'BAR')
|
|
354
355
|
key = "as_json/unspecified/JsonFoobar/#{example.id}/short/true"
|
|
355
356
|
case cache_store
|
|
356
|
-
when :memory_store
|
|
357
|
+
when :memory_store
|
|
357
358
|
expect(Mongoid::CachedJson.config.cache).to receive(:fetch).with(key, force: true).twice
|
|
358
|
-
when :dalli_store
|
|
359
|
+
when :dalli_store, :mem_cache_store
|
|
359
360
|
expect(Mongoid::CachedJson.config.cache).not_to receive(:write)
|
|
360
361
|
else
|
|
361
362
|
fail ArgumentError, "invalid cache store: #{cache_store}"
|
|
@@ -496,6 +497,14 @@ describe Mongoid::CachedJson do
|
|
|
496
497
|
expect(@image.as_json(properties: :all)).to eq(name: 'Image', urls: [])
|
|
497
498
|
end
|
|
498
499
|
end
|
|
500
|
+
context 'evaluating a false-y value in a reference type' do
|
|
501
|
+
it 'correctly returns false instead of nil' do
|
|
502
|
+
manager = JsonManager.create!(name: 'Boss')
|
|
503
|
+
manager.json_employees.create!(name: 'Matt')
|
|
504
|
+
manager_short_json = manager.as_json(properties: :short)
|
|
505
|
+
expect(manager_short_json[:has_left_handed_employee]).to eq(false)
|
|
506
|
+
end
|
|
507
|
+
end
|
|
499
508
|
end
|
|
500
509
|
end
|
|
501
510
|
end
|
data/spec/dalli_spec.rb
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
require 'active_support/cache/dalli_store'
|
|
3
2
|
|
|
4
|
-
describe
|
|
3
|
+
describe MEMCACHE_STORE_CLASS do
|
|
5
4
|
before :each do
|
|
6
5
|
@cache = Mongoid::CachedJson::Config.cache
|
|
7
6
|
Mongoid::CachedJson.configure do |config|
|
|
8
|
-
config.cache = ActiveSupport::Cache.lookup_store(
|
|
7
|
+
config.cache = ActiveSupport::Cache.lookup_store(MEMCACHE_STORE)
|
|
9
8
|
end
|
|
10
9
|
end
|
|
11
10
|
after :each do
|
|
12
11
|
Mongoid::CachedJson::Config.cache = @cache
|
|
13
12
|
end
|
|
14
13
|
it 'uses dalli_store' do
|
|
15
|
-
expect(Mongoid::CachedJson.config.cache).to be_a
|
|
14
|
+
expect(Mongoid::CachedJson.config.cache).to be_a MEMCACHE_STORE_CLASS
|
|
16
15
|
end
|
|
17
16
|
context 'read_multi' do
|
|
18
17
|
context 'array' do
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Per-field cache policy' do
|
|
4
|
+
before do
|
|
5
|
+
class FieldCacheDocument
|
|
6
|
+
include Mongoid::Document
|
|
7
|
+
include Mongoid::CachedJson
|
|
8
|
+
|
|
9
|
+
field :stored
|
|
10
|
+
field :live
|
|
11
|
+
|
|
12
|
+
json_fields stored: {}, live: { cache: false }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class FieldCacheChild
|
|
16
|
+
include Mongoid::Document
|
|
17
|
+
include Mongoid::CachedJson
|
|
18
|
+
|
|
19
|
+
field :value
|
|
20
|
+
|
|
21
|
+
json_fields value: {}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class FieldCacheParent
|
|
25
|
+
include Mongoid::Document
|
|
26
|
+
include Mongoid::CachedJson
|
|
27
|
+
|
|
28
|
+
field :name
|
|
29
|
+
attr_accessor :child
|
|
30
|
+
|
|
31
|
+
json_fields name: {}, child: { type: :reference, cache: false }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
after do
|
|
36
|
+
[FieldCacheDocument, FieldCacheChild, FieldCacheParent].each(&:delete_all)
|
|
37
|
+
[:FieldCacheDocument, :FieldCacheChild, :FieldCacheParent].each { |name| Object.send(:remove_const, name) }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
[true, false].each do |bulk|
|
|
41
|
+
context "with bulk reads #{bulk}" do
|
|
42
|
+
before do
|
|
43
|
+
@store = ActiveSupport::Cache::MemoryStore.new
|
|
44
|
+
@store.singleton_class.send(:undef_method, :read_multi) unless bulk
|
|
45
|
+
Mongoid::CachedJson.config.cache = @store
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'recomputes an individual callable field without refreshing cached siblings' do
|
|
49
|
+
document = FieldCacheDocument.create!(stored: 'stored', live: 'first')
|
|
50
|
+
expect(document.as_json).to eq(stored: 'stored', live: 'first')
|
|
51
|
+
|
|
52
|
+
document.stored = 'unsaved'
|
|
53
|
+
document.live = 'second'
|
|
54
|
+
expect(document.as_json).to eq(stored: 'stored', live: 'second')
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'bypasses the referenced model cache only for this field' do
|
|
58
|
+
parent = FieldCacheParent.create!(name: 'parent')
|
|
59
|
+
child = FieldCacheChild.create!(value: 'first')
|
|
60
|
+
parent.child = child
|
|
61
|
+
options = { properties: :short, version: :unspecified, is_top_level_json: false }
|
|
62
|
+
key = FieldCacheChild.cached_json_key(options, FieldCacheChild, child.id)
|
|
63
|
+
|
|
64
|
+
expect(parent.as_json).to eq(name: 'parent', child: { value: 'first' })
|
|
65
|
+
expect(@store.read(key)).to be_nil
|
|
66
|
+
|
|
67
|
+
child.value = 'second'
|
|
68
|
+
expect(parent.as_json).to eq(name: 'parent', child: { value: 'second' })
|
|
69
|
+
expect(@store.read(key)).to be_nil
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Per-model cache policy' do
|
|
4
|
+
before do
|
|
5
|
+
class UncachedDocument
|
|
6
|
+
include Mongoid::Document
|
|
7
|
+
include Mongoid::CachedJson
|
|
8
|
+
field :value
|
|
9
|
+
json_fields disable_caching: true, value: {}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class CachedContainer
|
|
13
|
+
include Mongoid::Document
|
|
14
|
+
include Mongoid::CachedJson
|
|
15
|
+
field :value
|
|
16
|
+
attr_accessor :child
|
|
17
|
+
|
|
18
|
+
json_fields value: {}, child: { type: :reference }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
after do
|
|
23
|
+
[UncachedDocument, CachedContainer].each(&:delete_all)
|
|
24
|
+
[:UncachedDocument, :CachedContainer].each { |name| Object.send(:remove_const, name) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
[true, false].each do |bulk|
|
|
28
|
+
context "with bulk reads #{bulk}" do
|
|
29
|
+
before do
|
|
30
|
+
@store = ActiveSupport::Cache::MemoryStore.new
|
|
31
|
+
@store.singleton_class.send(:undef_method, :read_multi) unless bulk
|
|
32
|
+
Mongoid::CachedJson.config.cache = @store
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'does not read or write shared cache for a disabled model' do
|
|
36
|
+
document = UncachedDocument.create!(value: 'first')
|
|
37
|
+
expect(@store).not_to receive(:read_multi)
|
|
38
|
+
expect(@store).not_to receive(:fetch)
|
|
39
|
+
expect(@store).not_to receive(:write)
|
|
40
|
+
expect(document.as_json).to eq(value: 'first')
|
|
41
|
+
document.value = 'second'
|
|
42
|
+
expect([document].as_json).to eq([{ value: 'second' }])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'keeps the parent cached while recomputing a disabled child' do
|
|
46
|
+
parent = CachedContainer.create!(value: 'parent')
|
|
47
|
+
child = UncachedDocument.create!(value: 'first')
|
|
48
|
+
parent.child = child
|
|
49
|
+
expect(parent.as_json).to eq(value: 'parent', child: { value: 'first' })
|
|
50
|
+
parent.value = 'not saved'
|
|
51
|
+
child.value = 'second'
|
|
52
|
+
expect(parent.as_json).to eq(value: 'parent', child: { value: 'second' })
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'does not disable caching on other models' do
|
|
56
|
+
expect(CachedContainer.cached_json_disable_caching).to be_falsey
|
|
57
|
+
document = CachedContainer.create!(value: 'first')
|
|
58
|
+
document.as_json
|
|
59
|
+
document.value = 'second'
|
|
60
|
+
expect(document.as_json[:value]).to eq('first')
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -68,7 +68,8 @@ describe Mongoid::Criteria do
|
|
|
68
68
|
)
|
|
69
69
|
# read_multi returned only 2 of 3 things, don't call fetch, just store the third value
|
|
70
70
|
expect(Mongoid::CachedJson.config.cache).not_to receive(:fetch)
|
|
71
|
-
|
|
71
|
+
expected_json = { name: 'screwdriver' }
|
|
72
|
+
expect(Mongoid::CachedJson.config.cache).to receive(:write).with("as_json/unspecified/Tool/#{tool2.id}/all/true", expected_json)
|
|
72
73
|
expect(tool_box.tools.as_json(properties: :all)).to eq([
|
|
73
74
|
{ tool_box: { x: :y }, x: :y },
|
|
74
75
|
{ tool_box: { x: :y }, name: 'screwdriver' }
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
if ENV['COVERAGE'] == 'true'
|
|
2
|
+
require 'simplecov'
|
|
3
|
+
SimpleCov.start do
|
|
4
|
+
track_files 'lib/**/*.rb'
|
|
5
|
+
add_filter '/spec/'
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
1
9
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
10
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
11
|
|
|
@@ -11,8 +19,22 @@ end
|
|
|
11
19
|
|
|
12
20
|
Mongoid.configure do |config|
|
|
13
21
|
config.connect_to('cached_json_test')
|
|
22
|
+
if Mongoid::VERSION.to_i >= 5
|
|
23
|
+
config.clients['default']['hosts'] = [ENV.fetch('MONGODB_HOST', 'localhost:27017')]
|
|
24
|
+
else
|
|
25
|
+
config.sessions['default']['hosts'] = [ENV.fetch('MONGODB_HOST', 'localhost:27017')]
|
|
26
|
+
end
|
|
14
27
|
end
|
|
15
28
|
|
|
29
|
+
if ActiveSupport::VERSION::MAJOR >= 6
|
|
30
|
+
require 'active_support/cache/mem_cache_store'
|
|
31
|
+
else
|
|
32
|
+
require 'active_support/cache/dalli_store'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
MEMCACHE_STORE = ActiveSupport::VERSION::MAJOR >= 6 ? :mem_cache_store : :dalli_store
|
|
36
|
+
MEMCACHE_STORE_CLASS = ActiveSupport::Cache.lookup_store(MEMCACHE_STORE).class
|
|
37
|
+
|
|
16
38
|
RSpec.configure do |config|
|
|
17
39
|
config.raise_errors_for_deprecations!
|
|
18
40
|
config.after :each do
|
|
@@ -12,8 +12,13 @@ class JsonManager
|
|
|
12
12
|
belongs_to :supervisor, class_name: 'JsonSupervisor', required: false
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
def has_left_handed_employee?
|
|
16
|
+
json_employees.any? { |e| e.is_left_handed? }
|
|
17
|
+
end
|
|
18
|
+
|
|
15
19
|
json_fields \
|
|
16
20
|
name: {},
|
|
17
21
|
ssn: { properties: :all },
|
|
18
|
-
employees: { type: :reference, definition: :json_employees }
|
|
22
|
+
employees: { type: :reference, definition: :json_employees },
|
|
23
|
+
has_left_handed_employee: { type: :reference, definition: :has_left_handed_employee? }
|
|
19
24
|
end
|
metadata
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
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.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aaron Windsor
|
|
8
8
|
- Daniel Doubrovkine
|
|
9
9
|
- Frank Macreery
|
|
10
|
-
autorequire:
|
|
10
|
+
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2026-10-17 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: mongoid
|
|
@@ -26,23 +26,27 @@ dependencies:
|
|
|
26
26
|
- - ">="
|
|
27
27
|
- !ruby/object:Gem::Version
|
|
28
28
|
version: '3.0'
|
|
29
|
-
description:
|
|
29
|
+
description:
|
|
30
30
|
email: dblock@dblock.org
|
|
31
31
|
executables: []
|
|
32
32
|
extensions: []
|
|
33
33
|
extra_rdoc_files: []
|
|
34
34
|
files:
|
|
35
|
+
- ".github/workflows/danger-comment.yml"
|
|
36
|
+
- ".github/workflows/danger.yml"
|
|
37
|
+
- ".github/workflows/test.yml"
|
|
35
38
|
- ".gitignore"
|
|
36
39
|
- ".rspec"
|
|
37
40
|
- ".rubocop.yml"
|
|
38
41
|
- ".rubocop_todo.yml"
|
|
39
|
-
- ".travis.yml"
|
|
40
42
|
- CHANGELOG.md
|
|
41
43
|
- CONTRIBUTING.md
|
|
44
|
+
- Dangerfile
|
|
42
45
|
- Gemfile
|
|
43
46
|
- LICENSE.md
|
|
44
47
|
- README.md
|
|
45
48
|
- Rakefile
|
|
49
|
+
- UPGRADING.md
|
|
46
50
|
- lib/mongoid-cached-json.rb
|
|
47
51
|
- lib/mongoid-cached-json/array.rb
|
|
48
52
|
- lib/mongoid-cached-json/cached_json.rb
|
|
@@ -52,12 +56,16 @@ files:
|
|
|
52
56
|
- lib/mongoid-cached-json/mongoid_criteria.rb
|
|
53
57
|
- lib/mongoid-cached-json/version.rb
|
|
54
58
|
- mongoid-cached-json.gemspec
|
|
59
|
+
- spec/all_fields_spec.rb
|
|
55
60
|
- spec/array_spec.rb
|
|
56
61
|
- spec/benchmark_spec.rb
|
|
62
|
+
- spec/cache_version_spec.rb
|
|
57
63
|
- spec/cached_json_spec.rb
|
|
58
64
|
- spec/config_spec.rb
|
|
59
65
|
- spec/dalli_spec.rb
|
|
66
|
+
- spec/field_cache_spec.rb
|
|
60
67
|
- spec/hash_spec.rb
|
|
68
|
+
- spec/model_cache_spec.rb
|
|
61
69
|
- spec/mongoid_criteria_spec.rb
|
|
62
70
|
- spec/spec_helper.rb
|
|
63
71
|
- spec/support/awesome_artwork.rb
|
|
@@ -91,7 +99,7 @@ homepage: http://github.com/mongoid/mongoid-cached-json
|
|
|
91
99
|
licenses:
|
|
92
100
|
- MIT
|
|
93
101
|
metadata: {}
|
|
94
|
-
post_install_message:
|
|
102
|
+
post_install_message:
|
|
95
103
|
rdoc_options: []
|
|
96
104
|
require_paths:
|
|
97
105
|
- lib
|
|
@@ -106,8 +114,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
106
114
|
- !ruby/object:Gem::Version
|
|
107
115
|
version: 1.3.6
|
|
108
116
|
requirements: []
|
|
109
|
-
rubygems_version: 3.
|
|
110
|
-
signing_key:
|
|
117
|
+
rubygems_version: 3.5.16
|
|
118
|
+
signing_key:
|
|
111
119
|
specification_version: 4
|
|
112
120
|
summary: Cached-json is a DSL for describing JSON representations of Mongoid models.
|
|
113
121
|
test_files: []
|
data/.travis.yml
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
sudo: false
|
|
2
|
-
|
|
3
|
-
script: bundle exec rake spec
|
|
4
|
-
|
|
5
|
-
services:
|
|
6
|
-
- mongodb
|
|
7
|
-
- memcache
|
|
8
|
-
|
|
9
|
-
rvm:
|
|
10
|
-
- 2.0.0
|
|
11
|
-
- 2.1.10
|
|
12
|
-
- 2.2.10
|
|
13
|
-
- 2.3.7
|
|
14
|
-
- 2.4.6
|
|
15
|
-
- 2.5.5
|
|
16
|
-
- 2.6.3
|
|
17
|
-
|
|
18
|
-
env:
|
|
19
|
-
- MONGOID_VERSION=3
|
|
20
|
-
- MONGOID_VERSION=4
|
|
21
|
-
- MONGOID_VERSION=5
|
|
22
|
-
- MONGOID_VERSION=6
|
|
23
|
-
- MONGOID_VERSION=7
|
|
24
|
-
|
|
25
|
-
cache: bundler
|
|
26
|
-
|
|
27
|
-
matrix:
|
|
28
|
-
include:
|
|
29
|
-
- rvm: 2.6.3
|
|
30
|
-
env: RUBOCOP=true
|
|
31
|
-
script: bundle exec rake rubocop
|
|
32
|
-
exclude:
|
|
33
|
-
- rvm: 2.0.0
|
|
34
|
-
env: MONGOID_VERSION=6
|
|
35
|
-
- rvm: 2.1.10
|
|
36
|
-
env: MONGOID_VERSION=6
|
|
37
|
-
- rvm: 2.0.0
|
|
38
|
-
env: MONGOID_VERSION=7
|
|
39
|
-
- rvm: 2.1.10
|
|
40
|
-
env: MONGOID_VERSION=7
|