aptible-resource 1.1.3 → 1.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5900b6d991cbb35f8f24586a4159c5e20a42bf7eb084c896a1e03d2fd88d393
4
- data.tar.gz: 3bc765fa4be89779be7e70e90d64827281057a1857b2fa6d6bdf7d6473561c19
3
+ metadata.gz: 0be9a27c339a79cef6ee77d5388d8baa8a2eb46fb9ffa3757c9a6bd7c3805271
4
+ data.tar.gz: 5806ba6232617393d0c6ccd83eda9ae8f7bd9a988623abbe9d63e5ed841df9be
5
5
  SHA512:
6
- metadata.gz: 8829126f5c77257f43619f14a8db713c4fe16ad7c63c9d0823047aca7fd3e0d0790238ee677d21648b9cf5e8e55611d062213aa631d4d6053436a6f3254d84e3
7
- data.tar.gz: c3b5c7229ca716235b946402fc92b3b6295b3707e05a762e988956e45c5d32080fcd11fd6ef18c405bb3526ec941bc8b389281a8da9045f8b51e40502d90d5df
6
+ metadata.gz: b7fd6a01fcb9e3f5389b03307046d1db07789932a8eaa5ab5a20cddfc6cb7bf49ff44553b6eb5661d358721bfea0a8265c5fdb026eaa50d18e4c38e9e0c64387
7
+ data.tar.gz: 8c06bb2636c1ad3948b3e30135cb6a16e7f65926f7f4111a44595bf978f5f3913adabd7fda7ffb92ebe25c87169934b7371956c9935e0fc2e4d736ff142d2ca3
@@ -0,0 +1,26 @@
1
+ on:
2
+ release:
3
+ types: [published]
4
+
5
+ jobs:
6
+ push:
7
+ name: Push gem to RubyGems.org
8
+ runs-on: ubuntu-latest
9
+
10
+ permissions:
11
+ id-token: write
12
+ contents: write
13
+
14
+ steps:
15
+ - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
16
+ with:
17
+ persist-credentials: false
18
+ - name: Set up Ruby
19
+ uses: ruby/setup-ruby@211ffaaa5f8dda97e9e8bca4e70d0fbaf2f8c41c
20
+ with:
21
+ bundler-cache: false
22
+ ruby-version: "3.3"
23
+
24
+ - run: bundle install
25
+
26
+ - uses: rubygems/release-gem@1c162a739e8b4cb21a676e97b087e8268d8fc40b
@@ -15,20 +15,15 @@ jobs:
15
15
  strategy:
16
16
  fail-fast: false
17
17
  matrix:
18
- RUBY_VERSION: [2.2, 2.3, 2.6, 2.7]
18
+ RUBY_VERSION: [2.3, 2.4, 2.5, 2.6, 2.7, 3.1, 3.2, 3.3, 3.4]
19
+ env:
20
+ RUBY_VERSION: ${{ matrix.RUBY_VERSION }}
19
21
  steps:
20
22
  - name: Check out code
21
23
  uses: actions/checkout@v4
22
24
 
23
- - name: Install Ruby
24
- uses: ruby/setup-ruby@v1
25
- with:
26
- ruby-version: ${{ matrix.RUBY_VERSION }}
27
- bundler: 1.17.3
28
- bundler-cache: true
29
-
30
25
  - name: Rubocop
31
- run: bundle exec rake rubocop
26
+ run: make lint
32
27
 
33
28
  - name: Test
34
- run: bundle exec rspec
29
+ run: make test
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ /docker/ruby-*/
data/Dockerfile ADDED
@@ -0,0 +1,22 @@
1
+ ARG RUBY_VERSION=2.3.1
2
+ FROM ruby:${RUBY_VERSION}
3
+
4
+ ARG BUNDLER_VERSION=1.17.3
5
+ ENV BUNDLER_VERSION=${BUNDLER_VERSION}
6
+ RUN if [ "${BUNDLER_VERSION}" != "" ] ; then \
7
+ gem install bundler -v "${BUNDLER_VERSION}" ; \
8
+ fi
9
+
10
+ WORKDIR /app
11
+ COPY Gemfile /app/
12
+ COPY aptible-resource.gemspec /app/
13
+ RUN mkdir -p /app/lib/aptible/resource/
14
+ COPY lib/aptible/resource/version.rb /app/lib/aptible/resource/
15
+ RUN mkdir -p /app/lib/hyper_resource/
16
+ COPY lib/hyper_resource/version.rb /app/lib/hyper_resource/
17
+
18
+ RUN bundle install
19
+
20
+ COPY . /app
21
+
22
+ CMD ["bash"]
data/Makefile ADDED
@@ -0,0 +1,74 @@
1
+
2
+ export COMPOSE_IGNORE_ORPHANS ?= true
3
+ export RUBY_VERSION ?= 2.3.1
4
+ RUBY_VERSION_MAJOR = $(word 1,$(subst ., ,$(RUBY_VERSION)))
5
+ RUBY_VERSION_MINOR = $(word 2,$(subst ., ,$(RUBY_VERSION)))
6
+ export BUNDLER_VERSION ?=
7
+ ifeq ($(BUNDLER_VERSION),)
8
+ ifeq ($(RUBY_VERSION_MAJOR),2)
9
+ # Use old bundler for Ruby 2.3-2.6; Ruby 2.7 needs bundler 2.x to avoid resolver bugs
10
+ ifeq ($(RUBY_VERSION_MINOR),7)
11
+ export BUNDLER_VERSION = 2.4.22
12
+ else
13
+ export BUNDLER_VERSION = 1.17.3
14
+ endif
15
+ endif
16
+ endif
17
+ PROJECT_NAME = $(shell ls *.gemspec | sed 's/\.gemspec//')
18
+ export COMPOSE_PROJECT_NAME ?= $(PROJECT_NAME)-$(subst .,_,$(RUBY_VERSION))
19
+
20
+ default: help
21
+
22
+ ## Show this help message
23
+ help:
24
+ @echo "\n\033[1;34mAvailable targets:\033[0m\n"
25
+ @awk 'BEGIN {FS = ":"; prev = ""} \
26
+ /^## / {prev = substr($$0, 4); next} \
27
+ /^[a-zA-Z_-]+:/ {if (prev != "") printf " \033[1;36m%-20s\033[0m %s\n", $$1, prev; prev = ""} \
28
+ {prev = ""}' $(MAKEFILE_LIST) | sort
29
+ @echo
30
+
31
+ BUILD_ARGS ?=
32
+ ## Build and pull docker compose images
33
+ build: gemfile-lock
34
+ docker compose build --pull $(BUILD_ARGS)
35
+
36
+ ## Create a Gemfile.lock specific to the container (i.e., for the ruby version)
37
+ gemfile-lock:
38
+ mkdir -pv ./docker/ruby-$(RUBY_VERSION)/ && \
39
+ echo '' > ./docker/ruby-$(RUBY_VERSION)/Gemfile.lock
40
+
41
+ ## Open shell in a docker container, supports CMD=
42
+ bash: build
43
+ $(MAKE) run CMD=bash
44
+
45
+ CMD ?= bash
46
+ ## Run command in a docker container, supports CMD=
47
+ run:
48
+ docker compose run --rm runner $(CMD)
49
+
50
+ ## Run tests in a docker container, supports ARGS=
51
+ test: build
52
+ $(MAKE) test-direct ARGS="$(ARGS)"
53
+
54
+ ## Run tests in a docker container without building, supports ARGS=
55
+ test-direct:
56
+ $(MAKE) run CMD="bundle exec rspec $(ARGS)"
57
+
58
+ ## Run rubocop in a docker container, supports ARGS=
59
+ lint: build
60
+ $(MAKE) lint-direct ARGS="$(ARGS)"
61
+
62
+ ## Run rubocop in a docker container without building, supports ARGS=
63
+ lint-direct:
64
+ $(MAKE) run CMD="bundle exec rake rubocop $(ARGS)"
65
+
66
+ ## Clean up docker compose resources
67
+ clean: clean-gemfile-lock
68
+ docker compose down --remove-orphans --volumes
69
+
70
+ ## Clean up the container specific Gemfile.lock
71
+ clean-gemfile-lock:
72
+ rm -v ./docker/ruby-$(RUBY_VERSION)/Gemfile.lock ||:
73
+
74
+ .PHONY: build bash test
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'aptible-tasks'
32
32
  spec.add_development_dependency 'bundler'
33
33
  spec.add_development_dependency 'pry'
34
- spec.add_development_dependency 'rake', '< 11.0'
35
- spec.add_development_dependency 'rspec', '~> 2.0'
36
- spec.add_development_dependency 'webmock', '~> 2.3.2'
34
+ spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
+ spec.add_development_dependency 'webmock', '~> 3.0'
37
37
  end
@@ -0,0 +1,12 @@
1
+ services:
2
+ runner:
3
+ build:
4
+ context: .
5
+ args:
6
+ RUBY_VERSION: ${RUBY_VERSION:-2.3.1}
7
+ BUNDLER_VERSION: ${BUNDLER_VERSION:-}
8
+ volumes:
9
+ - type: bind
10
+ source: .
11
+ target: /app
12
+ - ./docker/ruby-${RUBY_VERSION}/Gemfile.lock:/app/Gemfile.lock
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module Resource
3
- VERSION = '1.1.3'.freeze
3
+ VERSION = '1.1.4'.freeze
4
4
  end
5
5
  end
@@ -5,42 +5,38 @@ require 'spec_helper'
5
5
  describe Aptible::Resource::Base do
6
6
  let(:hyperresource_exception) { HyperResource::ResponseError.new('403') }
7
7
  let(:error_response) { double 'Faraday::Response' }
8
- before { hyperresource_exception.stub(:response) { error_response } }
8
+ let(:expected_root_url) { 'https://resource.example.com' }
9
9
  before do
10
- error_response.stub(:body) { { message: 'Forbidden' }.to_json }
11
- error_response.stub(:status) { 403 }
10
+ allow(hyperresource_exception).to receive(:response)
11
+ .and_return(error_response)
12
+ end
13
+ before do
14
+ allow(error_response).to receive(:body)
15
+ .and_return({ message: 'Forbidden' }.to_json)
16
+ allow(error_response).to receive(:status).and_return(403)
12
17
  end
13
18
 
14
19
  shared_context 'paginated collection' do
15
20
  let(:urls) { ['/mainframes', '/mainframes?page=1'] }
16
- let(:calls) { [] }
21
+ let(:expected_calls) do
22
+ urls.map { |u| [:get, "#{expected_root_url}#{u}"] }
23
+ end
24
+ let(:expected_record_ids) do
25
+ urls.map.with_index { |_, i| i + 1 }
26
+ end
17
27
 
18
28
  before do
19
- pages = {}
20
-
21
29
  urls.each_with_index do |url, idx|
22
- collection = double("Collection for #{url}")
23
- links = {}
24
-
25
- allow(collection).to receive(:entries).and_return(["At #{url}"])
26
- allow(collection).to receive(:links).and_return(links)
27
-
28
- next_url = urls[idx + 1]
29
- if next_url
30
- links['next'] = HyperResource::Link.new(nil, 'href' => next_url)
31
- end
32
-
33
- pages[url] = collection
34
- end
35
-
36
- [Api, Api::Mainframe].each do |klass|
37
- allow_any_instance_of(klass).to receive(:find_by_url) do |_, u, _|
38
- calls << u
39
- page = pages[u]
40
- raise "Accessed unexpected URL #{u}" if page.nil?
41
-
42
- page
43
- end
30
+ next_href = {}
31
+ next_href = { next: { href: urls[idx + 1] } } if urls[idx + 1]
32
+ stub_request(:get, "#{expected_root_url}#{url}")
33
+ .to_return(
34
+ body: {
35
+ _embedded: { mainframes: [{ id: idx + 1, _type: 'mainframe' }] },
36
+ _links: next_href
37
+ }.to_json,
38
+ status: 200
39
+ )
44
40
  end
45
41
  end
46
42
  end
@@ -54,6 +50,14 @@ describe Aptible::Resource::Base do
54
50
  end
55
51
  end
56
52
 
53
+ describe '.root_url' do
54
+ it 'should have a root_url with no trailing slash' do
55
+ the_url = Api.new.root_url
56
+ expect(the_url).not_to end_with('/')
57
+ expect(the_url).to eq(expected_root_url)
58
+ end
59
+ end
60
+
57
61
  describe '.find' do
58
62
  it 'should find' do
59
63
  stub_request(
@@ -89,9 +93,10 @@ describe Aptible::Resource::Base do
89
93
  let(:collection) { double 'Api' }
90
94
 
91
95
  before do
92
- collection.stub(:entries) { [mainframe] }
93
- collection.stub(:links) { {} }
94
- Api::Mainframe.any_instance.stub(:find_by_url) { collection }
96
+ allow(collection).to receive(:entries).and_return([mainframe])
97
+ allow(collection).to receive(:links).and_return({})
98
+ allow_any_instance_of(Api::Mainframe).to receive(:find_by_url)
99
+ .and_return(collection)
95
100
  end
96
101
 
97
102
  it 'should be an array' do
@@ -116,9 +121,12 @@ describe Aptible::Resource::Base do
116
121
  it 'should collect entries from all pages' do
117
122
  records = Api::Mainframe.all
118
123
  expect(records.size).to eq(2)
119
- expect(records.first).to eq('At /mainframes')
120
- expect(records.second).to eq('At /mainframes?page=1')
121
- expect(calls).to eq(urls)
124
+ expect(records).to all(be_a_kind_of(Api::Mainframe))
125
+ expect(records.first.id).to eq(1)
126
+ expect(records.second.id).to eq(2)
127
+ expected_calls.each do |args|
128
+ expect(WebMock).to have_requested(*args)
129
+ end
122
130
  end
123
131
 
124
132
  it "should return an empty list for a URL that doesn't exist" do
@@ -135,18 +143,25 @@ describe Aptible::Resource::Base do
135
143
  pages = 0
136
144
  Api::Mainframe.each_page { pages += 1 }
137
145
  expect(pages).to eq(2)
138
- expect(calls).to eq(urls)
146
+ expected_calls.each do |args|
147
+ expect(WebMock).to have_requested(*args)
148
+ end
139
149
  end
140
150
 
141
151
  it 'should find all records' do
142
- records = ['At /mainframes', 'At /mainframes?page=1']
143
- Api::Mainframe.each_page { |p| expect(p).to eq([records.shift]) }
144
- expect(calls).to eq(urls)
152
+ Api::Mainframe.each_page do |p|
153
+ expect(p).to all(be_a_kind_of(Api::Mainframe))
154
+ expect(p.map(&:id)).to eq([expected_record_ids.shift])
155
+ end
156
+ expected_calls.each do |args|
157
+ expect(WebMock).to have_requested(*args)
158
+ end
145
159
  end
146
160
 
147
161
  it 'should not access more URLs if the consumer breaks' do
148
162
  Api::Mainframe.each_page { break }
149
- expect(calls).to eq(['/mainframes'])
163
+ expect(WebMock).to have_requested(*expected_calls.first)
164
+ expect(WebMock).not_to have_requested(*expected_calls.second)
150
165
  end
151
166
 
152
167
  it 'should return an enum if no block is given' do
@@ -154,7 +169,9 @@ describe Aptible::Resource::Base do
154
169
  pages = 0
155
170
  e.each { pages += 1 }
156
171
  expect(pages).to eq(2)
157
- expect(calls).to eq(urls)
172
+ expected_calls.each do |args|
173
+ expect(WebMock).to have_requested(*args)
174
+ end
158
175
  end
159
176
  end
160
177
 
@@ -162,29 +179,34 @@ describe Aptible::Resource::Base do
162
179
  let(:mainframe) { Api::Mainframe.new }
163
180
  let(:mainframes_link) { HyperResource::Link.new(href: '/mainframes') }
164
181
 
165
- before { Api.any_instance.stub(:mainframes) { mainframes_link } }
166
- before { mainframes_link.stub(:create) { mainframe } }
182
+ before do
183
+ allow_any_instance_of(Api).to receive(:mainframes)
184
+ .and_return(mainframes_link)
185
+ end
186
+ before { allow(mainframes_link).to receive(:create).and_return(mainframe) }
167
187
 
168
188
  it 'should create a new top-level resource' do
169
- mainframes_link.stub(:create) { mainframe }
189
+ allow(mainframes_link).to receive(:create).and_return(mainframe)
170
190
  expect(mainframes_link).to receive(:create)
171
191
  Api::Mainframe.create(foo: 'bar')
172
192
  end
173
193
 
174
194
  it 'should populate #errors in the event of an error' do
175
- mainframes_link.stub(:create) { raise hyperresource_exception }
195
+ allow(mainframes_link).to receive(:create)
196
+ .and_raise(hyperresource_exception)
176
197
  mainframe = Api::Mainframe.create
177
198
  expect(mainframe.errors.messages).to eq(base: 'Forbidden')
178
199
  expect(mainframe.errors.full_messages).to eq(['Forbidden'])
179
200
  end
180
201
 
181
202
  it 'should return a Base-classed resource on error' do
182
- mainframes_link.stub(:create) { raise hyperresource_exception }
203
+ allow(mainframes_link).to receive(:create)
204
+ .and_raise(hyperresource_exception)
183
205
  expect(Api::Mainframe.create).to be_a Api::Mainframe
184
206
  end
185
207
 
186
208
  it 'should return the object in the event of successful creation' do
187
- mainframes_link.stub(:create) { mainframe }
209
+ allow(mainframes_link).to receive(:create).and_return(mainframe)
188
210
  expect(Api::Mainframe.create).to eq mainframe
189
211
  end
190
212
  end
@@ -193,18 +215,22 @@ describe Aptible::Resource::Base do
193
215
  let(:mainframe) { Api::Mainframe.new }
194
216
  let(:mainframes_link) { HyperResource::Link.new(href: '/mainframes') }
195
217
 
196
- before { Api.any_instance.stub(:mainframes) { mainframes_link } }
197
- before { mainframes_link.stub(:create) { mainframe } }
218
+ before do
219
+ allow_any_instance_of(Api).to receive(:mainframes)
220
+ .and_return(mainframes_link)
221
+ end
222
+ before { allow(mainframes_link).to receive(:create).and_return(mainframe) }
198
223
 
199
224
  it 'should pass through any exceptions' do
200
- mainframes_link.stub(:create) { raise hyperresource_exception }
225
+ allow(mainframes_link).to receive(:create)
226
+ .and_raise(hyperresource_exception)
201
227
  expect do
202
228
  Api::Mainframe.create!
203
229
  end.to raise_error HyperResource::ResponseError
204
230
  end
205
231
 
206
232
  it 'should return the object in the event of successful creation' do
207
- mainframes_link.stub(:create) { mainframe }
233
+ allow(mainframes_link).to receive(:create).and_return(mainframe)
208
234
  expect(Api::Mainframe.create!).to eq mainframe
209
235
  end
210
236
  end
@@ -222,20 +248,20 @@ describe Aptible::Resource::Base do
222
248
  describe '#bearer_token' do
223
249
  it 'should accept an Aptible::Resource::Token' do
224
250
  token = Api::Token.new
225
- token.stub(:access_token) { 'aptible_auth_token' }
226
- subject.stub(:token) { token }
251
+ allow(token).to receive(:access_token).and_return('aptible_auth_token')
252
+ allow(subject).to receive(:token).and_return(token)
227
253
  expect(subject.bearer_token).to eq token.access_token
228
254
  end
229
255
 
230
256
  it 'should accept a Fridge::AccessToken' do
231
257
  token = Fridge::AccessToken.new
232
- token.stub(:to_s) { 'fridge_access_token' }
233
- subject.stub(:token) { token }
258
+ allow(token).to receive(:to_s).and_return('fridge_access_token')
259
+ allow(subject).to receive(:token).and_return(token)
234
260
  expect(subject.bearer_token).to eq token.to_s
235
261
  end
236
262
 
237
263
  it 'should accept a String' do
238
- subject.stub(:token) { 'token' }
264
+ allow(subject).to receive(:token).and_return('token')
239
265
  expect(subject.bearer_token).to eq 'token'
240
266
  end
241
267
  end
@@ -250,26 +276,29 @@ describe Aptible::Resource::Base do
250
276
 
251
277
  describe '#update' do
252
278
  it 'should populate #errors in the event of an error' do
253
- HyperResource.any_instance.stub(:put) { raise hyperresource_exception }
279
+ allow_any_instance_of(HyperResource).to receive(:put)
280
+ .and_raise(hyperresource_exception)
254
281
  subject.update({})
255
282
  expect(subject.errors.messages).to eq(base: 'Forbidden')
256
283
  expect(subject.errors.full_messages).to eq(['Forbidden'])
257
284
  end
258
285
 
259
286
  it 'should return false in the event of an error' do
260
- HyperResource.any_instance.stub(:put) { raise hyperresource_exception }
287
+ allow_any_instance_of(HyperResource).to receive(:put)
288
+ .and_raise(hyperresource_exception)
261
289
  expect(subject.update({})).to eq false
262
290
  end
263
291
 
264
292
  it 'should return the object in the event of a successful update' do
265
- HyperResource.any_instance.stub(:put) { subject }
293
+ allow_any_instance_of(HyperResource).to receive(:put).and_return(subject)
266
294
  expect(subject.update({})).to eq subject
267
295
  end
268
296
  end
269
297
 
270
298
  describe '#update!' do
271
299
  it 'should populate #errors in the event of an error' do
272
- HyperResource.any_instance.stub(:put) { raise hyperresource_exception }
300
+ allow_any_instance_of(HyperResource).to receive(:put)
301
+ .and_raise(hyperresource_exception)
273
302
  begin
274
303
  subject.update!({})
275
304
  rescue StandardError
@@ -281,14 +310,15 @@ describe Aptible::Resource::Base do
281
310
  end
282
311
 
283
312
  it 'should pass through any exceptions' do
284
- HyperResource.any_instance.stub(:put) { raise hyperresource_exception }
313
+ allow_any_instance_of(HyperResource).to receive(:put)
314
+ .and_raise(hyperresource_exception)
285
315
  expect do
286
316
  subject.update!({})
287
317
  end.to raise_error HyperResource::ResponseError
288
318
  end
289
319
 
290
320
  it 'should return the object in the event of a successful update' do
291
- HyperResource.any_instance.stub(:put) { subject }
321
+ allow_any_instance_of(HyperResource).to receive(:put).and_return(subject)
292
322
  expect(subject.update!({})).to eq subject
293
323
  end
294
324
  end
@@ -309,50 +339,61 @@ describe Aptible::Resource::Base do
309
339
  let(:mainframe) { Api::Mainframe.new }
310
340
  let(:mainframes_link) { HyperResource::Link.new(href: '/mainframes') }
311
341
 
312
- before { subject.stub(:loaded) { true } }
313
- before { subject.stub(:links) { { mainframes: mainframes_link } } }
314
- before { mainframes_link.stub(:entries) { [mainframe] } }
315
- before { mainframes_link.stub(:base_href) { '/mainframes' } }
342
+ before { allow(subject).to receive(:loaded).and_return(true) }
343
+ before do
344
+ allow(subject).to receive(:links)
345
+ .and_return(mainframes: mainframes_link)
346
+ end
347
+ before do
348
+ allow(mainframes_link).to receive(:entries).and_return([mainframe])
349
+ end
350
+ before do
351
+ allow(mainframes_link).to receive(:base_href).and_return('/mainframes')
352
+ end
316
353
 
317
354
  describe '#create_#{relation}' do
318
355
  it 'should populate #errors in the event of an error' do
319
- mainframes_link.stub(:create) { raise hyperresource_exception }
356
+ allow(mainframes_link).to receive(:create)
357
+ .and_raise(hyperresource_exception)
320
358
  mainframe = subject.create_mainframe({})
321
359
  expect(mainframe.errors.messages).to eq(base: 'Forbidden')
322
360
  expect(mainframe.errors.full_messages).to eq(['Forbidden'])
323
361
  end
324
362
 
325
363
  it 'should return a Base-classed resource on error' do
326
- mainframes_link.stub(:create) { raise hyperresource_exception }
364
+ allow(mainframes_link).to receive(:create)
365
+ .and_raise(hyperresource_exception)
327
366
  expect(subject.create_mainframe.class).to eq Aptible::Resource::Base
328
367
  end
329
368
 
330
369
  it 'should have errors present on error' do
331
- mainframes_link.stub(:create) { raise hyperresource_exception }
370
+ allow(mainframes_link).to receive(:create)
371
+ .and_raise(hyperresource_exception)
332
372
  expect(subject.create_mainframe.errors.any?).to be true
333
373
  end
334
374
 
335
375
  it 'should return the object in the event of successful creation' do
336
- mainframes_link.stub(:create) { mainframe }
376
+ allow(mainframes_link).to receive(:create).and_return(mainframe)
337
377
  expect(subject.create_mainframe({})).to eq mainframe
338
378
  end
339
379
 
340
380
  it 'should have no errors on successful creation' do
341
- mainframes_link.stub(:create) { mainframe }
381
+ allow(mainframes_link).to receive(:create).and_return(mainframe)
342
382
  expect(subject.create_mainframe.errors.any?).to be false
343
383
  end
344
384
  end
345
385
 
346
386
  describe '#create_#{relation}!' do
347
387
  it 'should pass through any exceptions' do
348
- mainframes_link.stub(:create) { raise hyperresource_exception }
388
+ allow(mainframes_link).to receive(:create)
389
+ .and_raise(hyperresource_exception)
349
390
  expect do
350
391
  subject.create_mainframe!({})
351
392
  end.to raise_error HyperResource::ResponseError
352
393
  end
353
394
 
354
395
  it 'should return the object in the event of successful creation' do
355
- mainframes_link.stub(:create) { mainframe }
396
+ allow(mainframes_link).to receive(:create).and_return(mainframe)
356
397
  expect(subject.create_mainframe!({})).to eq mainframe
357
398
  end
358
399
  end
@@ -362,11 +403,13 @@ describe Aptible::Resource::Base do
362
403
 
363
404
  it 'should return all records' do
364
405
  records = subject.mainframes
365
-
366
406
  expect(records.size).to eq(2)
367
- expect(records.first).to eq('At /mainframes')
368
- expect(records.second).to eq('At /mainframes?page=1')
369
- expect(calls).to eq(urls)
407
+ expect(records).to all(be_a_kind_of(Api::Mainframe))
408
+ expect(records.first.id).to eq(1)
409
+ expect(records.second.id).to eq(2)
410
+ expected_calls.each do |args|
411
+ expect(WebMock).to have_requested(*args)
412
+ end
370
413
  end
371
414
  end
372
415
 
@@ -375,17 +418,20 @@ describe Aptible::Resource::Base do
375
418
 
376
419
  it 'should iterate over all records' do
377
420
  records = []
378
- subject.each_mainframe { |mainframe| records << mainframe }
379
-
421
+ subject.each_mainframe { |m| records << m }
380
422
  expect(records.size).to eq(2)
381
- expect(records.first).to eq('At /mainframes')
382
- expect(records.second).to eq('At /mainframes?page=1')
383
- expect(calls).to eq(urls)
423
+ expect(records).to all(be_a_kind_of(Api::Mainframe))
424
+ expect(records.first.id).to eq(1)
425
+ expect(records.second.id).to eq(2)
426
+ expected_calls.each do |args|
427
+ expect(WebMock).to have_requested(*args)
428
+ end
384
429
  end
385
430
 
386
431
  it 'should stop iterating when the consumer breaks' do
387
432
  subject.each_mainframe { |_| break }
388
- expect(calls).to eq([urls[0]])
433
+ expect(WebMock).to have_requested(*expected_calls.first)
434
+ expect(WebMock).not_to have_requested(*expected_calls.second)
389
435
  end
390
436
 
391
437
  it 'should return an enum if no block is given' do
@@ -393,7 +439,10 @@ describe Aptible::Resource::Base do
393
439
  records = []
394
440
  e.each { |m| records << m }
395
441
  expect(records.size).to eq(2)
396
- expect(calls).to eq(urls)
442
+ expect(records).to all(be_a_kind_of(Api::Mainframe))
443
+ expected_calls.each do |args|
444
+ expect(WebMock).to have_requested(*args)
445
+ end
397
446
  end
398
447
  end
399
448
  end
@@ -402,10 +451,13 @@ describe Aptible::Resource::Base do
402
451
  let(:m1) { Api::Mainframe.new }
403
452
  let(:m2) { Api::Mainframe.new }
404
453
 
405
- before { subject.stub(:loaded) { true } }
406
- before { subject.stub(:objects) { { embedded_mainframes: [m1, m2] } } }
407
- before { m1.stub(id: 1) }
408
- before { m2.stub(id: 2) }
454
+ before { allow(subject).to receive(:loaded).and_return(true) }
455
+ before do
456
+ allow(subject).to receive(:objects)
457
+ .and_return(embedded_mainframes: [m1, m2])
458
+ end
459
+ before { allow(m1).to receive(:id).and_return(1) }
460
+ before { allow(m2).to receive(:id).and_return(2) }
409
461
 
410
462
  describe '#{relation}s' do
411
463
  it 'should return all records' do
@@ -447,25 +499,27 @@ describe Aptible::Resource::Base do
447
499
 
448
500
  it 'should return the raw attribute' do
449
501
  Api.field :foo, type: String
450
- subject.stub(:attributes) { { foo: 'bar' } }
502
+ allow(subject).to receive(:attributes).and_return(foo: 'bar')
451
503
  expect(subject.foo).to eq 'bar'
452
504
  end
453
505
 
454
506
  it 'should parse the attribute if DateTime' do
455
507
  Api.field :created_at, type: DateTime
456
- subject.stub(:attributes) { { created_at: Time.now.to_json } }
508
+ allow(subject).to receive(:attributes)
509
+ .and_return(created_at: Time.now.to_json)
457
510
  expect(subject.created_at).to be_a DateTime
458
511
  end
459
512
 
460
513
  it 'should parse the attribute if Time' do
461
514
  Api.field :created_at, type: Time
462
- subject.stub(:attributes) { { created_at: Time.now.to_json } }
515
+ allow(subject).to receive(:attributes)
516
+ .and_return(created_at: Time.now.to_json)
463
517
  expect(subject.created_at).to be_a Time
464
518
  end
465
519
 
466
520
  it 'should add a ? helper if Boolean' do
467
521
  Api.field :awesome, type: Aptible::Resource::Boolean
468
- subject.stub(:attributes) { { awesome: 'true' } }
522
+ allow(subject).to receive(:attributes).and_return(awesome: 'true')
469
523
  expect(subject.awesome?).to be true
470
524
  end
471
525
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-05 00:00:00.000000000 Z
11
+ date: 2025-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -140,44 +140,44 @@ dependencies:
140
140
  name: rake
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "<"
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: '11.0'
145
+ version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "<"
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: '11.0'
152
+ version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rspec
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '2.0'
159
+ version: '3.0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '2.0'
166
+ version: '3.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: webmock
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 2.3.2
173
+ version: '3.0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: 2.3.2
180
+ version: '3.0'
181
181
  description: Foundation classes for Aptible resource server gems
182
182
  email:
183
183
  - frank@macreery.com
@@ -186,16 +186,20 @@ extensions: []
186
186
  extra_rdoc_files: []
187
187
  files:
188
188
  - ".github/CODEOWNERS"
189
+ - ".github/workflows/release.yml"
189
190
  - ".github/workflows/test.yml"
190
191
  - ".gitignore"
191
192
  - ".rspec"
192
193
  - ".rubocop.yml"
194
+ - Dockerfile
193
195
  - Gemfile
194
196
  - LICENSE.md
197
+ - Makefile
195
198
  - README.md
196
199
  - Rakefile
197
200
  - SECURITY.md
198
201
  - aptible-resource.gemspec
202
+ - docker-compose.yml
199
203
  - lib/aptible/resource.rb
200
204
  - lib/aptible/resource/adapter.rb
201
205
  - lib/aptible/resource/base.rb
@@ -228,7 +232,7 @@ homepage: https://github.com/aptible/aptible-resource
228
232
  licenses:
229
233
  - MIT
230
234
  metadata: {}
231
- post_install_message:
235
+ post_install_message:
232
236
  rdoc_options: []
233
237
  require_paths:
234
238
  - lib
@@ -243,8 +247,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
247
  - !ruby/object:Gem::Version
244
248
  version: '0'
245
249
  requirements: []
246
- rubygems_version: 3.0.3.1
247
- signing_key:
250
+ rubygems_version: 3.5.22
251
+ signing_key:
248
252
  specification_version: 4
249
253
  summary: Foundation classes for Aptible resource server gems
250
254
  test_files: