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,119 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::CertificateResource do
4
- include_context 'resources'
5
-
6
- let(:certificate_fixture_path) { 'certificates/find' }
7
- let(:base_path) { '/v2/certificates'}
8
- let(:certificate_id) { '892071a0-bb95-49bc-8021-3afd67a210bf' }
9
- subject(:resource) { described_class.new(connection: connection) }
10
-
11
- RSpec::Matchers.define :match_certificate_fixture do
12
- match do |certificate|
13
- expect(certificate.id).to eq('892071a0-bb95-49bc-8021-3afd67a210bf')
14
- expect(certificate.name).to eq('web-cert-01')
15
- expect(certificate.dns_names).to be_empty
16
- expect(certificate.not_after).to eq('2017-02-22T00:23:00Z')
17
- expect(certificate.sha1_fingerprint).to eq('dfcc9f57d86bf58e321c2c6c31c7a971be244ac7')
18
- expect(certificate.created_at).to eq('2017-02-08T16:02:37Z')
19
- expect(certificate.state).to eq('verified')
20
- expect(certificate.type).to eq('custom')
21
- end
22
- end
23
-
24
- describe '#find' do
25
- let(:certificate) do
26
- DropletKit::Certificate.new(
27
- id: '892071a0-bb95-49bc-8021-3afd67a210bf',
28
- name: 'web-cert-01',
29
- dns_names: ["somedomain.com"],
30
- not_after: '2017-02-22T00:23:00Z',
31
- sha1_fingerprint: 'dfcc9f57d86bf58e321c2c6c31c7a971be244ac7',
32
- created_at: '2017-02-08T16:02:37Z',
33
- status: "verified",
34
- type: "custom",
35
- )
36
- end
37
-
38
- it 'returns certificate' do
39
- stub_do_api(File.join(base_path, certificate_id), :get).to_return(body: api_fixture(certificate_fixture_path))
40
- certificate = resource.find(id: certificate_id)
41
-
42
- expect(certificate).to match_certificate_fixture
43
- end
44
- end
45
-
46
- describe '#all' do
47
- let(:certificates_fixture_path) { 'certificates/all' }
48
-
49
- it 'returns all of the certificates' do
50
- stub_do_api(base_path, :get).to_return(body: api_fixture(certificates_fixture_path))
51
- certificates = resource.all
52
-
53
- expect(certificates).to all(be_kind_of(DropletKit::Certificate))
54
- expect(certificates.first).to match_certificate_fixture
55
- end
56
-
57
- it_behaves_like 'a paginated index' do
58
- let(:fixture_path) { certificates_fixture_path }
59
- let(:api_path) { base_path }
60
- end
61
- end
62
-
63
- describe '#create' do
64
- let(:path) { base_path }
65
-
66
- let(:certificate) do
67
- DropletKit::Certificate.new(
68
- name: 'web-cert-01',
69
- private_key: '-----BEGIN PRIVATE KEY-----',
70
- leaf_certificate: '-----BEGIN CERTIFICATE-----',
71
- certificate_chain: '-----BEGIN CERTIFICATE-----'
72
- )
73
- end
74
-
75
- it 'returns created certificate' do
76
- json_body = DropletKit::CertificateMapping.representation_for(:create, certificate)
77
- stub_do_api(path, :post).with(body: json_body).to_return(body: api_fixture(certificate_fixture_path), status: 201)
78
-
79
- expect(resource.create(certificate)).to match_certificate_fixture
80
- end
81
-
82
- context 'lets encrypt certificate' do
83
- let(:lets_encrypt_certificate) do
84
- DropletKit::Certificate.new(
85
- name: 'lets-encrypt-cert',
86
- dns_names: ['somedomain.com', 'api.somedomain.com'],
87
- type: 'lets_encrypt'
88
- )
89
- end
90
-
91
- it 'returns created lets encrpyt certificate' do
92
- json_body = DropletKit::CertificateMapping.representation_for(:create, lets_encrypt_certificate)
93
- stub_do_api(path, :post).with(body: json_body).to_return(body: api_fixture('certificates/lets_encrypt'), status: 201)
94
- parsed_json = JSON.parse(json_body)
95
-
96
- certificate = resource.create(lets_encrypt_certificate)
97
-
98
- expect(certificate.name).to eq(parsed_json['name'])
99
- expect(certificate.type).to eq(parsed_json['type'])
100
- expect(certificate.dns_names).to match_array(parsed_json['dns_names'])
101
- expect(certificate.state).to eq('pending')
102
- end
103
- end
104
-
105
- it_behaves_like 'an action that handles invalid parameters' do
106
- let(:action) { 'create' }
107
- let(:arguments) { DropletKit::Certificate.new }
108
- end
109
- end
110
-
111
- describe '#delete' do
112
- it 'sends a delete request for the certificate' do
113
- request = stub_do_api(File.join(base_path, certificate_id), :delete)
114
- resource.delete(id: certificate_id)
115
-
116
- expect(request).to have_been_made
117
- end
118
- end
119
- end
@@ -1,99 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::DomainRecordResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- describe '#all' do
8
- it 'returns all of the domain records for a domain' do
9
- response = api_fixture('domain_records/all')
10
- stub_do_api('/v2/domains/example.com/records', :get).to_return(body: response)
11
-
12
- expected_records = DropletKit::DomainRecordMapping.extract_collection(response, :read)
13
- returned_records = resource.all(for_domain: 'example.com')
14
-
15
- expect(returned_records).to all(be_kind_of(DropletKit::DomainRecord))
16
- expect(returned_records).to eq(expected_records)
17
- end
18
-
19
- it_behaves_like 'a paginated index' do
20
- let(:fixture_path) {'domain_records/all'}
21
- let(:api_path) {'/v2/domains/example.com/records'}
22
- end
23
- end
24
-
25
- describe '#create' do
26
- it 'creates a domain record' do
27
- response = api_fixture('domain_records/create')
28
-
29
- domain_record = DropletKit::DomainRecord.new(
30
- type: 'CNAME',
31
- name: 'www',
32
- data: '@',
33
- ttl: 90
34
- )
35
- as_hash = DropletKit::DomainRecordMapping.hash_for(:create, domain_record)
36
- expect(as_hash['type']).to eq('CNAME')
37
- expect(as_hash['name']).to eq('www')
38
- expect(as_hash['data']).to eq('@')
39
- expect(as_hash['ttl']).to eq(90)
40
-
41
- as_json = DropletKit::DomainRecordMapping.representation_for(:create, domain_record)
42
- stub_do_api('/v2/domains/example.com/records', :post).with(body: as_json).to_return(body: response, status: 201)
43
-
44
- created_domain_record = resource.create(domain_record, for_domain: 'example.com')
45
- expect(created_domain_record.id).to eq(16)
46
- expect(created_domain_record.name).to eq('www')
47
- expect(created_domain_record.type).to eq('CNAME')
48
- expect(created_domain_record.data).to eq('@')
49
- expect(created_domain_record.ttl).to eq(90)
50
- end
51
- end
52
-
53
- describe '#find' do
54
- it 'returns a domain record' do
55
- response = api_fixture('domain_records/find')
56
- stub_do_api('/v2/domains/example.com/records/12', :get).to_return(body: response)
57
-
58
- expected_record = DropletKit::DomainRecordMapping.extract_single(response, :read)
59
- expect(resource.find(id: 12, for_domain: 'example.com')).to eq(expected_record)
60
- end
61
-
62
- it_behaves_like 'resource that handles common errors' do
63
- let(:path) { '/v2/domains/example.com/records/12' }
64
- let(:method) { :get }
65
- let(:action) { :find }
66
- let(:arguments) { { for_domain: 'example.com', id: 123 } }
67
- end
68
- end
69
-
70
- describe '#delete' do
71
- it 'deletes the domain record for an id and domain name' do
72
- request = stub_do_api('/v2/domains/example.com/records/12', :delete)
73
- resource.delete(for_domain: 'example.com', id: 12)
74
-
75
- expect(request).to have_been_made
76
- end
77
- end
78
-
79
- describe '#update' do
80
- it 'updates a record' do
81
- response = api_fixture('domain_records/update')
82
-
83
- domain_record = DropletKit::DomainRecord.new(name: 'lol')
84
- as_hash = DropletKit::DomainRecordMapping.hash_for(:update, domain_record)
85
- expect(as_hash['name']).to eq('lol')
86
-
87
- as_json = DropletKit::DomainRecordMapping.representation_for(:update, domain_record)
88
- request = stub_do_api('/v2/domains/example.com/records/1066', :put).with(body: as_json).to_return(body: response, status: 200)
89
- updated_domain_record = resource.update(domain_record, for_domain: 'example.com', id: 1066)
90
-
91
- expect(request).to have_been_made
92
- expect(updated_domain_record.id).to eq(1066)
93
- expect(updated_domain_record.name).to eq('lol')
94
- expect(updated_domain_record.type).to eq('CNAME')
95
- expect(updated_domain_record.data).to eq('@')
96
- expect(updated_domain_record.ttl).to eq(1800)
97
- end
98
- end
99
- end
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::DomainResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- describe '#all' do
8
- it 'returns all of the domains' do
9
- response = api_fixture('domains/all')
10
- stub_do_api('/v2/domains', :get).to_return(body: response)
11
- expected_domains = DropletKit::DomainMapping.extract_collection(response, :read)
12
-
13
- expect(resource.all).to eq(expected_domains)
14
- end
15
-
16
- it_behaves_like 'a paginated index' do
17
- let(:fixture_path) {'domains/all'}
18
- let(:api_path) {'/v2/domains'}
19
- end
20
- end
21
-
22
- describe '#create' do
23
- it 'send a POST request to create a domain' do
24
- response = api_fixture('domains/create')
25
-
26
- domain = DropletKit::Domain.new(ip_address: '1.1.1.1', name: 'example.com')
27
- as_hash = DropletKit::DomainMapping.hash_for(:create, domain)
28
- expect(as_hash['ip_address']).to eq('1.1.1.1')
29
- expect(as_hash['name']).to eq('example.com')
30
-
31
- as_json = DropletKit::DomainMapping.representation_for(:create, domain)
32
- stub_do_api('/v2/domains', :post).with(body: as_json).to_return(body: response, status: 201)
33
-
34
- created_domain = resource.create(domain)
35
- expect(created_domain.name).to eq('example.com')
36
- expect(created_domain.ttl).to eq(1800)
37
- expect(created_domain.zone_file).to eq(nil)
38
- end
39
- end
40
-
41
- describe '#find' do
42
- it 'returns a single domain' do
43
- response = api_fixture('domains/find')
44
- stub_do_api('/v2/domains/example.com', :get).to_return(body: response)
45
- expected_domain = DropletKit::DomainMapping.extract_single(response, :read)
46
-
47
- expect(resource.find(name: 'example.com')).to eq(expected_domain)
48
- end
49
-
50
- it_behaves_like 'resource that handles common errors' do
51
- let(:path) { '/v2/domains/example.com' }
52
- let(:method) { :get }
53
- let(:action) { :find }
54
- let(:arguments) { { name: 'example.com' } }
55
- end
56
- end
57
-
58
- describe '#delete' do
59
- it 'deletes a single domain' do
60
- request = stub_do_api('/v2/domains/example.com', :delete)
61
- resource.delete(name: 'example.com')
62
- expect(request).to have_been_made
63
- end
64
- end
65
- end
@@ -1,223 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::DropletActionResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- let(:droplet_id) { 1066 }
6
-
7
- let(:fixture) { api_fixture("droplet_actions/#{action}") }
8
-
9
- include_context 'resources'
10
-
11
- describe '#action_for_id' do
12
- let(:action) { 'event' }
13
- let(:path) { "/v2/droplets/#{droplet_id}/actions" }
14
- let(:fixture) { api_fixture('droplet_actions/find') }
15
-
16
- it 'performs the action' do
17
- request = stub_do_api(path, :post).with(
18
- body: { type: action, param_1: 1, param_2: 2 }.to_json
19
- ).to_return(body: fixture, status: 201)
20
-
21
- resource.action_for_id(droplet_id: droplet_id, type: action, param_1: 1, param_2: 2)
22
- expect(request).to have_been_made
23
- end
24
- end
25
-
26
- describe '#action_for_tag' do
27
- let(:action) { 'event' }
28
- let(:path) { '/v2/droplets/actions' }
29
- let(:fixture) { api_fixture('droplet_actions/find') }
30
-
31
- it 'performs the action' do
32
- request = stub_do_api(path, :post).with(
33
- body: { tag_name: 'test-tag', type: action, param_1: 1, param_2: 2 }.to_json
34
- ).to_return(body: fixture, status: 201)
35
-
36
- resource.action_for_tag(tag_name: 'test-tag', type: action, param_1: 1, param_2: 2)
37
- expect(request).to have_been_made
38
- end
39
- end
40
-
41
- described_class::ACTIONS_WITHOUT_INPUT.each do |action_name|
42
- describe "Action #{action_name}" do
43
- let(:action) { action_name }
44
- let(:path) { "/v2/droplets/#{droplet_id}/actions" }
45
-
46
- it 'performs the action' do
47
- request = stub_do_api(path, :post).with(
48
- body: { type: action }.to_json
49
- ).to_return(body: fixture, status: 201)
50
-
51
- returned_action = resource.send(action, droplet_id: droplet_id)
52
-
53
- expect(request).to have_been_made
54
- expect(returned_action.type).to eq(action)
55
- end
56
-
57
- it_behaves_like 'an action that handles invalid parameters' do
58
- let(:object) { DropletKit::Droplet.new }
59
- let(:arguments) { { droplet_id: droplet_id } }
60
- end
61
- end
62
- end
63
-
64
- described_class::TAG_ACTIONS.each do |action_name|
65
- describe "Batch Action #{action_name}" do
66
- let(:action) { "#{action_name}_for_tag" }
67
- let(:path) { "/v2/droplets/actions?tag_name=testing-1" }
68
- let(:fixture) do
69
- single_action = DropletKit::ActionMapping.extract_single(api_fixture("droplet_actions/#{action_name}"), :read)
70
-
71
- DropletKit::ActionMapping.represent_collection_for(:read, [single_action])
72
- end
73
-
74
- it 'performs the action' do
75
- request = stub_do_api(path, :post).with(
76
- body: { type: action_name }.to_json
77
- ).to_return(body: fixture, status: 201)
78
-
79
- returned_actions = resource.send(action, tag_name: 'testing-1')
80
-
81
- expect(request).to have_been_made
82
- expect(returned_actions.first.type).to eq(action_name)
83
- end
84
- end
85
- end
86
-
87
- describe "Action snapshot" do
88
- let(:action) { 'snapshot' }
89
-
90
- it 'performs the action' do
91
- request = stub_do_api("/v2/droplets/#{droplet_id}/actions", :post).with(
92
- body: { type: action, name: 'Dwight' }.to_json
93
- ).to_return(body: fixture, status: 201)
94
-
95
- returned_action = resource.send(action, droplet_id: droplet_id, name: 'Dwight')
96
-
97
- expect(request).to have_been_made
98
- expect(returned_action.type).to eq(action)
99
- end
100
- end
101
-
102
- describe "Action change_kernel" do
103
- let(:action) { 'change_kernel' }
104
-
105
- it 'performs the action' do
106
- request = stub_do_api("/v2/droplets/#{droplet_id}/actions", :post).with(
107
- body: { type: action, kernel: 1556 }.to_json
108
- ).to_return(body: fixture, status: 201)
109
-
110
- returned_action = resource.send(action, droplet_id: droplet_id, kernel: 1556)
111
-
112
- expect(request).to have_been_made
113
- expect(returned_action.type).to eq(action)
114
- end
115
- end
116
-
117
- describe "Action rename" do
118
- let(:action) { 'rename' }
119
-
120
- it 'performs the action' do
121
- request = stub_do_api("/v2/droplets/#{droplet_id}/actions", :post).with(
122
- body: { type: action, name: 'newname.com' }.to_json
123
- ).to_return(body: fixture, status: 201)
124
-
125
- returned_action = resource.send(action, droplet_id: droplet_id, name: 'newname.com')
126
-
127
- expect(request).to have_been_made
128
- expect(returned_action.type).to eq(action)
129
- end
130
- end
131
-
132
- describe "Action rebuild" do
133
- let(:action) { 'rebuild' }
134
-
135
- it 'performs the action' do
136
- request = stub_do_api("/v2/droplets/#{droplet_id}/actions", :post).with(
137
- body: { type: action, image: 'ubuntu-14-04-x86' }.to_json
138
- ).to_return(body: fixture, status: 201)
139
-
140
- returned_action = resource.send(action, droplet_id: droplet_id, image: 'ubuntu-14-04-x86')
141
-
142
- expect(request).to have_been_made
143
- expect(returned_action.type).to eq(action)
144
- end
145
- end
146
-
147
- describe "Action restore" do
148
- let(:action) { 'restore' }
149
-
150
- it 'performs the action' do
151
- request = stub_do_api("/v2/droplets/#{droplet_id}/actions", :post).with(
152
- body: { type: action, image: 'ubuntu-14-04-x86' }.to_json
153
- ).to_return(body: fixture, status: 201)
154
-
155
- returned_action = resource.send(action, droplet_id: droplet_id, image: 'ubuntu-14-04-x86')
156
-
157
- expect(request).to have_been_made
158
- expect(returned_action.type).to eq(action)
159
- end
160
- end
161
-
162
- describe "Action resize" do
163
- let(:action) { 'resize' }
164
-
165
- it 'performs the action' do
166
- request = stub_do_api("/v2/droplets/#{droplet_id}/actions", :post).with(
167
- body: { type: action, size: '1gb', disk: nil }.to_json
168
- ).to_return(body: fixture, status: 201)
169
-
170
- returned_action = resource.send(action, droplet_id: droplet_id, size: '1gb')
171
-
172
- expect(request).to have_been_made
173
- expect(returned_action.type).to eq(action)
174
- end
175
- end
176
-
177
- describe "Action resize with disk" do
178
- let(:action) { 'resize' }
179
-
180
- it 'performs the action' do
181
- request = stub_do_api("/v2/droplets/#{droplet_id}/actions", :post).with(
182
- body: { type: action, size: '1gb', disk: true }.to_json
183
- ).to_return(body: fixture, status: 201)
184
-
185
- returned_action = resource.send(action, droplet_id: droplet_id, size: '1gb', disk: true)
186
-
187
- expect(request).to have_been_made
188
- expect(returned_action.type).to eq(action)
189
- end
190
- end
191
-
192
- describe '#find' do
193
- it 'returns an action' do
194
- request = stub_do_api("/v2/droplets/1066/actions/123", :get).to_return(
195
- body: api_fixture('droplet_actions/find')
196
- )
197
-
198
- returned_action = resource.find(droplet_id: 1066, id: 123)
199
- expect(request).to have_been_made
200
-
201
- expect(returned_action.type).to eq('test')
202
- expect(returned_action.started_at).to eq("2014-07-29T14:35:27Z")
203
- expect(returned_action.completed_at).to eq(nil)
204
- expect(returned_action.resource_id).to eq(nil)
205
- expect(returned_action.resource_type).to eq("backend")
206
- expect(returned_action.region_slug).to eq('nyc1')
207
-
208
- expect(returned_action.region).to be_kind_of(DropletKit::Region)
209
- expect(returned_action.region.slug).to eq('nyc1')
210
- expect(returned_action.region.name).to eq('New York')
211
- expect(returned_action.region.sizes).to include('512mb')
212
- expect(returned_action.region.available).to be(true)
213
- expect(returned_action.region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
214
- end
215
-
216
- it_behaves_like 'resource that handles common errors' do
217
- let(:path) { '/v2/droplets/1066/actions/123' }
218
- let(:method) { :get }
219
- let(:action) { :find }
220
- let(:arguments) { { droplet_id: 1066, id: 123 } }
221
- end
222
- end
223
- end