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,126 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe DropletKit::ProjectResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- RSpec::Matchers.define :match_project_fixture do |expected|
8
- match do |actual|
9
- expect(actual).to be_kind_of(DropletKit::Project)
10
- expect(actual.name).to eq('cloud.digitalocean.com')
11
- expect(actual.id).to eq('c177dc8c-12c1-4483-af1c-877eed0f14cb')
12
- expect(actual.owner_uuid).to eq('34fc5c195b417b7157649f6b8ae273ae9b1b2970')
13
- expect(actual.owner_id).to eq(123)
14
- expect(actual.description).to eq('Our control panel')
15
- expect(actual.purpose).to eq('Web Application')
16
- expect(actual.environment).to eq('Production')
17
- expect(actual.is_default).to be_falsey
18
- expect(actual.created_at).to be_present
19
- expect(actual.updated_at).to be_present
20
- end
21
- end
22
- describe '#all' do
23
- it 'returns all of the projects' do
24
- stub_do_api('/v2/projects', :get)
25
- .to_return(body: api_fixture('projects/all'))
26
- projects = resource.all
27
-
28
- expect(projects).to all(be_kind_of(DropletKit::Project))
29
- expect(projects.collection.size).to eq(2)
30
-
31
- default = projects[0]
32
- expect(default.name).to eq('digitalocean')
33
- expect(default.id).to eq('ec104091-d6d3-41b6-b803-780156de20ae')
34
- expect(default.owner_uuid).to eq('34fc5c195b417b7157649f6b8ae273ae9b1b2970')
35
- expect(default.owner_id).to eq(123)
36
- expect(default.description).to eq('Update your project information under Settings')
37
- expect(default.purpose).to be_empty
38
- expect(default.environment).to be_empty
39
- expect(default.is_default).to be_truthy
40
- expect(default.created_at).to be_present
41
- expect(default.updated_at).to be_present
42
-
43
- cloud = projects[1]
44
- expect(cloud).to match_project_fixture
45
- end
46
-
47
- context 'when empty' do
48
- it 'returns an empty array of projects' do
49
- stub_do_api('/v2/projects', :get)
50
- .to_return(body: api_fixture('projects/all_empty'))
51
- projects = resource.all.map(&:id)
52
-
53
- expect(projects).to be_empty
54
- end
55
- end
56
-
57
- it_behaves_like 'a paginated index' do
58
- let(:fixture_path) { 'projects/all' }
59
- let(:api_path) { '/v2/projects' }
60
- end
61
- end
62
-
63
- describe '#find' do
64
- it 'returns a singular tag' do
65
- stub_do_api('/v2/projects/c177dc8c-12c1-4483-af1c-877eed0f14cb', :get)
66
- .to_return(body: api_fixture('projects/find'))
67
-
68
- project = resource.find(id: 'c177dc8c-12c1-4483-af1c-877eed0f14cb')
69
-
70
- expect(project).to match_project_fixture
71
- end
72
- end
73
-
74
- describe '#create' do
75
- it 'returns the created project' do
76
- project = DropletKit::Project.new(name: 'cloud.digitalocean.com', description: 'Our control panel', purpose: 'Web Application', environment: 'Production')
77
-
78
- as_string = DropletKit::ProjectMapping.representation_for(:create, project)
79
-
80
- stub_do_api('/v2/projects', :post).with(body: as_string)
81
- .to_return(body: api_fixture('projects/find'), status: 201)
82
- created_project = resource.create(project)
83
-
84
- expect(created_project).to match_project_fixture
85
- end
86
- end
87
-
88
- describe '#delete' do
89
- it 'deletes a project' do
90
- request = stub_do_api('/v2/projects/c177dc8c-12c1-4483-af1c-877eed0f14cb', :delete)
91
- .to_return(body: '', status: 204)
92
-
93
- resource.delete(id: 'c177dc8c-12c1-4483-af1c-877eed0f14cb')
94
- expect(request).to have_been_made
95
- end
96
- end
97
-
98
- describe '#list_resources' do
99
- it 'list resources in the specified project' do
100
- request = stub_do_api('/v2/projects/c177dc8c-12c1-4483-af1c-877eed0f14cb/resources', :get)
101
- .to_return(body: api_fixture('projects/resources'), status: 200)
102
-
103
- resources = resource.list_resources(id: 'c177dc8c-12c1-4483-af1c-877eed0f14cb')
104
-
105
- expect(request).to have_been_made
106
- expect(resources.to_a.size).to eq(10)
107
- resources.each do |resource|
108
- expect(resource[:urn]).to start_with('do:')
109
- expect(resource[:self_link]).to_not be_empty
110
- end
111
-
112
- objects = resources.map(&:to_model)
113
- expect(objects.first).to be_nil # Can't map spaces
114
- droplets = objects[1..-1]
115
- droplets.each do |droplet|
116
- expect(droplet).to be_a(DropletKit::Droplet)
117
- expect(droplet.id).to_not be_empty
118
- end
119
- end
120
-
121
- it_behaves_like 'a paginated index' do
122
- let(:fixture_path) { 'projects/resources' }
123
- let(:api_path) { '/v2/projects/c177dc8c-12c1-4483-af1c-877eed0f14cb/resources' }
124
- end
125
- end
126
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::RegionResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- describe '#all' do
8
- it 'returns a collection of regions' do
9
- body = api_fixture('regions/all')
10
- stub_do_api('/v2/regions').to_return(body: body)
11
- expected = DropletKit::RegionMapping.extract_collection(body, :read)
12
-
13
- expect(resource.all).to eq(expected)
14
- end
15
-
16
- it_behaves_like 'a paginated index' do
17
- let(:fixture_path) {'regions/all'}
18
- let(:api_path) {'/v2/regions'}
19
- end
20
-
21
- it_behaves_like 'resource that handles common errors' do
22
- let(:path) { '/v2/regions' }
23
- let(:method) { :get }
24
- let(:action) { :all }
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::SizeResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- describe '#all' do
8
- it 'returns a collection of regions' do
9
- body = api_fixture('sizes/all')
10
- stub_do_api('/v2/sizes').to_return(body: body)
11
- expected = DropletKit::SizeMapping.extract_collection(body, :read)
12
-
13
- expect(resource.all).to eq(expected)
14
- end
15
-
16
- it_behaves_like 'a paginated index' do
17
- let(:fixture_path) {'sizes/all'}
18
- let(:api_path) {'/v2/sizes'}
19
- end
20
-
21
- it_behaves_like 'resource that handles common errors' do
22
- let(:path) { '/v2/sizes' }
23
- let(:method) { :get }
24
- let(:action) { :all }
25
- end
26
- end
27
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::SnapshotResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- describe '#all' do
8
- it 'returns all of the snapshots' do
9
- snapshots_json = api_fixture('snapshots/all')
10
- stub_do_api('/v2/snapshots', :get).to_return(body: snapshots_json)
11
- expected_snapshots = DropletKit::SnapshotMapping.extract_collection(snapshots_json, :read)
12
-
13
- expect(resource.all).to eq(expected_snapshots)
14
- end
15
-
16
- it 'returns snapshots of a type' do
17
- snapshots_json = api_fixture('snapshots/resource_type')
18
- stub_do_api('/v2/snapshots', :get)
19
- .with(query: hash_including({ resource_type: 'droplet' }))
20
- .to_return(body: snapshots_json)
21
- expected_snapshots = DropletKit::SnapshotMapping.extract_collection(snapshots_json, :read)
22
-
23
- expect(resource.all(resource_type: :droplet)).to eq(expected_snapshots)
24
- end
25
-
26
- it_behaves_like 'a paginated index' do
27
- let(:fixture_path) { 'snapshots/all' }
28
- let(:api_path) { '/v2/snapshots' }
29
- end
30
- end
31
-
32
- describe '#find' do
33
- it 'returns a singular snapshot' do
34
- stub_do_api('/v2/snapshots/7724db7c-e098-11e5-b522-000f53304e51', :get).to_return(body: api_fixture('snapshots/find'))
35
- snapshot = resource.find(id: "7724db7c-e098-11e5-b522-000f53304e51")
36
-
37
- expect(snapshot.id).to eq("7724db7c-e098-11e5-b522-000f53304e51")
38
- expect(snapshot.name).to eq("Ubuntu Foo")
39
- expect(snapshot.regions).to eq(["nyc1"])
40
- expect(snapshot.resource_type).to eq("volume")
41
- expect(snapshot.resource_id).to eq("7724db7c-e098-11e5-b522-000f53304e51")
42
- expect(snapshot.min_disk_size).to eq(10)
43
- expect(snapshot.size_gigabytes).to eq(0.4)
44
- end
45
-
46
- it_behaves_like 'resource that handles common errors' do
47
- let(:path) { '/v2/snapshots/123' }
48
- let(:method) { :get }
49
- let(:action) { :find }
50
- let(:arguments) { { id: 123 } }
51
- end
52
- end
53
-
54
- describe '#delete' do
55
- it 'deletes an snapshot' do
56
- request = stub_do_api('/v2/snapshots/146', :delete).to_return(body: '', status: 204)
57
- resource.delete(id: 146)
58
- expect(request).to have_been_made
59
- end
60
- end
61
- end
@@ -1,92 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::SSHKeyResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- describe '#all' do
8
- it 'returns a list of ssh keys' do
9
- stub_do_api('/v2/account/keys').to_return(body: api_fixture('ssh_keys/all'))
10
- ssh_keys = resource.all
11
-
12
- expect(ssh_keys).to all(be_kind_of(DropletKit::SSHKey))
13
-
14
- expect(ssh_keys.first.id).to eq(1)
15
- expect(ssh_keys.first.fingerprint).to eq("f5:d1:78:ed:28:72:5f:e1:ac:94:fd:1f:e0:a3:48:6d")
16
- expect(ssh_keys.first.public_key).to eq("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDGk5V68BJ4P3Ereh779Vi/Ft2qs/rbXrcjKLGo6zsyeyFUE0svJUpRDEJvFSf8RlezKx1/1ulJu9+kZsxRiUKn example")
17
- expect(ssh_keys.first.name).to eq("Example Key")
18
- end
19
-
20
- it_behaves_like 'a paginated index' do
21
- let(:fixture_path) {'ssh_keys/all'}
22
- let(:api_path) {'/v2/ssh_keys'}
23
- end
24
- end
25
-
26
- describe '#create' do
27
- it 'creates a ssh key in the users account' do
28
- ssh_key = DropletKit::SSHKey.new(name: 'Example Key', public_key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDbW5JSFLg70Z0/MNNUncNgfxnrHfjBSlWzyF3e+3tNLUVgGagZISnzF4Y03/aS79aiCmbd4vCEcxyB4Wxtpddh example')
29
-
30
- request = stub_do_api('/v2/account/keys', :post).with(
31
- body: DropletKit::SSHKeyMapping.representation_for(:create, ssh_key)
32
- ).to_return(body: api_fixture('ssh_keys/create'), status: 201)
33
-
34
- created_key = resource.create(ssh_key)
35
-
36
- expect(request).to have_been_made
37
-
38
- expect(created_key).to be_kind_of(DropletKit::SSHKey)
39
-
40
- expect(created_key.id).to eq(2)
41
- expect(created_key.fingerprint).to eq("bf:3a:82:fc:4a:25:0b:a3:23:97:fb:4e:e4:88:e1:0e")
42
- expect(created_key.public_key).to eq("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDbW5JSFLg70Z0/MNNUncNgfxnrHfjBSlWzyF3e+3tNLUVgGagZISnzF4Y03/aS79aiCmbd4vCEcxyB4Wxtpddh example")
43
- expect(created_key.name).to eq("Example Key")
44
- end
45
- end
46
-
47
- describe '#find' do
48
- it 'returns a single ssh key record' do
49
- stub_do_api('/v2/account/keys/123').to_return(body: api_fixture('ssh_keys/find'))
50
- ssh_key = resource.find(id: 123)
51
- expect(ssh_key.id).to eq(3)
52
- expect(ssh_key.fingerprint).to eq("32:af:23:06:21:fb:e6:5b:d3:cc:7f:b7:00:0f:79:aa")
53
- expect(ssh_key.public_key).to eq("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDZEgsAbWmQF+f8TU3F4fCg4yjVzdKudQbbhGb+qRKP5ju4Yo0Zzneia+oFm4bfzG+ydxUlOlbzq+Tpoj+INFv5 example")
54
- expect(ssh_key.name).to eq("Example Key")
55
- end
56
-
57
- it_behaves_like 'resource that handles common errors' do
58
- let(:path) { '/v2/account/keys/123' }
59
- let(:method) { :get }
60
- let(:action) { :find }
61
- let(:arguments) { { id: 123 } }
62
- end
63
- end
64
-
65
- describe '#update' do
66
- it 'updates the SSH key' do
67
- ssh_key = DropletKit::SSHKey.new(name: 'Example Key')
68
-
69
- request = stub_do_api('/v2/account/keys/123', :put).with(
70
- body: DropletKit::SSHKeyMapping.representation_for(:update, ssh_key)
71
- ).to_return(body: api_fixture('ssh_keys/update'), status: 200)
72
-
73
- updated_key = resource.update(ssh_key, id: 123)
74
-
75
- expect(request).to have_been_made
76
-
77
- expect(updated_key.id).to eq(123)
78
- expect(updated_key.fingerprint).to eq("32:af:23:06:21:fb:e6:5b:d3:cc:7f:b7:00:0f:79:aa")
79
- expect(updated_key.public_key).to eq("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDZEgsAbWmQF+f8TU3F4fCg4yjVzdKudQbbhGb+qRKP5ju4Yo0Zzneia+oFm4bfzG+ydxUlOlbzq+Tpoj+INFv5 example")
80
- expect(updated_key.name).to eq("Example Key")
81
- end
82
- end
83
-
84
- describe '#delete' do
85
- it 'deletes an SSH key' do
86
- request = stub_do_api('/v2/account/keys/123', :delete).to_return(status: 204)
87
- resource.delete(id: 123)
88
-
89
- expect(request).to have_been_made
90
- end
91
- end
92
- end
@@ -1,135 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe DropletKit::TagResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- RSpec::Matchers.define :match_tag_fixture do |expected|
8
- match do |actual|
9
- expect(actual).to be_kind_of(DropletKit::Tag)
10
- expect(actual.name).to eq('testing-1')
11
- end
12
- end
13
-
14
- describe '#all' do
15
- it 'returns all of the tags' do
16
- stub_do_api('/v2/tags', :get)
17
- .to_return(body: api_fixture('tags/all'))
18
- tags = resource.all
19
-
20
- expect(tags).to all(be_kind_of(DropletKit::Tag))
21
- expect(tags[0].name).to eq('testing-1')
22
- expect(tags[1].name).to eq('testing-2')
23
- end
24
-
25
- context 'when empty' do
26
- it 'returns an empty array of tags' do
27
- stub_do_api('/v2/tags', :get)
28
- .to_return(body: api_fixture('tags/all_empty'))
29
- tags = resource.all.map(&:id)
30
-
31
- expect(tags).to be_empty
32
- end
33
- end
34
-
35
- it_behaves_like 'a paginated index' do
36
- let(:fixture_path) { 'tags/all' }
37
- let(:api_path) { '/v2/tags' }
38
- end
39
- end
40
-
41
- describe '#find' do
42
- it 'returns a singular tag' do
43
- stub_do_api('/v2/tags/testing-1', :get)
44
- .to_return(body: api_fixture('tags/find'))
45
-
46
- tag = resource.find(name: 'testing-1')
47
-
48
- expect(tag).to be_kind_of(DropletKit::Tag)
49
- expect(tag).to match_tag_fixture
50
- expect(tag.resources.count).to eq(2)
51
- expect(tag.resources.droplets.count).to eq(1)
52
- expect(tag.resources.droplets.last_tagged).to be_kind_of(DropletKit::Droplet)
53
- expect(tag.resources.droplets.last_tagged.id).to eq(1)
54
- expect(tag.resources.droplets.last_tagged_uri).to eq('https://api.digitalocean.com/v2/droplets/1')
55
-
56
- expect(tag.resources.images.count).to eq(1)
57
- expect(tag.resources.images.attributes).to_not include(:last_tagged)
58
- expect(tag.resources.images.last_tagged_uri).to eq('https://api.digitalocean.com/v2/images/146')
59
- end
60
- end
61
-
62
- describe '#create' do
63
- it 'returns the created tag' do
64
- tag = DropletKit::Tag.new(name: 'testing-1')
65
-
66
- as_string = DropletKit::TagMapping.representation_for(:create, tag)
67
-
68
- stub_do_api('/v2/tags', :post).with(body: as_string)
69
- .to_return(body: api_fixture('tags/create'), status: 201)
70
- created_tag = resource.create(tag)
71
-
72
- expect(created_tag).to match_tag_fixture
73
- end
74
- end
75
-
76
- describe '#delete' do
77
- it 'deletes a tag' do
78
- request = stub_do_api('/v2/tags/testing-1', :delete)
79
- .to_return(body: '', status: 204)
80
-
81
- resource.delete(name: 'testing-1')
82
- expect(request).to have_been_made
83
- end
84
- end
85
-
86
- describe '#tag_resources' do
87
- it 'adds a tag' do
88
- params = {
89
- resources: [
90
- {
91
- resource_id: '1',
92
- resource_type: "droplet"
93
- },
94
- {
95
- resource_id: '146',
96
- resource_type: "images"
97
- }
98
- ]
99
- }
100
-
101
- request = stub_do_api('/v2/tags/testing-1/resources', :post)
102
- .with(body: params.to_json)
103
- .to_return(body: '', status: 204)
104
-
105
- resource.tag_resources(params.merge(name: 'testing-1'))
106
-
107
- expect(request).to have_been_made
108
- end
109
- end
110
-
111
- describe '#untag_resources' do
112
- it 'removes a tag' do
113
- params = {
114
- resources: [
115
- {
116
- resource_id: '1',
117
- resource_type: "droplet"
118
- },
119
- {
120
- resource_id: '146',
121
- resource_type: "images"
122
- }
123
- ]
124
- }
125
-
126
- request = stub_do_api('/v2/tags/testing-1/resources', :delete)
127
- .with(body: params.to_json)
128
- .to_return(body: '', status: 204)
129
-
130
- resource.untag_resources(params.merge(name: 'testing-1'))
131
-
132
- expect(request).to have_been_made
133
- end
134
- end
135
- end