active_remote-cached 0.2.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +55 -0
- data/Gemfile +2 -0
- data/Rakefile +6 -4
- data/active_remote-cached.gemspec +23 -17
- data/lib/active_remote/cached/argument_keys.rb +49 -46
- data/lib/active_remote/cached/cache.rb +50 -49
- data/lib/active_remote/cached/railtie.rb +5 -5
- data/lib/active_remote/cached/version.rb +3 -1
- data/lib/active_remote/cached.rb +149 -84
- data/lib/active_remote-cached.rb +3 -1
- data/spec/active_remote/cached/argument_keys_spec.rb +12 -10
- data/spec/active_remote/cached/cache_spec.rb +13 -16
- data/spec/active_remote/cached_delete_methods_spec.rb +19 -12
- data/spec/active_remote/cached_exist_methods_spec.rb +40 -33
- data/spec/active_remote/cached_find_methods_spec.rb +64 -51
- data/spec/active_remote/cached_search_methods_spec.rb +153 -102
- data/spec/spec_helper.rb +5 -10
- metadata +41 -10
@@ -1,130 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
class ExistMethodClass
|
4
6
|
include ::ActiveRemote::Cached
|
5
7
|
|
6
|
-
def self.find
|
7
|
-
|
8
|
+
def self.find
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.search
|
13
|
+
nil
|
14
|
+
end
|
8
15
|
|
9
16
|
cached_finders_for :guid
|
10
17
|
cached_finders_for :guid, :user_guid
|
11
|
-
cached_finders_for [
|
12
|
-
cached_finders_for [
|
18
|
+
cached_finders_for %i[user_guid client_guid]
|
19
|
+
cached_finders_for %i[derp user_guid client_guid]
|
13
20
|
end
|
14
21
|
|
15
22
|
describe ExistMethodClass do
|
16
|
-
describe
|
23
|
+
describe 'API' do
|
17
24
|
it "creates 'cached_exist_find_by_guid'" do
|
18
|
-
ExistMethodClass.
|
25
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_guid)
|
19
26
|
end
|
20
27
|
|
21
28
|
it "creates 'cached_exist_search_by_guid'" do
|
22
|
-
ExistMethodClass.
|
29
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_guid)
|
23
30
|
end
|
24
31
|
|
25
32
|
it "creates 'cached_exist_find_by_user_guid'" do
|
26
|
-
ExistMethodClass.
|
33
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_user_guid)
|
27
34
|
end
|
28
35
|
|
29
36
|
it "creates 'cached_exist_search_by_user_guid'" do
|
30
|
-
ExistMethodClass.
|
37
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_user_guid)
|
31
38
|
end
|
32
39
|
|
33
40
|
it "creates 'cached_exist_find_by_user_guid_and_client_guid'" do
|
34
|
-
ExistMethodClass.
|
41
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_user_guid_and_client_guid)
|
35
42
|
end
|
36
43
|
|
37
44
|
it "creates 'cached_exist_search_by_user_guid_and_client_guid'" do
|
38
|
-
ExistMethodClass.
|
45
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_user_guid_and_client_guid)
|
39
46
|
end
|
40
47
|
|
41
48
|
it "creates 'cached_exist_find_by_client_guid_and_user_guid'" do
|
42
|
-
ExistMethodClass.
|
49
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_client_guid_and_user_guid)
|
43
50
|
end
|
44
51
|
|
45
52
|
it "creates 'cached_exist_search_by_client_guid_and_user_guid'" do
|
46
|
-
ExistMethodClass.
|
53
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_client_guid_and_user_guid)
|
47
54
|
end
|
48
55
|
|
49
56
|
it "creates 'cached_exist_find_by_derp_and_user_guid_and_client_guid'" do
|
50
|
-
ExistMethodClass.
|
57
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_derp_and_user_guid_and_client_guid)
|
51
58
|
end
|
52
59
|
|
53
60
|
it "creates 'cached_exist_search_by_derp_and_user_guid_and_client_guid'" do
|
54
|
-
ExistMethodClass.
|
61
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_derp_and_user_guid_and_client_guid)
|
55
62
|
end
|
56
63
|
|
57
64
|
it "creates 'cached_exist_find_by_client_guid_and_derp_and_user_guid'" do
|
58
|
-
ExistMethodClass.
|
65
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_client_guid_and_derp_and_user_guid)
|
59
66
|
end
|
60
67
|
|
61
68
|
it "creates 'cached_exist_search_by_client_guid_and_derp_and_user_guid'" do
|
62
|
-
ExistMethodClass.
|
69
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_client_guid_and_derp_and_user_guid)
|
63
70
|
end
|
64
71
|
|
65
72
|
it "creates 'cached_exist_find_by_client_guid_and_user_guid_and_derp'" do
|
66
|
-
ExistMethodClass.
|
73
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_client_guid_and_user_guid_and_derp)
|
67
74
|
end
|
68
75
|
|
69
76
|
it "creates 'cached_exist_search_by_client_guid_and_user_guid_and_derp'" do
|
70
|
-
ExistMethodClass.
|
77
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_client_guid_and_user_guid_and_derp)
|
71
78
|
end
|
72
79
|
|
73
80
|
# ? based methods
|
74
81
|
it "creates 'cached_exist_find_by_guid?'" do
|
75
|
-
ExistMethodClass.
|
82
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_guid?)
|
76
83
|
end
|
77
84
|
|
78
85
|
it "creates 'cached_exist_search_by_guid?'" do
|
79
|
-
ExistMethodClass.
|
86
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_guid?)
|
80
87
|
end
|
81
88
|
|
82
89
|
it "creates 'cached_exist_find_by_user_guid?'" do
|
83
|
-
ExistMethodClass.
|
90
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_user_guid?)
|
84
91
|
end
|
85
92
|
|
86
93
|
it "creates 'cached_exist_search_by_user_guid?'" do
|
87
|
-
ExistMethodClass.
|
94
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_user_guid?)
|
88
95
|
end
|
89
96
|
|
90
97
|
it "creates 'cached_exist_find_by_user_guid_and_client_guid?'" do
|
91
|
-
ExistMethodClass.
|
98
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_user_guid_and_client_guid?)
|
92
99
|
end
|
93
100
|
|
94
101
|
it "creates 'cached_exist_search_by_user_guid_and_client_guid?'" do
|
95
|
-
ExistMethodClass.
|
102
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_user_guid_and_client_guid?)
|
96
103
|
end
|
97
104
|
|
98
105
|
it "creates 'cached_exist_find_by_client_guid_and_user_guid?'" do
|
99
|
-
ExistMethodClass.
|
106
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_client_guid_and_user_guid?)
|
100
107
|
end
|
101
108
|
|
102
109
|
it "creates 'cached_exist_search_by_client_guid_and_user_guid?'" do
|
103
|
-
ExistMethodClass.
|
110
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_client_guid_and_user_guid?)
|
104
111
|
end
|
105
112
|
|
106
113
|
it "creates 'cached_exist_find_by_derp_and_user_guid_and_client_guid?'" do
|
107
|
-
ExistMethodClass.
|
114
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_derp_and_user_guid_and_client_guid?)
|
108
115
|
end
|
109
116
|
|
110
117
|
it "creates 'cached_exist_search_by_derp_and_user_guid_and_client_guid?'" do
|
111
|
-
ExistMethodClass.
|
118
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_derp_and_user_guid_and_client_guid?)
|
112
119
|
end
|
113
120
|
|
114
121
|
it "creates 'cached_exist_find_by_client_guid_and_derp_and_user_guid?'" do
|
115
|
-
ExistMethodClass.
|
122
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_client_guid_and_derp_and_user_guid?)
|
116
123
|
end
|
117
124
|
|
118
125
|
it "creates 'cached_exist_search_by_client_guid_and_derp_and_user_guid?'" do
|
119
|
-
ExistMethodClass.
|
126
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_client_guid_and_derp_and_user_guid?)
|
120
127
|
end
|
121
128
|
|
122
129
|
it "creates 'cached_exist_find_by_client_guid_and_user_guid_and_derp?'" do
|
123
|
-
ExistMethodClass.
|
130
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_find_by_client_guid_and_user_guid_and_derp?)
|
124
131
|
end
|
125
132
|
|
126
133
|
it "creates 'cached_exist_search_by_client_guid_and_user_guid_and_derp?'" do
|
127
|
-
ExistMethodClass.
|
134
|
+
expect(ExistMethodClass).to respond_to(:cached_exist_search_by_client_guid_and_user_guid_and_derp?)
|
128
135
|
end
|
129
136
|
end
|
130
137
|
end
|
@@ -1,54 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
class FindMethodClass
|
4
6
|
include ::ActiveRemote::Cached
|
5
7
|
|
6
|
-
def self.find
|
7
|
-
|
8
|
+
def self.find
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.search
|
13
|
+
nil
|
14
|
+
end
|
8
15
|
|
9
16
|
cached_finders_for :foo, :expires_in => 500
|
10
17
|
cached_finders_for :guid
|
11
18
|
cached_finders_for :guid, :user_guid
|
12
|
-
cached_finders_for [
|
13
|
-
cached_finders_for [
|
19
|
+
cached_finders_for %i[user_guid client_guid]
|
20
|
+
cached_finders_for %i[derp user_guid client_guid]
|
14
21
|
end
|
15
22
|
|
16
23
|
describe FindMethodClass do
|
17
|
-
|
24
|
+
let(:versioned_prefix) do
|
25
|
+
"#{RUBY_ENGINE_VERSION}:#{ActiveSupport::VERSION::STRING}"
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'API' do
|
18
29
|
it "creates 'cached_find_by_foo'" do
|
19
|
-
FindMethodClass.
|
30
|
+
expect(FindMethodClass).to respond_to(:cached_find_by_foo)
|
20
31
|
end
|
21
32
|
|
22
33
|
it "creates 'cached_find_by_guid'" do
|
23
|
-
FindMethodClass.
|
34
|
+
expect(FindMethodClass).to respond_to(:cached_find_by_guid)
|
24
35
|
end
|
25
36
|
|
26
37
|
it "creates 'cached_find_by_user_guid'" do
|
27
|
-
FindMethodClass.
|
38
|
+
expect(FindMethodClass).to respond_to(:cached_find_by_user_guid)
|
28
39
|
end
|
29
40
|
|
30
41
|
it "creates 'cached_find_by_user_guid_and_client_guid'" do
|
31
|
-
FindMethodClass.
|
42
|
+
expect(FindMethodClass).to respond_to(:cached_find_by_user_guid_and_client_guid)
|
32
43
|
end
|
33
44
|
|
34
45
|
it "creates 'cached_find_by_client_guid_and_user_guid'" do
|
35
|
-
FindMethodClass.
|
46
|
+
expect(FindMethodClass).to respond_to(:cached_find_by_client_guid_and_user_guid)
|
36
47
|
end
|
37
48
|
|
38
49
|
it "creates 'cached_find_by_derp_and_user_guid_and_client_guid'" do
|
39
|
-
FindMethodClass.
|
50
|
+
expect(FindMethodClass).to respond_to(:cached_find_by_derp_and_user_guid_and_client_guid)
|
40
51
|
end
|
41
52
|
|
42
53
|
it "creates 'cached_find_by_client_guid_and_derp_and_user_guid'" do
|
43
|
-
FindMethodClass.
|
54
|
+
expect(FindMethodClass).to respond_to(:cached_find_by_client_guid_and_derp_and_user_guid)
|
44
55
|
end
|
45
56
|
|
46
57
|
it "creates 'cached_find_by_client_guid_and_user_guid_and_derp'" do
|
47
|
-
FindMethodClass.
|
58
|
+
expect(FindMethodClass).to respond_to(:cached_find_by_client_guid_and_user_guid_and_derp)
|
48
59
|
end
|
49
60
|
end
|
50
61
|
|
51
|
-
describe
|
62
|
+
describe '#cached_find_by_guid' do
|
52
63
|
before do
|
53
64
|
::ActiveRemote::Cached.cache(HashCache.new)
|
54
65
|
::ActiveRemote::Cached.default_options(:expires_in => 100)
|
@@ -58,50 +69,50 @@ describe FindMethodClass do
|
|
58
69
|
::ActiveRemote::Cached.default_options({})
|
59
70
|
end
|
60
71
|
|
61
|
-
it
|
62
|
-
FindMethodClass.
|
63
|
-
|
64
|
-
end
|
72
|
+
it 'executes find_by_guid when cached_find with guid called' do
|
73
|
+
expect(FindMethodClass).to receive(:find).and_return(:hello)
|
74
|
+
expect(FindMethodClass.cached_find(:guid => :guid)).to eq(:hello)
|
65
75
|
end
|
66
76
|
|
67
|
-
it
|
68
|
-
FindMethodClass.
|
69
|
-
|
70
|
-
end
|
77
|
+
it 'executes the fetch block if not present in cache' do
|
78
|
+
expect(FindMethodClass).to receive(:find).and_return(:hello)
|
79
|
+
expect(FindMethodClass.cached_find_by_guid(:guid)).to eq(:hello)
|
71
80
|
end
|
72
81
|
|
73
|
-
it
|
74
|
-
::ActiveRemote::Cached.cache.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
82
|
+
it 'merges the default options in for the fetch call' do
|
83
|
+
expect(::ActiveRemote::Cached.cache).to receive(:fetch).with(
|
84
|
+
[versioned_prefix, FindMethodClass.name, '#find', 'guid'], { :expires_in => 100 }
|
85
|
+
).and_return(:hello)
|
86
|
+
expect(FindMethodClass).not_to receive(:find)
|
87
|
+
expect(FindMethodClass.cached_find_by_guid(:guid)).to eq(:hello)
|
79
88
|
end
|
80
89
|
|
81
|
-
it
|
82
|
-
::ActiveRemote::Cached.cache.
|
90
|
+
it 'overrides the default options with local options for the fetch call' do
|
91
|
+
expect(::ActiveRemote::Cached.cache).to receive(:fetch).with(
|
92
|
+
[versioned_prefix, FindMethodClass.name, '#find', 'guid'], { :expires_in => 200 }
|
93
|
+
).and_return(:hello)
|
94
|
+
expect(FindMethodClass).not_to receive(:find)
|
83
95
|
|
84
|
-
FindMethodClass.
|
85
|
-
FindMethodClass.cached_find_by_guid(:guid, :expires_in => 200).must_equal(:hello)
|
86
|
-
end
|
96
|
+
expect(FindMethodClass.cached_find_by_guid(:guid, :expires_in => 200)).to eq(:hello)
|
87
97
|
end
|
88
98
|
|
89
|
-
describe
|
99
|
+
describe 'namespaced cache' do
|
90
100
|
before do
|
91
|
-
::ActiveRemote::Cached.default_options(:expires_in => 100, :namespace =>
|
101
|
+
::ActiveRemote::Cached.default_options(:expires_in => 100, :namespace => 'MyApp')
|
92
102
|
end
|
93
103
|
|
94
|
-
it
|
95
|
-
::ActiveRemote::Cached.cache.
|
104
|
+
it 'uses the namespace as a prefix to the cache key' do
|
105
|
+
expect(::ActiveRemote::Cached.cache).to receive(:fetch).with(
|
106
|
+
[versioned_prefix, 'MyApp', FindMethodClass.name, '#find', 'guid'], { :expires_in => 100 }
|
107
|
+
).and_return(:hello)
|
96
108
|
|
97
|
-
FindMethodClass.
|
98
|
-
|
99
|
-
end
|
109
|
+
expect(FindMethodClass).not_to receive(:find)
|
110
|
+
FindMethodClass.cached_find_by_guid(:guid)
|
100
111
|
end
|
101
112
|
end
|
102
113
|
end
|
103
114
|
|
104
|
-
describe
|
115
|
+
describe '#cached_find_by_foo' do
|
105
116
|
before do
|
106
117
|
::ActiveRemote::Cached.cache(HashCache.new)
|
107
118
|
::ActiveRemote::Cached.default_options(:expires_in => 100)
|
@@ -111,20 +122,22 @@ describe FindMethodClass do
|
|
111
122
|
::ActiveRemote::Cached.default_options({})
|
112
123
|
end
|
113
124
|
|
114
|
-
it
|
115
|
-
::ActiveRemote::Cached.cache.
|
125
|
+
it 'overrides the default options with cached_finder options for the fetch call' do
|
126
|
+
expect(::ActiveRemote::Cached.cache).to receive(:fetch).with(
|
127
|
+
[versioned_prefix, FindMethodClass.name, '#find', 'foo'], { :expires_in => 500 }
|
128
|
+
).and_return(:hello)
|
116
129
|
|
117
|
-
FindMethodClass.
|
118
|
-
|
119
|
-
end
|
130
|
+
expect(FindMethodClass).not_to receive(:find)
|
131
|
+
expect(FindMethodClass.cached_find_by_foo(:foo)).to eq(:hello)
|
120
132
|
end
|
121
133
|
|
122
|
-
it
|
123
|
-
::ActiveRemote::Cached.cache.
|
134
|
+
it 'overrides the cached_finder options with local options for the fetch call' do
|
135
|
+
expect(::ActiveRemote::Cached.cache).to receive(:fetch).with(
|
136
|
+
[versioned_prefix, FindMethodClass.name, '#find', 'foo'], { :expires_in => 200 }
|
137
|
+
).and_return(:hello)
|
124
138
|
|
125
|
-
FindMethodClass.
|
126
|
-
|
127
|
-
end
|
139
|
+
expect(FindMethodClass).not_to receive(:find)
|
140
|
+
expect(FindMethodClass.cached_find_by_foo(:foo, :expires_in => 200)).to eq(:hello)
|
128
141
|
end
|
129
142
|
end
|
130
143
|
end
|