gandi_v5 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +44 -2
  5. data/Guardfile +5 -6
  6. data/README.md +5 -5
  7. data/doc/GandiV5/Billing/Info/Prepaid.html +817 -0
  8. data/doc/GandiV5/Billing/Info.html +641 -0
  9. data/doc/GandiV5/Billing.html +293 -0
  10. data/doc/GandiV5/Data/ClassMethods.html +223 -0
  11. data/doc/GandiV5/Data/Converter/ArrayOf.html +413 -0
  12. data/doc/GandiV5/Data/Converter/Symbol.html +322 -0
  13. data/doc/GandiV5/Data/Converter/Time.html +330 -0
  14. data/doc/GandiV5/Data/Converter.html +433 -0
  15. data/doc/GandiV5/Data.html +785 -0
  16. data/doc/GandiV5/Domain/AutoRenew.html +1237 -0
  17. data/doc/GandiV5/Domain/Availability/Product/Period.html +220 -0
  18. data/doc/GandiV5/Domain/Availability/Product/Price.html +1031 -0
  19. data/doc/GandiV5/Domain/Availability/Product.html +988 -0
  20. data/doc/GandiV5/Domain/Availability/Tax.html +440 -0
  21. data/doc/GandiV5/Domain/Availability.html +1020 -0
  22. data/doc/GandiV5/Domain/Contact.html +4459 -0
  23. data/doc/GandiV5/Domain/Contract.html +520 -0
  24. data/doc/GandiV5/Domain/Dates.html +1313 -0
  25. data/doc/GandiV5/Domain/RenewalInformation.html +1147 -0
  26. data/doc/GandiV5/Domain/RestoreInformation.html +339 -0
  27. data/doc/GandiV5/Domain/SharingSpace.html +437 -0
  28. data/doc/GandiV5/Domain/TLD.html +1565 -0
  29. data/doc/GandiV5/Domain.html +16847 -0
  30. data/doc/GandiV5/Email/Mailbox/Responder.html +1560 -0
  31. data/doc/GandiV5/Email/Mailbox.html +6307 -0
  32. data/doc/GandiV5/Email/Offer.html +514 -0
  33. data/doc/GandiV5/Email/Slot.html +4244 -0
  34. data/doc/GandiV5/Email.html +144 -0
  35. data/doc/GandiV5/Error/GandiError.html +270 -0
  36. data/doc/GandiV5/Error.html +151 -0
  37. data/doc/GandiV5/LiveDNS/Domain.html +2984 -0
  38. data/doc/GandiV5/LiveDNS/RecordSet.html +1593 -0
  39. data/doc/GandiV5/LiveDNS/Zone/Snapshot.html +1556 -0
  40. data/doc/GandiV5/LiveDNS/Zone.html +8891 -0
  41. data/doc/GandiV5/LiveDNS.html +300 -0
  42. data/doc/GandiV5/Organization.html +2341 -0
  43. data/doc/GandiV5.html +1183 -0
  44. data/doc/_index.html +474 -0
  45. data/doc/class_list.html +51 -0
  46. data/doc/css/common.css +1 -0
  47. data/doc/css/full_list.css +58 -0
  48. data/doc/css/style.css +496 -0
  49. data/doc/file.README.html +175 -0
  50. data/doc/file_list.html +56 -0
  51. data/doc/frames.html +17 -0
  52. data/doc/index.html +175 -0
  53. data/doc/js/app.js +303 -0
  54. data/doc/js/full_list.js +216 -0
  55. data/doc/js/jquery.js +4 -0
  56. data/doc/method_list.html +2427 -0
  57. data/doc/top-level-namespace.html +110 -0
  58. data/gandi_v5.gemspec +1 -1
  59. data/lib/gandi_v5/billing.rb +2 -2
  60. data/lib/gandi_v5/data.rb +2 -0
  61. data/lib/gandi_v5/domain/auto_renew.rb +4 -4
  62. data/lib/gandi_v5/domain/availability/product/period.rb +24 -0
  63. data/lib/gandi_v5/domain/availability/product/price.rb +36 -0
  64. data/lib/gandi_v5/domain/availability/product.rb +52 -0
  65. data/lib/gandi_v5/domain/availability/tax.rb +20 -0
  66. data/lib/gandi_v5/domain/availability.rb +49 -0
  67. data/lib/gandi_v5/domain/tld.rb +57 -0
  68. data/lib/gandi_v5/domain.rb +41 -86
  69. data/lib/gandi_v5/email/mailbox/responder.rb +43 -2
  70. data/lib/gandi_v5/email/mailbox.rb +32 -21
  71. data/lib/gandi_v5/email/offer.rb +2 -2
  72. data/lib/gandi_v5/email/slot.rb +42 -16
  73. data/lib/gandi_v5/error/gandi_error.rb +2 -2
  74. data/lib/gandi_v5/live_dns/domain.rb +59 -45
  75. data/lib/gandi_v5/live_dns/zone/snapshot.rb +27 -8
  76. data/lib/gandi_v5/live_dns/zone.rb +63 -59
  77. data/lib/gandi_v5/live_dns.rb +20 -0
  78. data/lib/gandi_v5/organization.rb +2 -2
  79. data/lib/gandi_v5/version.rb +1 -1
  80. data/lib/gandi_v5.rb +25 -5
  81. data/spec/features/domain_spec.rb +1 -1
  82. data/spec/fixtures/bodies/{GandiV5_Domain/availability.yaml → GandiV5_Domain_Availability/fetch.yaml} +0 -0
  83. data/spec/fixtures/bodies/{GandiV5_Domain/tld.yaml → GandiV5_Domain_TLD/fetch.yaml} +0 -0
  84. data/spec/fixtures/bodies/{GandiV5_Domain/tlds.yaml → GandiV5_Domain_TLD/list.yaml} +0 -0
  85. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/{get.yaml → fetch.yaml} +0 -0
  86. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yaml +3 -0
  87. data/spec/units/gandi_v5/billing_spec.rb +2 -2
  88. data/spec/units/gandi_v5/domain/auto_renew_spec.rb +5 -5
  89. data/spec/units/gandi_v5/domain/availability/product/period_spec.rb +4 -0
  90. data/spec/units/gandi_v5/domain/availability/product/price_spec.rb +4 -0
  91. data/spec/units/gandi_v5/domain/availability/product_spec.rb +4 -0
  92. data/spec/units/gandi_v5/domain/availability/tax_spec.rb +4 -0
  93. data/spec/units/gandi_v5/domain/availability_spec.rb +43 -0
  94. data/spec/units/gandi_v5/domain/tld_spec.rb +29 -0
  95. data/spec/units/gandi_v5/domain_spec.rb +89 -81
  96. data/spec/units/gandi_v5/email/mailbox/responder_spec.rb +52 -0
  97. data/spec/units/gandi_v5/email/mailbox_spec.rb +56 -27
  98. data/spec/units/gandi_v5/email/offer_spec.rb +1 -1
  99. data/spec/units/gandi_v5/email/slot_spec.rb +101 -13
  100. data/spec/units/gandi_v5/live_dns/domain_spec.rb +70 -40
  101. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +32 -3
  102. data/spec/units/gandi_v5/live_dns/zone_spec.rb +68 -50
  103. data/spec/units/gandi_v5/live_dns_spec.rb +24 -0
  104. data/spec/units/gandi_v5/organization_spec.rb +1 -1
  105. data/spec/units/gandi_v5_spec.rb +37 -12
  106. metadata +72 -9
  107. data/TODO.md +0 -29
@@ -5,19 +5,32 @@ describe GandiV5::Email::Slot do
5
5
  described_class.new id: 123, capacity: 1, mailbox_type: :standard, status: :inactive, fqdn: 'example.com'
6
6
  end
7
7
 
8
- it '#delete' do
9
- expect(GandiV5).to receive(:delete).with('https://api.gandi.net/v5/email/slots/example.com/123')
10
- .and_return('message' => 'Confirmation message.')
11
- expect(subject.delete).to eq 'Confirmation message.'
8
+ describe '#delete' do
9
+ it 'Is deletable' do
10
+ subject = described_class.new fqdn: 'example.com', id: 123, status: :inactive, refundable: true
11
+ expect(GandiV5).to receive(:delete).with('https://api.gandi.net/v5/email/slots/example.com/123')
12
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
13
+ expect(subject.delete).to eq 'Confirmation message.'
14
+ end
15
+
16
+ it 'Is in use' do
17
+ subject = described_class.new fqdn: 'example.com', id: 123, status: :active, refundable: true
18
+ expect(GandiV5).to_not receive(:delete)
19
+ expect { subject.delete }.to raise_error GandiV5::Error, 'slot can\'t be deleted whilst active'
20
+ end
21
+
22
+ it 'Is not refundable' do
23
+ subject = described_class.new fqdn: 'example.com', id: 123, status: :inactive, refundable: false
24
+ expect(GandiV5).to_not receive(:delete)
25
+ expect { subject.delete }.to raise_error GandiV5::Error, 'slot can\'t be deleted if it\'s not refundable'
26
+ end
12
27
  end
13
- # TODO: check for inactiveness
14
- # TODO: check for refundableness
15
28
 
16
29
  describe '#refresh' do
17
30
  before :each do
18
31
  body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Slot', 'get.yaml'))
19
32
  expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/slots/example.com/123')
20
- .and_return(YAML.load_file(body_fixture))
33
+ .and_return([nil, YAML.load_file(body_fixture)])
21
34
  subject.refresh
22
35
  end
23
36
 
@@ -44,18 +57,93 @@ describe GandiV5::Email::Slot do
44
57
  end
45
58
  end
46
59
 
60
+ describe '#inactive?' do
61
+ it 'When active' do
62
+ slot = described_class.new status: :active
63
+ expect(slot.inactive?).to be false
64
+ end
65
+
66
+ it 'When inactive' do
67
+ slot = described_class.new status: :inactive
68
+ expect(slot.inactive?).to be true
69
+ end
70
+ end
71
+
72
+ describe '#free?' do
73
+ it 'When free' do
74
+ slot = described_class.new mailbox_type: :free
75
+ expect(slot.free?).to be true
76
+ end
77
+
78
+ it 'When standard' do
79
+ slot = described_class.new mailbox_type: :standard
80
+ expect(slot.free?).to be false
81
+ end
82
+
83
+ it 'When premium' do
84
+ slot = described_class.new mailbox_type: :premium
85
+ expect(slot.free?).to be false
86
+ end
87
+ end
88
+
89
+ describe '#standard?' do
90
+ it 'When free' do
91
+ slot = described_class.new mailbox_type: :free
92
+ expect(slot.standard?).to be false
93
+ end
94
+
95
+ it 'When standard' do
96
+ slot = described_class.new mailbox_type: :standard
97
+ expect(slot.standard?).to be true
98
+ end
99
+
100
+ it 'When premium' do
101
+ slot = described_class.new mailbox_type: :premium
102
+ expect(slot.standard?).to be false
103
+ end
104
+ end
105
+
106
+ describe '#premium?' do
107
+ it 'When free' do
108
+ slot = described_class.new mailbox_type: :free
109
+ expect(slot.premium?).to be false
110
+ end
111
+
112
+ it 'When standard' do
113
+ slot = described_class.new mailbox_type: :standard
114
+ expect(slot.premium?).to be false
115
+ end
116
+
117
+ it 'When premium' do
118
+ slot = described_class.new mailbox_type: :premium
119
+ expect(slot.premium?).to be true
120
+ end
121
+ end
122
+
47
123
  describe '.create' do
48
124
  let(:url) { 'https://api.gandi.net/v5/email/slots/example.com' }
125
+ let(:created_response) do
126
+ double(
127
+ RestClient::Response,
128
+ headers: { location: 'https://api.gandi.net/v5/email/slots/example.com/created-slot-uuid' }
129
+ )
130
+ end
131
+ let(:created_slot) { double GandiV5::Email::Slot }
132
+
49
133
  it 'With default type' do
50
134
  expect(GandiV5).to receive(:post).with(url, '{"mailbox_type":"standard"}')
51
- .and_return('message' => 'Confirmation message.')
52
- expect(described_class.create('example.com')).to eq 'Confirmation message.'
135
+ .and_return([created_response, { 'message' => 'Confirmation message.' }])
136
+ expect(described_class).to receive(:fetch).with('example.com', 'created-slot-uuid').and_return(created_slot)
137
+
138
+ expect(described_class.create('example.com')).to be created_slot
53
139
  end
54
140
 
55
141
  it 'With passed type' do
56
142
  expect(GandiV5).to receive(:post).with(url, '{"mailbox_type":"premium"}')
57
- .and_return('message' => 'Confirmation message.')
58
- expect(described_class.create('example.com', :premium)).to eq 'Confirmation message.'
143
+ .and_return([created_response, { 'message' => 'Confirmation message.' }])
144
+ expect(described_class).to receive(:fetch).with('example.com', 'created-slot-uuid').and_return(created_slot)
145
+
146
+ expect(described_class.create('example.com', :premium)).to be created_slot
59
147
  end
60
148
  end
61
149
 
@@ -65,7 +153,7 @@ describe GandiV5::Email::Slot do
65
153
  before :each do
66
154
  body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Slot', 'get.yaml'))
67
155
  expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/slots/example.com/123')
68
- .and_return(YAML.load_file(body_fixture))
156
+ .and_return([nil, YAML.load_file(body_fixture)])
69
157
  end
70
158
 
71
159
  its('fqdn') { should eq 'example.com' }
@@ -85,7 +173,7 @@ describe GandiV5::Email::Slot do
85
173
  before :each do
86
174
  body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Slot', 'list.yaml'))
87
175
  expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/slots/example.com')
88
- .and_return(YAML.load_file(body_fixture))
176
+ .and_return([nil, YAML.load_file(body_fixture)])
89
177
  end
90
178
 
91
179
  its('count') { should eq 1 }
@@ -9,7 +9,7 @@ describe GandiV5::LiveDNS::Domain do
9
9
  before :each do
10
10
  body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'get.yaml'))
11
11
  expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com')
12
- .and_return(YAML.load_file(body_fixture))
12
+ .and_return([nil, YAML.load_file(body_fixture)])
13
13
  subject.refresh
14
14
  end
15
15
 
@@ -20,14 +20,14 @@ describe GandiV5::LiveDNS::Domain do
20
20
  describe '#fetch_records' do
21
21
  it 'All of them' do
22
22
  expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records')
23
- .and_return([])
23
+ .and_return([nil, []])
24
24
 
25
25
  expect(subject.fetch_records).to eq []
26
26
  end
27
27
 
28
28
  it 'All for a name' do
29
29
  expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records/name')
30
- .and_return([])
30
+ .and_return([nil, []])
31
31
 
32
32
  expect(subject.fetch_records('name')).to eq []
33
33
  end
@@ -36,12 +36,15 @@ describe GandiV5::LiveDNS::Domain do
36
36
  expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT')
37
37
  .and_return(
38
38
  [
39
- {
40
- 'rrset_type' => 'TXT',
41
- 'rrset_name' => 'name',
42
- 'rrset_ttl' => 600,
43
- 'rrset_values' => %w[a b]
44
- }
39
+ nil,
40
+ [
41
+ {
42
+ 'rrset_type' => 'TXT',
43
+ 'rrset_name' => 'name',
44
+ 'rrset_ttl' => 600,
45
+ 'rrset_values' => %w[a b]
46
+ }
47
+ ]
45
48
  ]
46
49
  )
47
50
 
@@ -61,19 +64,19 @@ describe GandiV5::LiveDNS::Domain do
61
64
  describe '#fetch_zone_lines' do
62
65
  it 'All of them' do
63
66
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
64
- expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return('returned')
67
+ expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
65
68
  expect(subject.fetch_zone_lines).to eq 'returned'
66
69
  end
67
70
 
68
71
  it 'All for a name' do
69
72
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
70
- expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return('returned')
73
+ expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
71
74
  expect(subject.fetch_zone_lines('name')).to eq 'returned'
72
75
  end
73
76
 
74
77
  it 'A type for a name' do
75
78
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
76
- expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return('returned')
79
+ expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
77
80
  expect(subject.fetch_zone_lines('name', 'TXT')).to eq 'returned'
78
81
  end
79
82
 
@@ -86,7 +89,7 @@ describe GandiV5::LiveDNS::Domain do
86
89
  it 'Success' do
87
90
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
88
91
  body = '{"rrset_name":"name","rrset_type":"TXT","rrset_ttl":900,"rrset_values":["a","b"]}'
89
- expect(GandiV5).to receive(:post).with(url, body).and_return('message' => 'Confirmation message.')
92
+ expect(GandiV5).to receive(:post).with(url, body).and_return([nil, { 'message' => 'Confirmation message.' }])
90
93
  expect(subject.add_record('name', 'TXT', 900, 'a', 'b')).to eq 'Confirmation message.'
91
94
  end
92
95
 
@@ -112,19 +115,19 @@ describe GandiV5::LiveDNS::Domain do
112
115
  describe '#delete_records' do
113
116
  it 'All of them' do
114
117
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
115
- expect(GandiV5).to receive(:delete).with(url)
118
+ expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
116
119
  subject.delete_records
117
120
  end
118
121
 
119
122
  it 'All for a name' do
120
123
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
121
- expect(GandiV5).to receive(:delete).with(url)
124
+ expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
122
125
  subject.delete_records 'name'
123
126
  end
124
127
 
125
128
  it 'A type for a name' do
126
129
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
127
- expect(GandiV5).to receive(:delete).with(url)
130
+ expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
128
131
  subject.delete_records 'name', 'TXT'
129
132
  end
130
133
 
@@ -142,7 +145,7 @@ describe GandiV5::LiveDNS::Domain do
142
145
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
143
146
  body = '{"items":[{"rrset_name":"name","rrset_ttl":600,"rrset_type":"TXT","rrset_values":["a"]}]}'
144
147
  expect(GandiV5).to receive(:put).with(url, body)
145
- .and_return('message' => 'Confirmation message.')
148
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
146
149
  expect(subject.replace_records(records: records)).to eq 'Confirmation message.'
147
150
  end
148
151
 
@@ -154,7 +157,7 @@ describe GandiV5::LiveDNS::Domain do
154
157
 
155
158
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
156
159
  expect(GandiV5).to receive(:put).with(url, records, 'content-type': 'text/plain')
157
- .and_return('message' => 'Confirmation message.')
160
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
158
161
  expect(subject.replace_records(text: records)).to eq 'Confirmation message.'
159
162
  end
160
163
 
@@ -170,30 +173,35 @@ describe GandiV5::LiveDNS::Domain do
170
173
  end
171
174
  end
172
175
 
173
- it '#replace_records_for' do
174
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
175
- body = '{"items":[{"rrset_type":"TXT","rrset_values":["a"]}]}'
176
- expect(GandiV5).to receive(:put).with(url, body)
177
- .and_return('message' => 'Confirmation message.')
178
- records = { type: 'TXT', values: ['a'] }
179
- expect(subject.replace_records_for('name', records)).to eq 'Confirmation message.'
180
- end
176
+ describe '#replace_records_for' do
177
+ it 'Given no type or ttl' do
178
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
179
+ body = '{"items":[{"rrset_type":"TXT","rrset_values":["a"]}]}'
180
+ expect(GandiV5).to receive(:put).with(url, body)
181
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
182
+ records = [{ type: 'TXT', values: ['a'] }]
183
+ expect(subject.replace_records_for('name', records)).to eq 'Confirmation message.'
184
+ end
181
185
 
182
- describe '#replace_??_records_for' do
183
- it '#replace_a_records_for' do
184
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/A'
185
- body = '{"rrset_ttl":600,"rrset_values":["192.168.0.1","192.168.0.2"]}'
186
+ it 'Given type and ttl' do
187
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
188
+ body = '{"rrset_values":["a"],"rrset_ttl":600}'
186
189
  expect(GandiV5).to receive(:put).with(url, body)
187
- .and_return('message' => 'Confirmation message.')
188
- expect(subject.replace_a_records_for('name', 600, '192.168.0.1', '192.168.0.2')).to eq 'Confirmation message.'
190
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
191
+ expect(subject.replace_records_for('name', ['a'], type: 'TXT', ttl: 600)).to eq 'Confirmation message.'
189
192
  end
190
193
 
191
- it '#replace_txt_records_for' do
194
+ it 'Given type but no ttl' do
192
195
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
193
- body = '{"rrset_ttl":600,"rrset_values":["a","b"]}'
196
+ body = '{"rrset_values":["a"],"rrset_ttl":null}'
194
197
  expect(GandiV5).to receive(:put).with(url, body)
195
- .and_return('message' => 'Confirmation message.')
196
- expect(subject.replace_txt_records_for('name', 600, 'a', 'b')).to eq 'Confirmation message.'
198
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
199
+ expect(subject.replace_records_for('name', ['a'], type: 'TXT')).to eq 'Confirmation message.'
200
+ end
201
+
202
+ it 'Given ttl but no type' do
203
+ expect(GandiV5).to_not receive(:put)
204
+ expect { subject.replace_records_for 'name', 'a', ttl: 600 }.to raise_error ArgumentError, 'missing keyword: type'
197
205
  end
198
206
  end
199
207
 
@@ -202,7 +210,7 @@ describe GandiV5::LiveDNS::Domain do
202
210
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com'
203
211
  body = '{"zone_uuid":"zone-uuid"}'
204
212
  expect(GandiV5).to receive(:patch).with(url, body)
205
- .and_return('message' => 'Confirmation message.')
213
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
206
214
  expect(subject.change_zone('zone-uuid')).to eq 'Confirmation message.'
207
215
  expect(subject.zone_uuid).to eq 'zone-uuid'
208
216
  end
@@ -211,20 +219,42 @@ describe GandiV5::LiveDNS::Domain do
211
219
  url = 'https://dns.api.gandi.net/api/v5/domains/example.com'
212
220
  body = '{"zone_uuid":"zone-uuid"}'
213
221
  expect(GandiV5).to receive(:patch).with(url, body)
214
- .and_return('message' => 'Confirmation message.')
222
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
215
223
  zone = double GandiV5::LiveDNS::Zone, uuid: 'zone-uuid'
216
224
  expect(subject.change_zone(zone)).to eq 'Confirmation message.'
217
225
  expect(subject.zone_uuid).to eq 'zone-uuid'
218
226
  end
219
227
  end
220
228
 
229
+ it '#fetch_zone' do
230
+ returns = double GandiV5::LiveDNS::Zone
231
+ expect(GandiV5::LiveDNS::Zone).to receive(:fetch).with('zone-uuid')
232
+ .and_return(returns)
233
+ expect(subject.fetch_zone).to be returns
234
+ end
235
+
236
+ describe '#zone' do
237
+ it 'Not previously fetched' do
238
+ returns = double GandiV5::LiveDNS::Zone
239
+ expect(subject).to receive(:fetch_zone).and_return(returns)
240
+ expect(subject.zone).to be returns
241
+ end
242
+
243
+ it 'Previously fetched' do
244
+ returns = double GandiV5::LiveDNS::Zone
245
+ subject.instance_exec { @zone = returns }
246
+ expect(subject).to_not receive(:fetch_zone)
247
+ expect(subject.zone).to be returns
248
+ end
249
+ end
250
+
221
251
  describe '.list' do
222
252
  subject { described_class.list }
223
253
 
224
254
  before :each do
225
255
  body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'list.yaml'))
226
256
  expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains')
227
- .and_return(YAML.load_file(body_fixture))
257
+ .and_return([nil, YAML.load_file(body_fixture)])
228
258
  end
229
259
 
230
260
  its('count') { should eq 1 }
@@ -238,7 +268,7 @@ describe GandiV5::LiveDNS::Domain do
238
268
  before :each do
239
269
  body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'get.yaml'))
240
270
  expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com')
241
- .and_return(YAML.load_file(body_fixture))
271
+ .and_return([nil, YAML.load_file(body_fixture)])
242
272
  end
243
273
 
244
274
  its('fqdn') { should eq 'example.com' }
@@ -12,17 +12,46 @@ describe GandiV5::LiveDNS::Zone::Snapshot do
12
12
 
13
13
  it '#delete' do
14
14
  expect(GandiV5).to receive(:delete).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/snapshots/snapshot-uuid')
15
- .and_return('message' => 'Confirmation message.')
15
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
16
16
  expect(subject.delete).to eq 'Confirmation message.'
17
17
  end
18
18
 
19
+ it '#fetch_zone' do
20
+ returns = double GandiV5::LiveDNS::Zone
21
+ expect(GandiV5::LiveDNS::Zone).to receive(:fetch).with('zone-uuid')
22
+ .and_return(returns)
23
+ expect(subject.fetch_zone).to be returns
24
+ end
25
+
26
+ describe '#zone' do
27
+ it 'Not previously fetched' do
28
+ returns = double GandiV5::LiveDNS::Zone
29
+ expect(subject).to receive(:fetch_zone).and_return(returns)
30
+ expect(subject.zone).to be returns
31
+ end
32
+
33
+ it 'Previously fetched' do
34
+ returns = double GandiV5::LiveDNS::Zone
35
+ subject.instance_exec { @zone = returns }
36
+ expect(subject).to_not receive(:fetch_zone)
37
+ expect(subject.zone).to be returns
38
+ end
39
+ end
40
+
41
+ it '.list' do
42
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Zone_Snapshot', 'list.yaml'))
43
+ expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/snapshots')
44
+ .and_return([nil, YAML.load_file(body_fixture)])
45
+ expect(described_class.list('zone-uuid')).to eq('snapshot-uuid' => Time.new(2016, 12, 16, 16, 51, 26, 0))
46
+ end
47
+
19
48
  describe '.fetch' do
20
49
  subject { described_class.fetch 'zone-uuid', 'snapshot-uuid' }
21
50
 
22
51
  before :each do
23
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Zone_Snapshot', 'get.yaml'))
52
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Zone_Snapshot', 'fetch.yaml'))
24
53
  expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/snapshots/snapshot-uuid')
25
- .and_return(YAML.load_file(body_fixture))
54
+ .and_return([nil, YAML.load_file(body_fixture)])
26
55
  end
27
56
 
28
57
  its('created_at') { should eq Time.new(2016, 12, 16, 16, 51, 26, 0) }