aptible-resource 0.2.9 → 0.3.0

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
  SHA1:
3
- metadata.gz: 6b75c4be6dcc1be4c4a775c7e3ace1a8562f0b53
4
- data.tar.gz: 8bc0c54ee27b05a8da04d051bda0cf799384e528
3
+ metadata.gz: 00d2a4af5d237bbb3f2ed2133240fa087d40fc31
4
+ data.tar.gz: a2cb0cc2cb94cdb8dafc5c27123a8dce0714d4dc
5
5
  SHA512:
6
- metadata.gz: 3d4df6aca5956b848888ef2dc6729c2e46fda753dddea061b522880167a0dcb834196c3e1f4920a87efb5babec7b856a52d032eb6fbef237daf64fa8a570006a
7
- data.tar.gz: 8b74e1da4365cf6148db8f02f0ddb4388067c2a4e5309d329f8588095e16d418e6816f075328ef5020bd82c6f3c59bb50660ebd4aebd8d11ad0dc6e56895f08e
6
+ metadata.gz: 7d49416b1b045515b6d09de321582df201f66d9c5418e58ed1816d626635d0619c5c3ba6689e41c00f99061f09c5caf50bb3ffb5184bb8e98864c78cdb6932b7
7
+ data.tar.gz: ef29aede6cd4afabdb434a7ece2bcd006391a19640838410f4afe4fc59e9449d6e17d05bc12287ac7ff262bc730f3c80464e68f00b0f2f3a24806402c103f9fb
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.license = 'MIT'
17
17
 
18
18
  spec.files = `git ls-files`.split($RS)
19
- spec.test_files = spec.files.grep(/^spec\//)
19
+ spec.test_files = spec.files.grep(%r{^spec\/})
20
20
  spec.require_paths = ['lib']
21
21
 
22
22
  # HyperResource dependencies
@@ -35,11 +35,18 @@ module Aptible
35
35
  name.split('::').last.underscore.pluralize
36
36
  end
37
37
 
38
+ # rubocop:disable AbcSize
38
39
  def self.all(options = {})
39
- resource = find_by_url(collection_href, options)
40
+ resource = find_by_url(options[:href] || collection_href, options)
40
41
  return [] unless resource
41
- resource.send(basename).entries
42
+ if resource.links.key?('next')
43
+ options[:href] = resource.links['next'].href
44
+ resource.send(basename).entries + all(options)
45
+ else
46
+ resource.send(basename).entries
47
+ end
42
48
  end
49
+ # rubocop: enable AbcSize
43
50
 
44
51
  def self.where(options = {})
45
52
  params = options.except(:token, :root, :namespace, :headers)
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module Resource
3
- VERSION = '0.2.9'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -32,6 +32,7 @@ describe Aptible::Resource::Base do
32
32
 
33
33
  before do
34
34
  collection.stub(:mainframes) { [mainframe] }
35
+ collection.stub(:links) { Hash.new }
35
36
  Api::Mainframe.any_instance.stub(:find_by_url) { collection }
36
37
  end
37
38
 
@@ -49,6 +50,22 @@ describe Aptible::Resource::Base do
49
50
  expect(klass).to receive(:new).with(options).and_return klass.new
50
51
  Api::Mainframe.all(options)
51
52
  end
53
+
54
+ describe 'when paginated' do
55
+ before do
56
+ page = double('page')
57
+ allow(page).to receive(:href).and_return(
58
+ '/next/page', '/next/page', '/next/page'
59
+ )
60
+ allow(collection).to receive(:links).and_return(
61
+ { 'next' => page }, { 'next' => page }, {}
62
+ )
63
+ end
64
+
65
+ it 'should collect entries on all pages' do
66
+ expect(Api::Mainframe.all).to eq [mainframe] + [mainframe]
67
+ end
68
+ end
52
69
  end
53
70
 
54
71
  describe '.create' do
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: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-04 00:00:00.000000000 Z
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uri_template