bps-google-api 0.4.9 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8856171f804e9a62eb6efe7d15ca99c8ffe2ba56754aabd6f2db030c1fb0ef9b
4
- data.tar.gz: 1b20297f206ef497b90ab9b7648dac0bf84c407d82c9f8a891d38903eb39c247
3
+ metadata.gz: de16bf3d1c0b8b9f1971b1bb77077ded52379e3502d667fb3ca168e74bf202aa
4
+ data.tar.gz: 9ef1b294632a591e4808a6d0456e346b2a29922bf0fb756905813586517d83af
5
5
  SHA512:
6
- metadata.gz: 4ae4b2476e6d4efb16593a71d0446217e0d3ab3b3be590918c7e9cbee81817d64bc52d9c164afc904133989666b5bb23d046f2deac6da38da359d0f3a1c82a7c
7
- data.tar.gz: 822146e8b118409ed47cb4ac204ab5f4190fda432b5baf49a937cd68cf140ee38bf860752f985ed6c60d14d79635381e8ffeca15305c84e5d90688c206e709fd
6
+ metadata.gz: 4a5a51dc5e75da452e7d548ad643997b9935ff8f535da11cb289e595deb2025c8bbbf15e77296f2053fd2b75a487af8a9d493ad45f28610e37d7f1b3263dffc3
7
+ data.tar.gz: 140eac17905e9b5396c79e39e7523192c3ce8616090328f893e0afe057e769dae71759a1fdcaac0a731939f485ab80868a662b2db9f48ef72d09658a2f6d2a1e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bps-google-api (0.4.9)
4
+ bps-google-api (0.4.10)
5
5
  exp_retry (~> 0.0.13)
6
6
  fileutils (~> 1.2)
7
7
  google-api-client (~> 0.23.4)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'bps-google-api'
5
- s.version = '0.4.9'
5
+ s.version = '0.4.10'
6
6
  s.date = '2021-02-27'
7
7
  s.summary = 'Configured Google API'
8
8
  s.description = 'A configured Google API wrapper.'
data/lib/google_api.rb CHANGED
@@ -29,11 +29,7 @@ require 'ext/hash' unless defined?(Rails)
29
29
  require 'ext/silent_progress_bar'
30
30
 
31
31
  class GoogleAPI
32
- @@mock = false # Default to normal behavior
33
-
34
32
  class << self
35
- attr_reader :mock
36
-
37
33
  def configuration
38
34
  @configuration ||= GoogleAPI::Config.new
39
35
  end
@@ -53,5 +49,9 @@ class GoogleAPI
53
49
  def mock!(value = true)
54
50
  @mock = value
55
51
  end
52
+
53
+ def mock
54
+ @mock || false
55
+ end
56
56
  end
57
57
  end
@@ -29,10 +29,16 @@ class GoogleAPI
29
29
 
30
30
  def call(method, *args)
31
31
  if GoogleAPI.mock
32
- self.send(:mock, method, *args)
32
+ send(:mock, method, *args)
33
33
  else
34
34
  ExpRetry.for(exception: RETRIES) { service.send(method, *args) }
35
35
  end
36
36
  end
37
+
38
+ # :nocov:
39
+ def mock(*)
40
+ raise 'This method must be overwritten by the inheriting class.'
41
+ end
42
+ # :nocov:
37
43
  end
38
44
  end
@@ -112,7 +112,7 @@ class GoogleAPI
112
112
  Google::Apis::CalendarV3::EventDateTime.new(key => date, time_zone: ENV['TZ'])
113
113
  end
114
114
 
115
- def mock(_method, *_args)
115
+ def mock(*)
116
116
  Google::Apis::CalendarV3::Event.new(
117
117
  id: SecureRandom.hex(8),
118
118
  html_link: 'http://calendar.google.com',
@@ -69,11 +69,6 @@ class GoogleAPI
69
69
 
70
70
  ProgressBar.create(bar_config)
71
71
  end
72
-
73
- # Is this one necessary?
74
- def mock(_method, *_args)
75
- nil
76
- end
77
72
  end
78
73
  end
79
74
  end
@@ -34,7 +34,7 @@ class GoogleAPI
34
34
  Google::Apis::AdminDirectoryV1::Member.new(email: email)
35
35
  end
36
36
 
37
- def mock(_method, *_args)
37
+ def mock(*)
38
38
  Google::Apis::AdminDirectoryV1::Members.new(
39
39
  members: [
40
40
  Google::Apis::AdminDirectoryV1::Member.new(email: 'nobody@example.com')
@@ -178,4 +178,22 @@ RSpec.describe GoogleAPI::Calendar do
178
178
  expect(subject.add_conference(event.id)).to be_a(Google::Apis::CalendarV3::Event)
179
179
  end
180
180
  end
181
+
182
+ describe 'mock' do
183
+ subject { described_class.new }
184
+
185
+ before { GoogleAPI.mock! }
186
+
187
+ it 'calls the mock method' do
188
+ expect(subject).to receive(:mock).and_call_original
189
+
190
+ subject.create({})
191
+ end
192
+
193
+ it 'calls the conference_mock method' do
194
+ expect(subject).to receive(:conference_mock).and_call_original
195
+
196
+ subject.conference_info('')
197
+ end
198
+ end
181
199
  end
@@ -46,4 +46,16 @@ RSpec.describe GoogleAPI::Group do
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ describe 'mock' do
51
+ subject { described_class.new }
52
+
53
+ before { GoogleAPI.mock! }
54
+
55
+ it 'calls the mock method' do
56
+ expect(subject).to receive(:mock).and_call_original
57
+
58
+ subject.members({})
59
+ end
60
+ end
49
61
  end
@@ -12,4 +12,8 @@ RSpec.describe GoogleAPI do
12
12
  it 'raises for invalid levels' do
13
13
  expect { GoogleAPI.logging!(:WRONG) }.to raise_error(ArgumentError, 'Unknown level')
14
14
  end
15
+
16
+ it 'sets the mock flag' do
17
+ expect { GoogleAPI.mock! }.to change { GoogleAPI.mock }.from(false).to(true)
18
+ end
15
19
  end
data/spec/spec_helper.rb CHANGED
@@ -32,4 +32,8 @@ RSpec.configure do |config|
32
32
  ENV['GOOGLE_AUTHORIZATION_CODE'] = 'test-auth-code'
33
33
  ENV['HIDE_PROGRESS_BARS'] = 'true'
34
34
  end
35
+
36
+ config.after do
37
+ GoogleAPI.mock!(false) # Reset mock state
38
+ end
35
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bps-google-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander