droplet_kit 2.8.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +4 -1
  3. data/lib/droplet_kit/mappings/cdn_mapping.rb +6 -0
  4. data/lib/droplet_kit/mappings/load_balancer_mapping.rb +1 -0
  5. data/lib/droplet_kit/models/cdn.rb +2 -0
  6. data/lib/droplet_kit/models/load_balancer.rb +1 -0
  7. data/lib/droplet_kit/resources/cdn_resource.rb +6 -0
  8. data/lib/droplet_kit/version.rb +1 -1
  9. metadata +4 -289
  10. data/.gitignore +0 -23
  11. data/.rspec +0 -2
  12. data/.travis.yml +0 -28
  13. data/CHANGELOG.md +0 -106
  14. data/Gemfile +0 -15
  15. data/Rakefile +0 -3
  16. data/droplet_kit.gemspec +0 -37
  17. data/spec/fixtures/account/info.json +0 -8
  18. data/spec/fixtures/actions/all.json +0 -24
  19. data/spec/fixtures/actions/find.json +0 -19
  20. data/spec/fixtures/cdns/all.json +0 -16
  21. data/spec/fixtures/cdns/create.json +0 -9
  22. data/spec/fixtures/cdns/find.json +0 -9
  23. data/spec/fixtures/cdns/update_ttl.json +0 -9
  24. data/spec/fixtures/certificates/all.json +0 -19
  25. data/spec/fixtures/certificates/find.json +0 -12
  26. data/spec/fixtures/certificates/lets_encrypt.json +0 -12
  27. data/spec/fixtures/domain_records/all.json +0 -57
  28. data/spec/fixtures/domain_records/create.json +0 -12
  29. data/spec/fixtures/domain_records/find.json +0 -12
  30. data/spec/fixtures/domain_records/update.json +0 -12
  31. data/spec/fixtures/domains/all.json +0 -12
  32. data/spec/fixtures/domains/create.json +0 -7
  33. data/spec/fixtures/domains/find.json +0 -7
  34. data/spec/fixtures/droplet_actions/change_kernel.json +0 -27
  35. data/spec/fixtures/droplet_actions/disable_backups.json +0 -27
  36. data/spec/fixtures/droplet_actions/enable_backups.json +0 -27
  37. data/spec/fixtures/droplet_actions/enable_ipv6.json +0 -27
  38. data/spec/fixtures/droplet_actions/enable_private_networking.json +0 -27
  39. data/spec/fixtures/droplet_actions/find.json +0 -19
  40. data/spec/fixtures/droplet_actions/password_reset.json +0 -27
  41. data/spec/fixtures/droplet_actions/power_cycle.json +0 -27
  42. data/spec/fixtures/droplet_actions/power_off.json +0 -27
  43. data/spec/fixtures/droplet_actions/power_on.json +0 -27
  44. data/spec/fixtures/droplet_actions/reboot.json +0 -27
  45. data/spec/fixtures/droplet_actions/rebuild.json +0 -27
  46. data/spec/fixtures/droplet_actions/rename.json +0 -27
  47. data/spec/fixtures/droplet_actions/resize.json +0 -27
  48. data/spec/fixtures/droplet_actions/restore.json +0 -27
  49. data/spec/fixtures/droplet_actions/shutdown.json +0 -27
  50. data/spec/fixtures/droplet_actions/snapshot.json +0 -27
  51. data/spec/fixtures/droplet_actions/upgrade.json +0 -27
  52. data/spec/fixtures/droplet_upgrades/all.json +0 -7
  53. data/spec/fixtures/droplets/all.json +0 -89
  54. data/spec/fixtures/droplets/all_empty.json +0 -7
  55. data/spec/fixtures/droplets/create.json +0 -84
  56. data/spec/fixtures/droplets/create_multiple.json +0 -168
  57. data/spec/fixtures/droplets/find.json +0 -84
  58. data/spec/fixtures/droplets/list_actions.json +0 -24
  59. data/spec/fixtures/droplets/list_backups.json +0 -18
  60. data/spec/fixtures/droplets/list_kernels.json +0 -17
  61. data/spec/fixtures/droplets/list_snapshots.json +0 -18
  62. data/spec/fixtures/firewalls/all.json +0 -67
  63. data/spec/fixtures/firewalls/find.json +0 -61
  64. data/spec/fixtures/floating_ip_actions/all.json +0 -41
  65. data/spec/fixtures/floating_ip_actions/assign.json +0 -27
  66. data/spec/fixtures/floating_ip_actions/find.json +0 -19
  67. data/spec/fixtures/floating_ip_actions/unassign.json +0 -27
  68. data/spec/fixtures/floating_ips/all.json +0 -186
  69. data/spec/fixtures/floating_ips/all_empty.json +0 -7
  70. data/spec/fixtures/floating_ips/create.json +0 -29
  71. data/spec/fixtures/floating_ips/create_with_droplet.json +0 -44
  72. data/spec/fixtures/floating_ips/find.json +0 -28
  73. data/spec/fixtures/image_actions/all.json +0 -36
  74. data/spec/fixtures/image_actions/convert.json +0 -27
  75. data/spec/fixtures/image_actions/find.json +0 -19
  76. data/spec/fixtures/image_actions/transfer.json +0 -27
  77. data/spec/fixtures/images/all.json +0 -31
  78. data/spec/fixtures/images/find.json +0 -16
  79. data/spec/fixtures/images/private.json +0 -31
  80. data/spec/fixtures/images/type.json +0 -31
  81. data/spec/fixtures/kubernetes/all.json +0 -70
  82. data/spec/fixtures/kubernetes/all_empty.json +0 -7
  83. data/spec/fixtures/kubernetes/cluster_node_pool.json +0 -24
  84. data/spec/fixtures/kubernetes/cluster_node_pool_create.json +0 -40
  85. data/spec/fixtures/kubernetes/cluster_node_pool_update.json +0 -31
  86. data/spec/fixtures/kubernetes/cluster_node_pools.json +0 -33
  87. data/spec/fixtures/kubernetes/clusters/create.json +0 -65
  88. data/spec/fixtures/kubernetes/clusters/find.json +0 -65
  89. data/spec/fixtures/kubernetes/clusters/kubeconfig.txt +0 -20
  90. data/spec/fixtures/kubernetes/clusters/update.json +0 -63
  91. data/spec/fixtures/kubernetes/options.json +0 -150
  92. data/spec/fixtures/load_balancers/all.json +0 -129
  93. data/spec/fixtures/load_balancers/find.json +0 -59
  94. data/spec/fixtures/projects/all.json +0 -37
  95. data/spec/fixtures/projects/all_empty.json +0 -12
  96. data/spec/fixtures/projects/find.json +0 -14
  97. data/spec/fixtures/projects/resources.json +0 -84
  98. data/spec/fixtures/regions/all.json +0 -47
  99. data/spec/fixtures/sizes/all.json +0 -37
  100. data/spec/fixtures/snapshots/all.json +0 -32
  101. data/spec/fixtures/snapshots/find.json +0 -14
  102. data/spec/fixtures/snapshots/resource_type.json +0 -20
  103. data/spec/fixtures/ssh_keys/all.json +0 -13
  104. data/spec/fixtures/ssh_keys/create.json +0 -8
  105. data/spec/fixtures/ssh_keys/find.json +0 -8
  106. data/spec/fixtures/ssh_keys/update.json +0 -8
  107. data/spec/fixtures/tags/all.json +0 -34
  108. data/spec/fixtures/tags/all_empty.json +0 -7
  109. data/spec/fixtures/tags/create.json +0 -15
  110. data/spec/fixtures/tags/find.json +0 -99
  111. data/spec/fixtures/volume_actions/all.json +0 -41
  112. data/spec/fixtures/volume_actions/attach.json +0 -34
  113. data/spec/fixtures/volume_actions/detach.json +0 -34
  114. data/spec/fixtures/volume_actions/find.json +0 -34
  115. data/spec/fixtures/volume_actions/resize.json +0 -34
  116. data/spec/fixtures/volumes/all.json +0 -41
  117. data/spec/fixtures/volumes/create.json +0 -34
  118. data/spec/fixtures/volumes/create_snapshot.json +0 -14
  119. data/spec/fixtures/volumes/find.json +0 -34
  120. data/spec/lib/droplet_kit/client_spec.rb +0 -102
  121. data/spec/lib/droplet_kit/models/base_model_spec.rb +0 -21
  122. data/spec/lib/droplet_kit/models/droplet_spec.rb +0 -32
  123. data/spec/lib/droplet_kit/paginated_resource_spec.rb +0 -85
  124. data/spec/lib/droplet_kit/resources/account_resource_spec.rb +0 -30
  125. data/spec/lib/droplet_kit/resources/action_resource_spec.rb +0 -83
  126. data/spec/lib/droplet_kit/resources/cdn_resource_spec.rb +0 -124
  127. data/spec/lib/droplet_kit/resources/certificate_resource_spec.rb +0 -119
  128. data/spec/lib/droplet_kit/resources/domain_record_resource_spec.rb +0 -99
  129. data/spec/lib/droplet_kit/resources/domain_resource_spec.rb +0 -65
  130. data/spec/lib/droplet_kit/resources/droplet_action_resource_spec.rb +0 -223
  131. data/spec/lib/droplet_kit/resources/droplet_resource_spec.rb +0 -340
  132. data/spec/lib/droplet_kit/resources/droplet_upgrade_resource_spec.rb +0 -22
  133. data/spec/lib/droplet_kit/resources/firewall_resource_spec.rb +0 -265
  134. data/spec/lib/droplet_kit/resources/floating_ip_action_resource_spec.rb +0 -137
  135. data/spec/lib/droplet_kit/resources/floating_ip_resource_spec.rb +0 -91
  136. data/spec/lib/droplet_kit/resources/image_action_resource_spec.rb +0 -149
  137. data/spec/lib/droplet_kit/resources/image_resource_spec.rb +0 -93
  138. data/spec/lib/droplet_kit/resources/kubernetes_cluster_resource_spec.rb +0 -313
  139. data/spec/lib/droplet_kit/resources/kubernetes_options_resource_spec.rb +0 -33
  140. data/spec/lib/droplet_kit/resources/load_balancer_resource_spec.rb +0 -213
  141. data/spec/lib/droplet_kit/resources/project_resource_spec.rb +0 -126
  142. data/spec/lib/droplet_kit/resources/region_resource_spec.rb +0 -27
  143. data/spec/lib/droplet_kit/resources/size_resource_spec.rb +0 -27
  144. data/spec/lib/droplet_kit/resources/snapshot_resource_spec.rb +0 -61
  145. data/spec/lib/droplet_kit/resources/ssh_key_resource_spec.rb +0 -92
  146. data/spec/lib/droplet_kit/resources/tag_resource_spec.rb +0 -135
  147. data/spec/lib/droplet_kit/resources/volume_action_resource_spec.rb +0 -157
  148. data/spec/lib/droplet_kit/resources/volume_resource_spec.rb +0 -124
  149. data/spec/spec_helper.rb +0 -19
  150. data/spec/support/fake_server.rb +0 -4
  151. data/spec/support/request_stub_helpers.rb +0 -28
  152. data/spec/support/resource_context.rb +0 -4
  153. data/spec/support/shared_examples/common_errors.rb +0 -27
  154. data/spec/support/shared_examples/paginated_endpoint.rb +0 -16
  155. data/spec/support/shared_examples/unprocessable_entity.rb +0 -11
@@ -1,157 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::VolumeActionResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- RSpec::Matchers.define :match_volume_action_fixture do |type|
8
- match do |action|
9
- expect(action).to be_kind_of(DropletKit::Action)
10
- expect(action.id).to eq(72531856)
11
- expect(action.status).to eq("in-progress")
12
- expect(action.type).to eq(type) if type
13
- expect(action.started_at).to eq("2015-11-12T17:51:03Z")
14
- expect(action.completed_at).to eq(nil)
15
- expect(action.resource_id).to eq(nil)
16
- expect(action.resource_type).to eq("volume")
17
- expect(action.region_slug).to eq("nyc1")
18
-
19
- expect(action.region).to be_kind_of(DropletKit::Region)
20
- end
21
- end
22
-
23
- describe '#attach' do
24
- let(:volume_id) { '7724db7c-e098-11e5-b522-000f53304e51' }
25
- let(:droplet_id) { 123 }
26
- let(:region) { 'nyc1' }
27
- let(:path) { "/v2/volumes/#{volume_id}/actions" }
28
- let(:action) { 'attach' }
29
- let(:fixture) { api_fixture("volume_actions/#{action}") }
30
-
31
- it 'sends an attach request for a volume' do
32
- request = stub_do_api(path).with(
33
- body: {
34
- type: action,
35
- droplet_id: droplet_id,
36
- volume_id: volume_id,
37
- region: region
38
- }.to_json
39
- ).to_return(body: fixture, status: 201)
40
-
41
- action = resource.attach(
42
- volume_id: volume_id,
43
- droplet_id: droplet_id,
44
- region: region
45
- )
46
-
47
- expect(request).to have_been_made
48
- expect(action).to match_volume_action_fixture('attach_volume')
49
- end
50
-
51
- it_behaves_like 'an action that handles invalid parameters' do
52
- let(:arguments) { { volume_id: volume_id, droplet_id: droplet_id } }
53
- end
54
- end
55
-
56
- describe '#detach' do
57
- let(:volume_id) { '7724db7c-e098-11e5-b522-000f53304e51' }
58
- let(:droplet_id) { 123 }
59
- let(:region) { 'nyc1' }
60
- let(:path) { "/v2/volumes/#{volume_id}/actions" }
61
- let(:action) { 'detach' }
62
- let(:fixture) { api_fixture("volume_actions/#{action}") }
63
-
64
- it 'sends an detach request for a volume' do
65
- request = stub_do_api(path).with(
66
- body: {
67
- type: action,
68
- droplet_id: droplet_id,
69
- volume_id: volume_id,
70
- region: region
71
- }.to_json
72
- ).to_return(body: fixture, status: 201)
73
-
74
- action = resource.detach(
75
- volume_id: volume_id,
76
- droplet_id: droplet_id,
77
- region: region
78
- )
79
-
80
- expect(request).to have_been_made
81
- expect(action).to match_volume_action_fixture('detach_volume')
82
- end
83
-
84
- it_behaves_like 'an action that handles invalid parameters' do
85
- let(:arguments) { { volume_id: volume_id } }
86
- end
87
- end
88
-
89
- describe '#resize' do
90
- let(:volume_id) { '7724db7c-e098-11e5-b522-000f53304e51' }
91
- let(:region) { 'nyc1' }
92
- let(:path) { "/v2/volumes/#{volume_id}/actions" }
93
- let(:action) { 'resize' }
94
- let(:fixture) { api_fixture("volume_actions/#{action}") }
95
-
96
- it 'sends an resize request for a volume' do
97
- request = stub_do_api(path).with(
98
- body: {
99
- type: action,
100
- size_gigabytes: 100,
101
- region: region
102
- }.to_json
103
- ).to_return(body: fixture, status: 201)
104
-
105
- action = resource.resize(
106
- volume_id: volume_id,
107
- region: region,
108
- size_gigabytes: 100
109
- )
110
-
111
- expect(request).to have_been_made
112
- expect(action).to match_volume_action_fixture('resize_volume')
113
- end
114
-
115
- it_behaves_like 'an action that handles invalid parameters' do
116
- let(:arguments) { { volume_id: volume_id } }
117
- end
118
- end
119
-
120
- describe '#all' do
121
- let(:volume_id) { '7724db7c-e098-11e5-b522-000f53304e51' }
122
-
123
- it 'returns all of the volume actions via a paginated resources' do
124
- request = stub_do_api("/v2/volumes/#{volume_id}/actions", :get).to_return(
125
- body: api_fixture('volume_actions/all'),
126
- status: 200
127
- )
128
-
129
- actions = resource.all(volume_id: volume_id).take(20)
130
-
131
- expect(request).to have_been_made
132
-
133
- expect(actions.size).to be(1)
134
-
135
- action = actions.first
136
- expect(action).to match_volume_action_fixture
137
- end
138
-
139
- it_behaves_like 'a paginated index' do
140
- let(:fixture_path) { 'volume_actions/all' }
141
- let(:api_path) { "/v2/volumes/#{volume_id}/actions" }
142
- let(:parameters) { { volume_id: volume_id } }
143
- end
144
- end
145
-
146
- describe '#find' do
147
- let(:id) { 72531856 }
148
- let(:volume_id) { '7724db7c-e098-11e5-b522-000f53304e51' }
149
-
150
- it 'returns a single action' do
151
- stub_do_api("/v2/volumes/#{volume_id}/actions/#{id}", :get).to_return(body: api_fixture('volume_actions/find'))
152
- action = resource.find(id: id, volume_id: volume_id)
153
-
154
- expect(action).to match_volume_action_fixture
155
- end
156
- end
157
- end
@@ -1,124 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::VolumeResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- RSpec::Matchers.define :match_volume_fixture do
8
- match do |volume|
9
- expect(volume).to be_kind_of(DropletKit::Volume)
10
-
11
- expect(volume.region).to be_kind_of(DropletKit::Region)
12
- expect(volume.id).to eq("7724db7c-e098-11e5-b522-000f53304e51")
13
- expect(volume.droplet_ids).to eq([])
14
- expect(volume.name).to eq("Example")
15
- expect(volume.description).to eq("Block store for examples")
16
- expect(volume.size_gigabytes).to eq(10)
17
- expect(volume.created_at).to eq("2016-03-02T17:00:49Z")
18
- end
19
- end
20
-
21
- describe '#all' do
22
- it 'returns all of the volumes' do
23
- stub_do_api('/v2/volumes', :get).to_return(body: api_fixture('volumes/all'))
24
- volumes = resource.all
25
-
26
- expect(volumes).to all(be_kind_of(DropletKit::Volume))
27
- expect(volumes.first).to match_volume_fixture
28
- end
29
-
30
- it_behaves_like 'a paginated index' do
31
- let(:fixture_path) { 'volumes/all' }
32
- let(:api_path) { '/v2/volumes' }
33
- end
34
- end
35
-
36
- describe '#find' do
37
- it 'returns a singular volume' do
38
- stub_do_api('/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51', :get).to_return(body: api_fixture('volumes/find'))
39
- volume = resource.find(id: "7724db7c-e098-11e5-b522-000f53304e51")
40
-
41
- expect(volume).to match_volume_fixture
42
- end
43
- end
44
-
45
- describe '#create' do
46
- let(:path) { '/v2/volumes' }
47
-
48
- context 'for a successful create' do
49
- it 'returns the created volume' do
50
- volume = DropletKit::Volume.new(
51
- size_gigabytes: 10,
52
- name: "Example",
53
- description: "Block store for examples",
54
- region: "nyc1"
55
- )
56
-
57
- as_string = DropletKit::VolumeMapping.representation_for(:create, volume)
58
- stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('volumes/create'), status: 201)
59
- created_volume = resource.create(volume)
60
-
61
- expect(created_volume).to match_volume_fixture
62
- end
63
- end
64
-
65
- context 'with a snapshot id' do
66
- it 'returns the created volume' do
67
- volume = DropletKit::Volume.new(
68
- size_gigabytes: 10,
69
- name: "Example",
70
- description: "Block store for examples",
71
- snapshot_id: "7724db7c-e098-11e5-b522-000f53304e51"
72
- )
73
-
74
- as_string = DropletKit::VolumeMapping.representation_for(:create, volume)
75
- stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('volumes/create'), status: 201)
76
- created_volume = resource.create(volume)
77
-
78
- expect(created_volume).to match_volume_fixture
79
- end
80
- end
81
-
82
- it_behaves_like 'an action that handles invalid parameters' do
83
- let(:action) { 'create' }
84
- let(:arguments) { DropletKit::Volume.new }
85
- end
86
- end
87
-
88
- describe '#create_snapshot' do
89
- let(:id) { '7724db7c-e098-11e5-b522-000f53304e51' }
90
- let(:path) { "/v2/volumes/#{id}/snapshot" }
91
-
92
- context 'for a successful create' do
93
- it 'returns the created volume' do
94
- as_string = { name: 'foo' }.to_json
95
- stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('volumes/create_snapshot'), status: 201)
96
- created_snapshot = resource.create_snapshot(id: id, name: 'foo')
97
-
98
- expect(created_snapshot).to be_kind_of(DropletKit::Snapshot)
99
-
100
- expect(created_snapshot.id).to eq("7724db7c-e098-11e5-b522-000f53304e51")
101
- expect(created_snapshot.name).to eq("Ubuntu Foo")
102
- expect(created_snapshot.regions).to eq(["nyc1"])
103
- expect(created_snapshot.resource_type).to eq("volume")
104
- expect(created_snapshot.resource_id).to eq("7724db7c-e098-11e5-b522-000f53304e51")
105
- expect(created_snapshot.min_disk_size).to eq(10)
106
- expect(created_snapshot.size_gigabytes).to eq(0.4)
107
- end
108
- end
109
-
110
- it_behaves_like 'an action that handles invalid parameters' do
111
- let(:action) { 'create_snapshot' }
112
- let(:arguments) { { id: id } }
113
- end
114
- end
115
-
116
- describe '#delete' do
117
- it 'sends a delete request for the volume' do
118
- request = stub_do_api('/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51', :delete)
119
- resource.delete(id: "7724db7c-e098-11e5-b522-000f53304e51")
120
-
121
- expect(request).to have_been_made
122
- end
123
- end
124
- end
@@ -1,19 +0,0 @@
1
- require 'simplecov'
2
-
3
- SimpleCov.start
4
-
5
- require 'faraday'
6
- require 'addressable/uri'
7
- require 'droplet_kit'
8
- require 'webmock/rspec'
9
-
10
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(SimpleCov::Formatter::HTMLFormatter)
11
-
12
- Dir['./spec/support/**/*.rb'].each do |file|
13
- require file
14
- end
15
-
16
- RSpec.configure do |config|
17
- config.order = :random
18
- config.include RequestStubHelpers
19
- end
@@ -1,4 +0,0 @@
1
- require 'sinatra/base'
2
-
3
- class FakeServer < Sinatra::Base
4
- end
@@ -1,28 +0,0 @@
1
- module RequestStubHelpers
2
- def stub_do_api(path, verb = :any)
3
- stub_request(verb, %r[#{DropletKit::Client::DIGITALOCEAN_API}#{Regexp.escape(path)}])
4
- end
5
-
6
- def api_fixture(fixture_name)
7
- Pathname.new('./spec/fixtures/').join("#{fixture_name}.json").read
8
- end
9
-
10
- def stub_pager_request(total_results = 40)
11
- Faraday::Adapter::Test::Stubs.new do |stub|
12
- stub.get('/droplets') do |env|
13
- request_count.count += 1
14
- uri = Addressable::URI.parse(env[:url].to_s)
15
- page = (uri.query_values['page'] || 1).to_i
16
- per_page = (uri.query_values['per_page'] || 20).to_i
17
-
18
- max_elems = [total_results, per_page].min
19
-
20
- range = (0...max_elems).map do |num|
21
- num + ((page - 1) * per_page)
22
- end
23
-
24
- [200, {}, { objects: range, meta: { total: total_results } }.to_json ]
25
- end
26
- end
27
- end
28
- end
@@ -1,4 +0,0 @@
1
- shared_context 'resources' do
2
- let(:client) { DropletKit::Client.new(access_token: 'bunk-token') }
3
- let(:connection) { client.connection }
4
- end
@@ -1,27 +0,0 @@
1
- shared_examples_for 'resource that handles common errors' do
2
- let(:arguments) { {} }
3
-
4
- it 'handles rate limit' do
5
- response_body = { id: :rate_limit, message: 'Too much!!!' }
6
- stub_do_api(path, method).to_return(body: response_body.to_json, status: 429, headers: {
7
- 'RateLimit-Limit' => 1200,
8
- 'RateLimit-Remaining' => 1193,
9
- 'RateLimit-Reset' => 1402425459,
10
- })
11
-
12
- expect { resource.send(action, arguments).to_a }.to raise_exception(DropletKit::Error) do |exception|
13
- expect(exception.message).to match /#{response_body[:message]}/
14
- expect(exception.limit).to eq 1200
15
- expect(exception.remaining).to eq 1193
16
- expect(exception.reset_at).to eq "1402425459"
17
- end
18
- end
19
-
20
- it 'handles unauthorized' do
21
- response_body = { id: :unauthorized, message: 'Nuh uh.' }
22
-
23
- stub_do_api(path, method).to_return(body: response_body.to_json, status: 401)
24
-
25
- expect { resource.send(action, arguments).to_a }.to raise_exception(DropletKit::Error).with_message(/#{response_body[:message]}/)
26
- end
27
- end
@@ -1,16 +0,0 @@
1
- # To use this, `fixture_path`, `api_path` and a `resource` must be defined
2
- # using `let`s.
3
- shared_examples_for 'a paginated index' do
4
- let(:fixture_path) { }
5
- let(:api_path) { }
6
- let(:parameters) { {} }
7
- let(:action) { :all }
8
-
9
- it 'returns a paginated resource' do
10
- fixture = api_fixture(fixture_path)
11
- stub_do_api(api_path, :get).to_return(body: fixture)
12
- response = resource.send(action, {page: 1, per_page: 1}.merge(parameters))
13
-
14
- expect(response).to be_kind_of(DropletKit::PaginatedResource)
15
- end
16
- end
@@ -1,11 +0,0 @@
1
- shared_examples_for 'an action that handles invalid parameters' do
2
- let(:verb) { :post }
3
- let(:exception) { DropletKit::FailedCreate }
4
-
5
- it 'raises an exception with the message attached' do
6
- response_body = { id: :unprocessable_entity, message: 'Something is not right' }
7
- stub_do_api(path, verb).to_return(body: response_body.to_json, status: 422)
8
-
9
- expect { resource.send(action, arguments) }.to raise_exception(exception).with_message(response_body[:message])
10
- end
11
- end