active_remote-cached 0.2.0 → 1.1.1

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.
@@ -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; nil; end
7
- def self.search; nil; end
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 [:user_guid, :client_guid]
12
- cached_finders_for [:derp, :user_guid, :client_guid]
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 "API" do
23
+ describe 'API' do
17
24
  it "creates 'cached_exist_find_by_guid'" do
18
- ExistMethodClass.must_respond_to("cached_exist_find_by_guid")
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.must_respond_to("cached_exist_search_by_guid")
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.must_respond_to("cached_exist_find_by_user_guid")
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.must_respond_to("cached_exist_search_by_user_guid")
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.must_respond_to("cached_exist_find_by_user_guid_and_client_guid")
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.must_respond_to("cached_exist_search_by_user_guid_and_client_guid")
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.must_respond_to("cached_exist_find_by_client_guid_and_user_guid")
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.must_respond_to("cached_exist_search_by_client_guid_and_user_guid")
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.must_respond_to("cached_exist_find_by_derp_and_user_guid_and_client_guid")
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.must_respond_to("cached_exist_search_by_derp_and_user_guid_and_client_guid")
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.must_respond_to("cached_exist_find_by_client_guid_and_derp_and_user_guid")
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.must_respond_to("cached_exist_search_by_client_guid_and_derp_and_user_guid")
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.must_respond_to("cached_exist_find_by_client_guid_and_user_guid_and_derp")
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.must_respond_to("cached_exist_search_by_client_guid_and_user_guid_and_derp")
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.must_respond_to("cached_exist_find_by_guid?")
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.must_respond_to("cached_exist_search_by_guid?")
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.must_respond_to("cached_exist_find_by_user_guid?")
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.must_respond_to("cached_exist_search_by_user_guid?")
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.must_respond_to("cached_exist_find_by_user_guid_and_client_guid?")
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.must_respond_to("cached_exist_search_by_user_guid_and_client_guid?")
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.must_respond_to("cached_exist_find_by_client_guid_and_user_guid?")
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.must_respond_to("cached_exist_search_by_client_guid_and_user_guid?")
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.must_respond_to("cached_exist_find_by_derp_and_user_guid_and_client_guid?")
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.must_respond_to("cached_exist_search_by_derp_and_user_guid_and_client_guid?")
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.must_respond_to("cached_exist_find_by_client_guid_and_derp_and_user_guid?")
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.must_respond_to("cached_exist_search_by_client_guid_and_derp_and_user_guid?")
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.must_respond_to("cached_exist_find_by_client_guid_and_user_guid_and_derp?")
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.must_respond_to("cached_exist_search_by_client_guid_and_user_guid_and_derp?")
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; nil; end
7
- def self.search; nil; end
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 [:user_guid, :client_guid]
13
- cached_finders_for [:derp, :user_guid, :client_guid]
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
- describe "API" do
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.must_respond_to("cached_find_by_foo")
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.must_respond_to("cached_find_by_guid")
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.must_respond_to("cached_find_by_user_guid")
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.must_respond_to("cached_find_by_user_guid_and_client_guid")
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.must_respond_to("cached_find_by_client_guid_and_user_guid")
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.must_respond_to("cached_find_by_derp_and_user_guid_and_client_guid")
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.must_respond_to("cached_find_by_client_guid_and_derp_and_user_guid")
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.must_respond_to("cached_find_by_client_guid_and_user_guid_and_derp")
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 "#cached_find_by_guid" do
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 "executes find_by_guid when cached_find with guid called" do
62
- FindMethodClass.stub(:find, :hello) do
63
- FindMethodClass.cached_find(:guid => :guid).must_equal(:hello)
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 "executes the fetch block if not present in cache" do
68
- FindMethodClass.stub(:find, :hello) do
69
- FindMethodClass.cached_find_by_guid(:guid).must_equal(:hello)
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 "merges the default options in for the fetch call" do
74
- ::ActiveRemote::Cached.cache.expects(:fetch).with([FindMethodClass.name, "#find", "guid"], :expires_in => 100).returns(:hello)
75
-
76
- FindMethodClass.stub(:find, :hello) do
77
- FindMethodClass.cached_find_by_guid(:guid).must_equal(:hello)
78
- end
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 "overrides the default options with local options for the fetch call" do
82
- ::ActiveRemote::Cached.cache.expects(:fetch).with([FindMethodClass.name, "#find", "guid"], :expires_in => 200).returns(:hello)
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.stub(:find, :hello) do
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 "namespaced cache" do
99
+ describe 'namespaced cache' do
90
100
  before do
91
- ::ActiveRemote::Cached.default_options(:expires_in => 100, :namespace => "MyApp")
101
+ ::ActiveRemote::Cached.default_options(:expires_in => 100, :namespace => 'MyApp')
92
102
  end
93
103
 
94
- it "uses the namespace as a prefix to the cache key" do
95
- ::ActiveRemote::Cached.cache.expects(:fetch).with(["MyApp", FindMethodClass.name, "#find", "guid"], :expires_in => 100).returns(:hello)
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.stub(:find, :hello) do
98
- FindMethodClass.cached_find_by_guid(:guid)
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 "#cached_find_by_foo" do
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 "overrides the default options with cached_finder options for the fetch call" do
115
- ::ActiveRemote::Cached.cache.expects(:fetch).with([FindMethodClass.name, "#find", "foo"], :expires_in => 500).returns(:hello)
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.stub(:find, :hello) do
118
- FindMethodClass.cached_find_by_foo(:foo).must_equal(:hello)
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 "overrides the cached_finder options with local options for the fetch call" do
123
- ::ActiveRemote::Cached.cache.expects(:fetch).with([FindMethodClass.name, "#find", "foo"], :expires_in => 200).returns(:hello)
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.stub(:find, :hello) do
126
- FindMethodClass.cached_find_by_foo(:foo, :expires_in => 200).must_equal(:hello)
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