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,137 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::FloatingIpActionResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- describe '#assign' do
8
- let(:ip) { '127.0.0.1' }
9
- let(:droplet_id) { 123 }
10
- let(:path) { "/v2/floating_ips/#{ip}/actions" }
11
- let(:action) { 'assign' }
12
- let(:fixture) { api_fixture("floating_ip_actions/#{action}") }
13
-
14
- it 'sends an assign request for a floating ip' do
15
- request = stub_do_api(path).with(
16
- body: { type: action, droplet_id: droplet_id }.to_json
17
- ).to_return(body: fixture, status: 201)
18
-
19
- action = resource.assign(ip: ip, droplet_id: droplet_id)
20
-
21
- expect(request).to have_been_made
22
-
23
- expect(action).to be_kind_of(DropletKit::Action)
24
- expect(action.id).to eq(2)
25
- expect(action.status).to eq("in-progress")
26
- expect(action.type).to eq("assign")
27
- expect(action.started_at).to eq("2014-08-05T15:15:28Z")
28
- expect(action.completed_at).to eq(nil)
29
- expect(action.resource_id).to eq(12)
30
- expect(action.resource_type).to eq("floating_ip")
31
- expect(action.region_slug).to eq("nyc1")
32
-
33
- expect(action.region).to be_kind_of(DropletKit::Region)
34
- expect(action.region.slug).to eq('nyc1')
35
- expect(action.region.name).to eq('New York')
36
- expect(action.region.sizes).to include('512mb')
37
- expect(action.region.available).to be(true)
38
- expect(action.region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
39
- end
40
-
41
- it_behaves_like 'an action that handles invalid parameters' do
42
- let(:arguments) { { ip: ip, droplet_id: droplet_id } }
43
- end
44
- end
45
-
46
- describe '#unassign' do
47
- let(:ip) { '127.0.0.1' }
48
- let(:path) { "/v2/floating_ips/#{ip}/actions" }
49
- let(:action) { 'unassign' }
50
- let(:fixture) { api_fixture("floating_ip_actions/#{action}") }
51
-
52
- it 'sends an unassign request for a floating ip' do
53
- request = stub_do_api(path).with(
54
- body: { type: action }.to_json
55
- ).to_return(body: fixture, status: 201)
56
-
57
- action = resource.unassign(ip: ip)
58
-
59
- expect(request).to have_been_made
60
-
61
- expect(action).to be_kind_of(DropletKit::Action)
62
- expect(action.id).to eq(2)
63
- expect(action.status).to eq("in-progress")
64
- expect(action.type).to eq("unassign")
65
- expect(action.started_at).to eq("2014-08-05T15:15:28Z")
66
- expect(action.completed_at).to eq(nil)
67
- expect(action.resource_id).to eq(12)
68
- expect(action.resource_type).to eq("floating_ip")
69
- expect(action.region_slug).to eq("nyc1")
70
-
71
- expect(action.region).to be_kind_of(DropletKit::Region)
72
- expect(action.region.slug).to eq('nyc1')
73
- expect(action.region.name).to eq('New York')
74
- expect(action.region.sizes).to include('512mb')
75
- expect(action.region.available).to be(true)
76
- expect(action.region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
77
- end
78
-
79
- it_behaves_like 'an action that handles invalid parameters' do
80
- let(:arguments) { { ip: ip } }
81
- end
82
- end
83
-
84
- describe '#all' do
85
- let(:ip) { '127.0.0.1' }
86
-
87
- it 'returns all of the floating ip actions via a paginated resources' do
88
- request = stub_do_api("/v2/floating_ips/#{ip}/actions", :get).to_return(
89
- body: api_fixture('floating_ip_actions/all'),
90
- status: 200
91
- )
92
-
93
- actions = resource.all(ip: ip).take(20)
94
-
95
- expect(request).to have_been_made
96
-
97
- expect(actions.size).to be(2)
98
-
99
- action = actions.first
100
-
101
- expect(action.id).to eq(19)
102
- expect(action.status).to eq("completed")
103
- expect(action.type).to eq("assign_ip")
104
- expect(action.started_at).to eq("2014-10-28T17:11:05Z")
105
- expect(action.completed_at).to eq("2014-10-28T17:11:06Z")
106
- expect(action.resource_id).to eq(45646587)
107
- expect(action.resource_type).to eq("floating_ip")
108
- expect(action.region).to be_kind_of(DropletKit::Region)
109
- expect(action.region_slug).to eq("nyc1")
110
- end
111
-
112
- it_behaves_like 'a paginated index' do
113
- let(:fixture_path) { 'floating_ip_actions/all' }
114
- let(:api_path) { "/v2/floating_ips/#{ip}/actions" }
115
- let(:parameters) { { ip: ip } }
116
- end
117
- end
118
-
119
- describe '#find' do
120
- let(:ip) { '127.0.0.1' }
121
-
122
- it 'returns a single action' do
123
- stub_do_api("/v2/floating_ips/#{ip}/actions/23", :get).to_return(body: api_fixture('floating_ip_actions/find'))
124
- action = resource.find(ip: ip, id: 23)
125
-
126
- expect(action.id).to eq(19)
127
- expect(action.status).to eq("completed")
128
- expect(action.type).to eq("assign_ip")
129
- expect(action.started_at).to eq("2014-10-28T17:11:05Z")
130
- expect(action.completed_at).to eq("2014-10-28T17:11:06Z")
131
- expect(action.resource_id).to eq(45646587)
132
- expect(action.resource_type).to eq("floating_ip")
133
- expect(action.region).to be_kind_of(DropletKit::Region)
134
- expect(action.region_slug).to eq("nyc1")
135
- end
136
- end
137
- end
@@ -1,91 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::FloatingIpResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- RSpec::Matchers.define :match_floating_ip_fixture do |droplet|
8
- match do |floating_ip|
9
- expect(floating_ip.region).to be_kind_of(DropletKit::Region)
10
- expect(floating_ip.droplet).to be_kind_of(DropletKit::Droplet) if droplet
11
-
12
- floating_ip.ip == "45.55.96.32"
13
- end
14
- end
15
-
16
- describe '#all' do
17
- it 'returns all of the floating_ips' do
18
- stub_do_api('/v2/floating_ips', :get).to_return(body: api_fixture('floating_ips/all'))
19
- floating_ips = resource.all
20
- expect(floating_ips).to all(be_kind_of(DropletKit::FloatingIp))
21
-
22
- expect(floating_ips.first).to match_floating_ip_fixture
23
- end
24
-
25
- it 'returns an empty array of floating_ips' do
26
- stub_do_api('/v2/floating_ips', :get).to_return(body: api_fixture('floating_ips/all_empty'))
27
- floating_ips = resource.all.map(&:ip)
28
- expect(floating_ips).to be_empty
29
- end
30
-
31
- it_behaves_like 'a paginated index' do
32
- let(:fixture_path) { 'floating_ips/all' }
33
- let(:api_path) { '/v2/floating_ips' }
34
- end
35
- end
36
-
37
- describe '#find' do
38
- it 'returns a singular floating_ip' do
39
- stub_do_api('/v2/floating_ips/45.55.96.32', :get).to_return(body: api_fixture('floating_ips/find'))
40
- floating_ip = resource.find(ip: "45.55.96.32")
41
- expect(floating_ip).to be_kind_of(DropletKit::FloatingIp)
42
- expect(floating_ip).to match_floating_ip_fixture
43
- end
44
- end
45
-
46
- describe '#create' do
47
- let(:path) { '/v2/floating_ips' }
48
-
49
- context 'for a successful create' do
50
- it 'returns the created floating_ip' do
51
- floating_ip = DropletKit::FloatingIp.new(
52
- region: 'nyc1'
53
- )
54
-
55
- as_string = DropletKit::FloatingIpMapping.representation_for(:create, floating_ip)
56
- stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('floating_ips/create'), status: 202)
57
- created_floating_ip = resource.create(floating_ip)
58
-
59
- expect(created_floating_ip).to match_floating_ip_fixture
60
- end
61
- end
62
-
63
- context 'for a successful create with droplet' do
64
- it 'returns the created floating_ip' do
65
- floating_ip = DropletKit::FloatingIp.new(
66
- droplet_id: 123
67
- )
68
-
69
- as_string = DropletKit::FloatingIpMapping.representation_for(:create, floating_ip)
70
- stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('floating_ips/create_with_droplet'), status: 202)
71
- created_floating_ip = resource.create(floating_ip)
72
-
73
- expect(created_floating_ip).to match_floating_ip_fixture
74
- end
75
- end
76
-
77
- it_behaves_like 'an action that handles invalid parameters' do
78
- let(:action) { 'create' }
79
- let(:arguments) { DropletKit::FloatingIp.new }
80
- end
81
- end
82
-
83
- describe '#delete' do
84
- it 'sends a delete request for the floating_ip' do
85
- request = stub_do_api('/v2/floating_ips/45.55.96.32', :delete)
86
- resource.delete(ip: "45.55.96.32")
87
-
88
- expect(request).to have_been_made
89
- end
90
- end
91
- end
@@ -1,149 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::ImageActionResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- describe '#transfer' do
8
- let(:image_id) { 449676391 }
9
- let(:path) { "/v2/images/#{image_id}/actions" }
10
- let(:action) { 'transfer' }
11
-
12
- it 'sends a transfer request for an image' do
13
- fixture = api_fixture('image_actions/transfer')
14
-
15
- request = stub_do_api(path).with(
16
- body: { type: action, region: 'sfo1' }.to_json
17
- ).to_return(body: fixture, status: 201)
18
-
19
- action = resource.transfer(image_id: image_id, region: 'sfo1')
20
-
21
- expect(request).to have_been_made
22
-
23
- expect(action).to be_kind_of(DropletKit::Action)
24
- expect(action.id).to eq(23)
25
- expect(action.status).to eq("in-progress")
26
- expect(action.type).to eq("transfer")
27
- expect(action.started_at).to eq("2014-08-05T15:15:28Z")
28
- expect(action.completed_at).to eq(nil)
29
- expect(action.resource_id).to eq(449676391)
30
- expect(action.resource_type).to eq("image")
31
- expect(action.region_slug).to eq("nyc1")
32
-
33
- expect(action.region).to be_kind_of(DropletKit::Region)
34
- expect(action.region.slug).to eq('nyc1')
35
- expect(action.region.name).to eq('New York')
36
- expect(action.region.sizes).to include('512mb')
37
- expect(action.region.available).to be(true)
38
- expect(action.region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
39
- end
40
-
41
- it_behaves_like 'an action that handles invalid parameters' do
42
- let(:object) { DropletKit::Image.new }
43
- let(:arguments) { { image_id: image_id, region: 'sfo1' } }
44
- end
45
- end
46
-
47
- describe '#convert' do
48
- let(:image_id) { 449676391 }
49
- let(:path) { "/v2/images/#{image_id}/actions" }
50
- let(:action) { 'convert' }
51
-
52
- it 'sends a convert request for an image' do
53
- fixture = api_fixture('image_actions/convert')
54
-
55
- request = stub_do_api(path).with(
56
- body: { type: action }.to_json
57
- ).to_return(body: fixture, status: 201)
58
-
59
- action = resource.convert(image_id: image_id)
60
-
61
- expect(request).to have_been_made
62
-
63
- expect(action).to be_kind_of(DropletKit::Action)
64
- expect(action.id).to eq(23)
65
- expect(action.status).to eq("in-progress")
66
- expect(action.type).to eq("convert")
67
- expect(action.started_at).to eq("2014-08-05T15:15:28Z")
68
- expect(action.completed_at).to eq(nil)
69
- expect(action.resource_id).to eq(449676391)
70
- expect(action.resource_type).to eq("image")
71
- expect(action.region_slug).to eq("nyc1")
72
-
73
- expect(action.region).to be_kind_of(DropletKit::Region)
74
- expect(action.region.slug).to eq('nyc1')
75
- expect(action.region.name).to eq('New York')
76
- expect(action.region.sizes).to include('512mb')
77
- expect(action.region.available).to be(true)
78
- expect(action.region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
79
- end
80
-
81
- it_behaves_like 'an action that handles invalid parameters' do
82
- let(:object) { DropletKit::Image.new }
83
- let(:arguments) { { image_id: image_id } }
84
- end
85
- end
86
-
87
- describe '#all' do
88
- it 'returns all of the image actions via a paginated resources' do
89
- request = stub_do_api('/v2/images/449676391/actions', :get).to_return(
90
- body: api_fixture('image_actions/all'),
91
- status: 200
92
- )
93
-
94
- actions = resource.all(image_id: 449676391).take(20)
95
-
96
- expect(request).to have_been_made
97
-
98
- expect(actions.size).to be(2)
99
-
100
- action = actions.first
101
-
102
- expect(action.id).to eq(298374)
103
- expect(action.status).to eq("completed")
104
- expect(action.type).to eq("image_destroy")
105
- expect(action.started_at).to eq("2014-10-28T17:11:05Z")
106
- expect(action.completed_at).to eq("2014-10-28T17:11:06Z")
107
- expect(action.resource_id).to eq(45646587)
108
- expect(action.resource_type).to eq("image")
109
- expect(action.region).to eq(nil)
110
- expect(action.region_slug).to eq(nil)
111
- end
112
-
113
- it_behaves_like 'a paginated index' do
114
- let(:fixture_path) {'image_actions/all'}
115
- let(:api_path) {'/v2/images/45646587/actions'}
116
- end
117
- end
118
-
119
- describe '#find' do
120
- it 'returns a single action' do
121
- stub_do_api('/v2/images/449676391/actions/23').to_return(body: api_fixture('image_actions/find'))
122
- action = resource.find(image_id: 449676391, id: 23)
123
-
124
- expect(action).to be_kind_of(DropletKit::Action)
125
- expect(action.id).to eq(23)
126
- expect(action.status).to eq("in-progress")
127
- expect(action.type).to eq("transfer")
128
- expect(action.started_at).to eq("2014-08-05T15:15:28Z")
129
- expect(action.completed_at).to eq(nil)
130
- expect(action.resource_id).to eq(449676391)
131
- expect(action.resource_type).to eq("image")
132
- expect(action.region_slug).to eq("nyc1")
133
-
134
- expect(action.region).to be_kind_of(DropletKit::Region)
135
- expect(action.region.slug).to eq('nyc1')
136
- expect(action.region.name).to eq('New York')
137
- expect(action.region.sizes).to include('512mb')
138
- expect(action.region.available).to be(true)
139
- expect(action.region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
140
- end
141
-
142
- it_behaves_like 'resource that handles common errors' do
143
- let(:path) { '/v2/images/1066/actions/123' }
144
- let(:method) { :get }
145
- let(:action) { :find }
146
- let(:arguments) { { image_id: 1066, id: 123 } }
147
- end
148
- end
149
- end
@@ -1,93 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::ImageResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- describe '#all' do
8
- it 'returns all of the images' do
9
- images_json = api_fixture('images/all')
10
- stub_do_api('/v2/images', :get).to_return(body: images_json)
11
- expected_images = DropletKit::ImageMapping.extract_collection images_json, :read
12
-
13
- expect(resource.all).to eq(expected_images)
14
- end
15
-
16
- it 'returns private images' do
17
- images_json = api_fixture('images/private')
18
- stub_do_api('/v2/images', :get)
19
- .with(query: hash_including({ private: 'true' }))
20
- .to_return(body: images_json)
21
- expected_images = DropletKit::ImageMapping.extract_collection images_json, :read
22
-
23
- expect(resource.all(private: true)).to eq(expected_images)
24
- end
25
-
26
- it 'returns images of a type' do
27
- images_json = api_fixture('images/type')
28
- stub_do_api('/v2/images', :get)
29
- .with(query: hash_including({ type: 'application' }))
30
- .to_return(body: images_json)
31
- expected_images = DropletKit::ImageMapping.extract_collection images_json, :read
32
-
33
- expect(resource.all(type: :application)).to eq(expected_images)
34
- end
35
-
36
- it_behaves_like 'a paginated index' do
37
- let(:fixture_path) { 'images/all' }
38
- let(:api_path) { '/v2/images' }
39
- end
40
- end
41
-
42
- describe '#find' do
43
- it 'returns a singular image' do
44
- stub_do_api('/v2/images/146', :get).to_return(body: api_fixture('images/find'))
45
- image = resource.find(id: 146)
46
-
47
- expect(image.id).to eq(146)
48
- expect(image.name).to eq("Ubuntu 13.04")
49
- expect(image.distribution).to eq(nil)
50
- expect(image.slug).to eq(nil)
51
- expect(image.public).to eq(false)
52
- expect(image.regions).to eq(["region--1"])
53
- expect(image.type).to eq("snapshot")
54
-
55
- expect(image.min_disk_size).to eq(20)
56
- expect(image.size_gigabytes).to eq(0.43)
57
- expect(image.created_at).to eq('2014-07-29T14:35:41Z')
58
- end
59
-
60
- it_behaves_like 'resource that handles common errors' do
61
- let(:path) { '/v2/images/123' }
62
- let(:method) { :get }
63
- let(:action) { :find }
64
- let(:arguments) { { id: 123 } }
65
- end
66
- end
67
-
68
- describe '#delete' do
69
- it 'deletes an image' do
70
- request = stub_do_api('/v2/images/146', :delete).to_return(body: '', status: 204)
71
- resource.delete(id: 146)
72
- expect(request).to have_been_made
73
- end
74
- end
75
-
76
- describe '#update' do
77
- it 'updates an image' do
78
- image = DropletKit::Image.new(name: 'new-name')
79
- as_hash = DropletKit::ImageMapping.hash_for(:update, image)
80
- expect(as_hash['name']).to eq('new-name')
81
-
82
- request = stub_do_api('/v2/images/146', :put).with(
83
- body: DropletKit::ImageMapping.representation_for(:update, image)
84
- ).to_return(body: api_fixture('images/find'))
85
-
86
- image = resource.update(image, id: 146)
87
- expect(request).to have_been_made
88
-
89
- expect(image).to be_kind_of(DropletKit::Image)
90
- expect(image.id).to eq(146)
91
- end
92
- end
93
- end