akamai_api 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -0
  3. data/.yardopts +4 -0
  4. data/Gemfile +16 -0
  5. data/README.md +53 -52
  6. data/Thorfile +7 -1
  7. data/akamai_api.gemspec +1 -7
  8. data/bin/akamai_api +2 -1
  9. data/cassettes/akamai_api_ccu_arl_invalidate/invalid_credentials.yml +1 -1
  10. data/cassettes/akamai_api_ccu_arl_invalidate/invalid_item.yml +1 -1
  11. data/cassettes/akamai_api_ccu_arl_invalidate/multiple_items.yml +1 -1
  12. data/cassettes/akamai_api_ccu_arl_invalidate/single_item.yml +1 -1
  13. data/cassettes/akamai_api_ccu_arl_remove/invalid_credentials.yml +1 -1
  14. data/cassettes/akamai_api_ccu_arl_remove/invalid_item.yml +2 -2
  15. data/cassettes/akamai_api_ccu_arl_remove/multiple_items.yml +1 -1
  16. data/cassettes/akamai_api_ccu_arl_remove/single_item.yml +1 -1
  17. data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_credentials.yml +1 -1
  18. data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_item.yml +1 -1
  19. data/cassettes/akamai_api_ccu_cpcode_invalidate/multiple_items.yml +1 -1
  20. data/cassettes/akamai_api_ccu_cpcode_invalidate/single_item.yml +1 -1
  21. data/cassettes/akamai_api_ccu_cpcode_remove/invalid_credentials.yml +1 -1
  22. data/cassettes/akamai_api_ccu_cpcode_remove/invalid_item.yml +1 -1
  23. data/cassettes/akamai_api_ccu_cpcode_remove/multiple_items.yml +1 -1
  24. data/cassettes/akamai_api_ccu_cpcode_remove/single_item.yml +1 -1
  25. data/cassettes/akamai_api_eccu_all_ids/invalid_credentials.yml +68 -0
  26. data/cassettes/akamai_api_eccu_all_ids/successful.yml +72 -0
  27. data/cassettes/akamai_api_eccu_destroy/invalid_credentials.yml +69 -0
  28. data/cassettes/akamai_api_eccu_destroy/not_found_request.yml +55 -0
  29. data/cassettes/akamai_api_eccu_destroy/successful.yml +57 -0
  30. data/cassettes/akamai_api_eccu_find/invalid_credentials.yml +69 -0
  31. data/cassettes/akamai_api_eccu_find/not_found_request.yml +55 -0
  32. data/cassettes/akamai_api_eccu_find/successful.yml +70 -0
  33. data/cassettes/akamai_api_eccu_find/successful_without_content.yml +70 -0
  34. data/cassettes/akamai_api_eccu_publish/invalid_credentials.yml +5 -5
  35. data/cassettes/akamai_api_eccu_publish/invalid_domain.yml +7 -7
  36. data/cassettes/akamai_api_eccu_publish/successful.yml +8 -8
  37. data/cassettes/akamai_api_eccu_update_email/invalid_credentials.yml +69 -0
  38. data/cassettes/akamai_api_eccu_update_email/not_found_request.yml +55 -0
  39. data/cassettes/akamai_api_eccu_update_email/successful.yml +57 -0
  40. data/cassettes/akamai_api_eccu_update_notes/invalid_credentials.yml +70 -0
  41. data/cassettes/akamai_api_eccu_update_notes/not_found_request.yml +56 -0
  42. data/cassettes/akamai_api_eccu_update_notes/successful.yml +58 -0
  43. data/features/ccu_arl_invalidate.feature +5 -9
  44. data/features/ccu_arl_remove.feature +5 -9
  45. data/features/ccu_cpcode_invalidate.feature +2 -6
  46. data/features/ccu_cpcode_remove.feature +2 -6
  47. data/features/ccu_purge_status.feature +2 -2
  48. data/features/eccu_publish.feature +6 -42
  49. data/features/step_definitions/file_named_with_content_steps.rb +3 -0
  50. data/features/support/env.rb +12 -3
  51. data/lib/akamai_api/ccu/base_response.rb +27 -0
  52. data/lib/akamai_api/ccu/error.rb +38 -0
  53. data/lib/akamai_api/ccu/purge/request.rb +58 -11
  54. data/lib/akamai_api/ccu/purge/response.rb +15 -9
  55. data/lib/akamai_api/ccu/purge.rb +14 -3
  56. data/lib/akamai_api/ccu/purge_status/not_found.rb +18 -0
  57. data/lib/akamai_api/ccu/purge_status/request.rb +41 -7
  58. data/lib/akamai_api/ccu/purge_status/response.rb +49 -3
  59. data/lib/akamai_api/ccu/purge_status.rb +17 -9
  60. data/lib/akamai_api/ccu/status/request.rb +20 -7
  61. data/lib/akamai_api/ccu/status/response.rb +8 -2
  62. data/lib/akamai_api/ccu/status.rb +13 -2
  63. data/lib/akamai_api/ccu/unrecognized_option.rb +6 -0
  64. data/lib/akamai_api/ccu.rb +132 -23
  65. data/lib/akamai_api/cli/app.rb +15 -13
  66. data/lib/akamai_api/cli/ccu/arl.rb +10 -4
  67. data/lib/akamai_api/cli/ccu/base.rb +11 -3
  68. data/lib/akamai_api/cli/ccu/cp_code.rb +10 -4
  69. data/lib/akamai_api/cli/ccu/purge_renderer.rb +1 -1
  70. data/lib/akamai_api/cli/ccu/status_renderer.rb +46 -26
  71. data/lib/akamai_api/cli/ccu.rb +2 -4
  72. data/lib/akamai_api/cli/command.rb +60 -25
  73. data/lib/akamai_api/cli/eccu/base.rb +59 -0
  74. data/lib/akamai_api/cli/eccu/entry_renderer.rb +5 -3
  75. data/lib/akamai_api/cli/eccu.rb +2 -56
  76. data/lib/akamai_api/cli.rb +2 -6
  77. data/lib/akamai_api/eccu/base_edit_request.rb +51 -0
  78. data/lib/akamai_api/eccu/base_request.rb +32 -0
  79. data/lib/akamai_api/eccu/destroy_request.rb +30 -0
  80. data/lib/akamai_api/eccu/find_request.rb +45 -0
  81. data/lib/akamai_api/eccu/find_response.rb +110 -0
  82. data/lib/akamai_api/eccu/invalid_domain.rb +7 -0
  83. data/lib/akamai_api/eccu/list_request.rb +21 -0
  84. data/lib/akamai_api/eccu/not_found.rb +6 -0
  85. data/lib/akamai_api/eccu/publish_request.rb +75 -0
  86. data/lib/akamai_api/eccu/soap_body.rb +99 -0
  87. data/lib/akamai_api/eccu/update_attribute_request.rb +62 -0
  88. data/lib/akamai_api/eccu.rb +19 -0
  89. data/lib/akamai_api/eccu_request.rb +39 -117
  90. data/lib/akamai_api/error.rb +5 -0
  91. data/lib/akamai_api/unauthorized.rb +6 -0
  92. data/lib/akamai_api/version.rb +1 -1
  93. data/lib/akamai_api.rb +18 -4
  94. data/spec/features/ccu/purge_request_spec.rb +10 -12
  95. data/spec/features/ccu/purge_status_request_spec.rb +5 -5
  96. data/spec/features/ccu/status_request_spec.rb +3 -3
  97. data/spec/features/eccu/destroy_spec.rb +28 -0
  98. data/spec/features/eccu/find_request_spec.rb +34 -0
  99. data/spec/features/eccu/list_request_spec.rb +22 -0
  100. data/spec/features/eccu/publish_request_spec.rb +29 -0
  101. data/spec/features/eccu/update_email_spec.rb +28 -0
  102. data/spec/features/eccu/update_notes_spec.rb +28 -0
  103. data/spec/lib/akamai_api/ccu/{response_spec.rb → base_response_spec.rb} +2 -2
  104. data/spec/lib/akamai_api/ccu/purge/request_spec.rb +26 -20
  105. data/spec/lib/akamai_api/ccu/purge/response_spec.rb +16 -26
  106. data/spec/lib/akamai_api/ccu/purge_status/not_found_response_spec.rb +34 -34
  107. data/spec/lib/akamai_api/ccu/purge_status/request_spec.rb +24 -12
  108. data/spec/lib/akamai_api/ccu/purge_status/{successful_response_spec.rb → response_spec.rb} +8 -8
  109. data/spec/lib/akamai_api/ccu/status/request_spec.rb +6 -6
  110. data/spec/lib/akamai_api/ccu/status/response_spec.rb +2 -2
  111. data/spec/lib/akamai_api/ccu_spec.rb +7 -7
  112. data/spec/lib/akamai_api/cli/ccu/status_renderer_spec.rb +5 -17
  113. data/spec/lib/akamai_api/eccu/destroy_request_spec.rb +75 -0
  114. data/spec/lib/akamai_api/eccu/find_request_spec.rb +74 -0
  115. data/spec/lib/akamai_api/eccu/find_response_spec.rb +159 -0
  116. data/spec/lib/akamai_api/eccu/list_request_spec.rb +43 -0
  117. data/spec/lib/akamai_api/eccu/publish_request_spec.rb +133 -0
  118. data/spec/lib/akamai_api/eccu/soap_body_spec.rb +46 -0
  119. data/spec/lib/akamai_api/eccu/update_attribute_request_spec.rb +86 -0
  120. data/spec/lib/akamai_api/eccu_request_spec.rb +149 -158
  121. data/spec/spec_helper.rb +11 -3
  122. metadata +90 -104
  123. data/lib/akamai_api/ccu/purge_status/not_found_response.rb +0 -9
  124. data/lib/akamai_api/ccu/purge_status/successful_response.rb +0 -25
  125. data/lib/akamai_api/ccu/response.rb +0 -18
  126. data/lib/akamai_api/soap_body.rb +0 -40
  127. data/spec/lib/akamai_api/soap_body_spec.rb +0 -48
  128. data/spec/support/savon_backports.rb +0 -10
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module AkamaiApi
4
- describe EccuRequest do
4
+ describe ECCURequest do
5
5
  include Savon::SpecHelper
6
6
 
7
7
  before(:all) { savon.mock! }
@@ -14,69 +14,68 @@ module AkamaiApi
14
14
  end
15
15
 
16
16
  it 'returns the id list of all available requests' do
17
- EccuRequest.all_ids.should =~ ['42994282', '43000154']
17
+ expect(ECCURequest.all_ids).to match_array ['42994282', '43000154']
18
18
  end
19
19
  end
20
20
 
21
21
  describe '::find' do
22
- let(:fixture) { File.read 'spec/fixtures/eccu/get_info/successful.xml' }
22
+ subject { ECCURequest }
23
23
 
24
- def soap_body id, verbose
25
- SoapBody.new do
26
- integer :fileId, id
27
- boolean :retrieveContents, verbose
28
- end
24
+ it 'delegates to FindRequest' do
25
+ fake_request = double
26
+ expect(fake_request).to receive(:execute).with(true).and_return AkamaiApi::ECCU::FindResponse.new({})
27
+ expect(AkamaiApi::ECCU::FindRequest).to receive(:new).with('1234').and_return fake_request
28
+ subject.find '1234'
29
29
  end
30
30
 
31
- context 'when calling the ECCU service' do
32
- it 'sets the specified code and verbosity' do
33
- body = soap_body(1234567, false).to_s
34
- savon.expects(:get_info).with(:message => body).returns(fixture)
35
- EccuRequest.find('1234567')
36
- end
37
-
38
- it 'sets to return file content if verbose is specified' do
39
- body = soap_body(1234567, true).to_s
40
- savon.expects(:get_info).with(:message => body).returns(fixture)
41
- EccuRequest.find('1234567', :verbose => true)
42
- end
31
+ it "returns an ECCURequest" do
32
+ response = AkamaiApi::ECCU::FindResponse.new({})
33
+ expect_any_instance_of(AkamaiApi::ECCU::FindRequest).to receive(:execute).and_return response
34
+ subject.find '1234'
43
35
  end
44
36
 
45
- it 'correctly assign the exact match' do
46
- body = soap_body(1234567, false).to_s
47
- savon.expects(:get_info).with(:message => body).returns(fixture)
48
- r = EccuRequest.find('1234567')
49
- r.property[:exact_match].should be_true
37
+ {
38
+ file: :file,
39
+ status: :status,
40
+ code: :code,
41
+ notes: :notes,
42
+ property: :property,
43
+ email: :email,
44
+ upload_date: :uploaded_at,
45
+ uploaded_by: :uploaded_by,
46
+ version: :version
47
+ }.each do |local_name, remote_name|
48
+ it "maps response '#{remote_name}' to '#{local_name}'" do
49
+ response = AkamaiApi::ECCU::FindResponse.new({})
50
+ allow(response).to receive(remote_name) { "foobarbaz" }
51
+ expect_any_instance_of(AkamaiApi::ECCU::FindRequest).to receive(:execute).and_return response
52
+ expect(subject.find('1234').send local_name).to eq "foobarbaz"
53
+ end
50
54
  end
51
55
  end
52
56
 
53
57
  describe '::last' do
54
58
  it 'find the most recent entry' do
55
- EccuRequest.stub :all_ids => %w(a b)
56
- EccuRequest.should_receive(:find).with('b', anything()).and_return :a
57
- EccuRequest.last.should == :a
59
+ allow(ECCURequest).to receive(:all_ids) { %w(a b) }
60
+ allow(ECCURequest).to receive(:find).with('b', anything()).and_return :a
61
+ expect(ECCURequest.last).to eq :a
58
62
  end
59
63
  end
60
64
 
61
65
  describe '::first' do
62
66
  it 'find the oldest entry' do
63
- EccuRequest.stub :all_ids => %w(a b)
64
- EccuRequest.should_receive(:find).with('a', anything()).and_return :a
65
- EccuRequest.first.should == :a
67
+ allow(ECCURequest).to receive(:all_ids) { %w(a b) }
68
+ allow(ECCURequest).to receive(:find).with('a', anything()).and_return :a
69
+ expect(ECCURequest.first).to eq :a
66
70
  end
67
71
  end
68
72
 
69
73
  describe '::all' do
70
74
  it 'returns the detail for each enlisted id' do
71
- EccuRequest.stub :all_ids => %w(a b)
72
- EccuRequest.should_receive(:find).with('a', anything()).and_return(:a)
73
- EccuRequest.should_receive(:find).with('b', anything()).and_return(:b)
74
- EccuRequest.all.should =~ [:a, :b]
75
- end
76
- it 'returns the detail for each enlisted id even if only one id is returned' do
77
- EccuRequest.stub :all_ids => "a"
78
- EccuRequest.should_receive(:find).with('a', anything()).and_return(:a)
79
- EccuRequest.all.should =~ [:a]
75
+ allow(ECCURequest).to receive(:all_ids) { %w(a b) }
76
+ allow(ECCURequest).to receive(:find).with('a', anything()).and_return(:a)
77
+ allow(ECCURequest).to receive(:find).with('b', anything()).and_return(:b)
78
+ expect(ECCURequest.all).to match_array [:a, :b]
80
79
  end
81
80
  end
82
81
 
@@ -87,80 +86,44 @@ module AkamaiApi
87
86
  describe '::publish_file' do
88
87
  it 'calls publish with the content of the specified file' do
89
88
  args = {}
90
- EccuRequest.should_receive(:publish).with('foo', xml_request_content, args)
91
- EccuRequest.publish_file('foo', xml_request, args)
89
+ allow(ECCURequest).to receive(:publish).with('foo', xml_request_content, args)
90
+ ECCURequest.publish_file('foo', xml_request, args)
92
91
  end
93
92
  end
94
93
 
95
94
  describe '::publish' do
96
- context 'when there is an error' do
97
- before do
98
- fixture = File.read 'spec/fixtures/eccu/upload/fault.xml'
99
- savon.expects(:upload).with(:message => :any).returns(fixture)
100
- end
95
+ let(:subject) { ECCURequest }
101
96
 
102
- it 'raises an error' do
103
- expect { EccuRequest.publish '', xml_request_content }.to raise_error Savon::SOAPFault
104
- end
97
+ it 'does not alter given arguments' do
98
+ expect_any_instance_of(AkamaiApi::ECCU::PublishRequest).to receive :execute
99
+ args = { property_type: 'asd' }
100
+ expect { subject.publish 'foo.com', 'asd', args }.to_not change args, :count
105
101
  end
106
102
 
107
- context 'when there are no errors' do
108
- let(:fixture) { File.read 'spec/fixtures/eccu/upload/successful.xml' }
109
-
110
- it 'returns an EccuRequest instance' do
111
- savon.expects(:upload).with(:message => :any).returns(fixture)
112
- EccuRequest.publish('', xml_request_content).should be_a Fixnum
113
- end
114
-
115
- it 'assigns the fields correctly' do
116
- content = xml_request_content
117
- body = SoapBody.new do
118
- string :filename, 'eccu_request.xml'
119
- text :contents, content
120
- string :notes, 'sample notes'
121
- string :versionString, 'v2'
122
- string :statusChangeEmail, 'foo@foo.com bar@bar.com'
123
- string :propertyName, 'foo.com'
124
- string :propertyType, 'prop'
125
- boolean :propertyNameExactMatch, false
126
- end
127
- savon.expects(:upload).with(:message => body.to_s).returns(fixture)
128
- EccuRequest.publish('foo.com', xml_request_content, {
129
- :file_name => 'eccu_request.xml',
130
- :notes => 'sample notes',
131
- :version => 'v2',
132
- :emails => %w(foo@foo.com bar@bar.com),
133
- :property_type => 'prop',
134
- :property_exact_match => false
135
- })
136
- end
103
+ it 'correctly builds a PublishRequest' do
104
+ expected_args = ['foo.com', { type: 'hostheader', exact_match: true }]
105
+ expect(AkamaiApi::ECCU::PublishRequest).to receive(:new).with(*expected_args).and_return double(execute: nil)
106
+ subject.publish 'foo.com', 'asd', property_type: 'hostheader', property_exact_match: true
107
+ end
137
108
 
138
- it 'assigns a default notes field if no notes are specified' do
139
- SoapBody.any_instance.stub :string => nil
140
- SoapBody.any_instance.should_receive(:string).with(:notes, kind_of(String))
141
- savon.expects(:upload).with(:message => :any).returns(fixture)
142
- EccuRequest.publish '', xml_request_content
143
- end
109
+ it 'does not pass nil values to constructor arguments' do
110
+ expect(AkamaiApi::ECCU::PublishRequest).to receive(:new).with('foo.com', {}).and_return double(execute: nil)
111
+ subject.publish 'foo.com', 'asd', property_type: nil, property_exact_match: nil
112
+ end
144
113
 
145
- it 'assigns emails field if specified' do
146
- SoapBody.any_instance.should_not_receive(:string).with(:statusChangeEmail, anything())
147
- savon.expects(:upload).with(:message => :any).returns(fixture)
148
- EccuRequest.publish '', xml_request_content
149
- end
114
+ it 'delegates to PublishRequest#execute' do
115
+ expect_any_instance_of(AkamaiApi::ECCU::PublishRequest).to receive(:execute).and_return 1
116
+ expect(subject.publish 'foo.com', 'asd').to eq 1
117
+ end
150
118
 
151
- it 'assigns the property type to hostheader by default' do
152
- SoapBody.any_instance.stub :string => nil
153
- SoapBody.any_instance.should_receive(:string).with(:propertyType, 'hostheader')
154
- savon.expects(:upload).with(:message => :any).returns(fixture)
155
- EccuRequest.publish '', xml_request_content
156
- end
119
+ it 'pass content and given arguments to execute' do
120
+ expect_any_instance_of(AkamaiApi::ECCU::PublishRequest).to receive(:execute).with 'asd', emails: 'foo@bar.com'
121
+ subject.publish 'foo.com', 'asd', emails: 'foo@bar.com'
122
+ end
157
123
 
158
- it 'assigns the property exact match to true by default' do
159
- SoapBody.any_instance.stub :boolean => nil
160
- SoapBody.any_instance.should_receive(:boolean).with(:propertyNameExactMatch, true)
161
- savon.expects(:upload).with(:message => :any).returns(fixture)
162
- EccuRequest.publish '', xml_request_content
163
- end
124
+ it 'removed unnecessary arguments when calling execute' do
125
+ expect_any_instance_of(AkamaiApi::ECCU::PublishRequest).to receive(:execute).with 'asd', emails: 'foo@bar.com'
126
+ subject.publish 'foo.com', 'asd', emails: 'foo@bar.com', property_exact_match: false
164
127
  end
165
128
  end
166
129
  end
@@ -168,90 +131,118 @@ module AkamaiApi
168
131
  describe 'instance' do
169
132
  describe 'constructor' do
170
133
  it 'assigns the attributes hash to the accessors' do
171
- req = EccuRequest.new :status => 'foo', :notes => 'bar'
172
- req.status.should == 'foo'
173
- req.notes.should == 'bar'
134
+ req = ECCURequest.new :status => 'foo', :notes => 'bar'
135
+ expect(req.status).to eq 'foo'
136
+ expect(req.notes).to eq 'bar'
174
137
  end
175
138
  end
176
139
 
177
140
  describe '#update_notes!' do
178
- let(:fixture) { File.read 'spec/fixtures/eccu/set_notes/successful.xml' }
179
-
180
- it 'updates the notes field' do
181
- savon.expects(:set_notes).with(:message => :any).returns(fixture)
182
- req = EccuRequest.new :code => '1234'
183
- expect {
184
- req.update_notes! 'foo'
185
- }.to change(req, :notes).to 'foo'
141
+ subject { ECCURequest.new code: '1234' }
142
+
143
+ it 'delegates to UpdateAttributeRequest' do
144
+ fake_request = double
145
+ expect(fake_request).to receive(:execute).with('foo').and_return true
146
+ expect(AkamaiApi::ECCU::UpdateAttributeRequest).to receive(:new).with('1234', :notes).and_return fake_request
147
+ subject.update_notes! 'foo'
186
148
  end
187
149
 
188
- it 'calls the ECCU service using code and notes' do
189
- body = SoapBody.new do
190
- integer :fileId, 1234
191
- string :notes, 'foo'
150
+ context 'when the update is successful' do
151
+ before do
152
+ expect_any_instance_of(AkamaiApi::ECCU::UpdateAttributeRequest).to receive(:execute).and_return true
153
+ end
154
+
155
+ it "returns true" do
156
+ expect(subject.update_notes! 'foo').to be_truthy
157
+ end
158
+
159
+ it "updates notes attribute" do
160
+ expect { subject.update_notes! 'foo' }.to change(subject, :notes).to 'foo'
192
161
  end
193
- savon.expects(:set_notes).with(:message => body.to_s).returns(fixture)
194
- EccuRequest.new(:code => '1234').update_notes! 'foo'
195
162
  end
196
163
 
197
- it 'calls the ECCU service and return the service boolean response' do
198
- savon.expects(:set_notes).with(:message => :any).returns(fixture)
199
- EccuRequest.new(:code => '1234').update_notes!('foo').should be_true
164
+ context 'when the update is not successful' do
165
+ before do
166
+ expect_any_instance_of(AkamaiApi::ECCU::UpdateAttributeRequest).to receive(:execute).and_return false
167
+ end
168
+
169
+ it "returns false" do
170
+ expect(subject.update_notes! 'foo').to be_falsy
171
+ end
172
+
173
+ it "does not update the notes attribute" do
174
+ expect { subject.update_notes! 'foo' }.to_not change { subject.notes }
175
+ end
200
176
  end
201
177
  end
202
178
 
203
- describe '#update_email' do
204
- let(:fixture) { File.read 'spec/fixtures/eccu/set_status_change_email/successful.xml' }
179
+ describe '#update_email!' do
180
+ subject { ECCURequest.new code: '1234' }
205
181
 
206
- it 'updates the email field' do
207
- savon.expects(:set_status_change_email).with(:message => :any).returns(fixture)
208
- req = EccuRequest.new :code => '1234'
209
- expect {
210
- req.update_email! 'foo'
211
- }.to change(req, :email).to 'foo'
182
+ it 'delegates to UpdateEmailRequest' do
183
+ fake_request = double
184
+ expect(fake_request).to receive(:execute).with('foo').and_return true
185
+ expect(AkamaiApi::ECCU::UpdateAttributeRequest).to receive(:new).with('1234', :status_change_email).and_return fake_request
186
+ subject.update_email! 'foo'
212
187
  end
213
188
 
214
- it 'calls the ECCU service using code and email' do
215
- body = SoapBody.new do
216
- integer :fileId, 1234
217
- string :statusChangeEmail, 'foo'
189
+ context 'when the update is successful' do
190
+ before do
191
+ expect_any_instance_of(AkamaiApi::ECCU::UpdateAttributeRequest).to receive(:execute).and_return true
192
+ end
193
+
194
+ it "returns true" do
195
+ expect(subject.update_email! 'foo').to be_truthy
218
196
  end
219
- savon.expects(:set_status_change_email).with(:message => body.to_s).returns(fixture)
220
- EccuRequest.new(:code => '1234').update_email! 'foo'
221
- end
222
197
 
223
- it 'calls the ECCU service and return the service boolean response' do
224
- savon.expects(:set_status_change_email).with(:message => :any).returns(fixture)
225
- EccuRequest.new(:code => '1234').update_email!('foo').should be_true
198
+ it "updates notes attribute" do
199
+ expect { subject.update_email! 'foo' }.to change(subject, :email).to 'foo'
200
+ end
226
201
  end
227
202
 
228
- context 'when there is an error' do
229
- let(:fixture) { File.read 'spec/fixtures/eccu/set_status_change_email/fault.xml' }
203
+ context 'when the update is not successful' do
204
+ before do
205
+ expect_any_instance_of(AkamaiApi::ECCU::UpdateAttributeRequest).to receive(:execute).and_return false
206
+ end
207
+
208
+ it "returns false" do
209
+ expect(subject.update_email! 'foo').to be_falsy
210
+ end
230
211
 
231
- it 'does not update the mail' do
232
- savon.expects(:set_status_change_email).with(:message => :any).returns(fixture)
233
- req = EccuRequest.new :code => '1234'
234
- expect {
235
- req.update_email! 'foo'
236
- }.to_not change(req, :email)
212
+ it "does not update the email attribute" do
213
+ expect { subject.update_email! 'foo' }.to_not change { subject.email }
237
214
  end
238
215
  end
239
216
  end
240
217
 
241
218
  describe '#destroy' do
242
- let(:fixture) { File.read 'spec/fixtures/eccu/delete/successful.xml' }
219
+ subject { ECCURequest.new code: '1234' }
220
+
221
+ it 'delegates to DestroyRequest' do
222
+ fake_request = double
223
+ expect(fake_request).to receive(:execute).and_return true
224
+ expect(AkamaiApi::ECCU::DestroyRequest).to receive(:new).with('1234').and_return fake_request
225
+ subject.destroy
226
+ end
227
+
228
+ context 'when the update is successful' do
229
+ before do
230
+ expect_any_instance_of(AkamaiApi::ECCU::DestroyRequest).to receive(:execute).and_return true
231
+ end
243
232
 
244
- it 'calls the ECCU service using code' do
245
- body = SoapBody.new do
246
- integer :fileId, 1234
233
+ it "returns true" do
234
+ expect(subject.destroy).to be_truthy
247
235
  end
248
- savon.expects(:delete).with(:message => body.to_s).returns(fixture)
249
- EccuRequest.new(:code => '1234').destroy
250
236
  end
251
237
 
252
- it 'calls the ECCU service and return the service boolean response' do
253
- savon.expects(:delete).with(:message => :any).returns(fixture)
254
- EccuRequest.new(:code => '1234').destroy.should be_true
238
+ context 'when the update is not successful' do
239
+ before do
240
+ expect_any_instance_of(AkamaiApi::ECCU::DestroyRequest).to receive(:execute).and_return false
241
+ end
242
+
243
+ it "returns false" do
244
+ expect(subject.destroy).to be_falsy
245
+ end
255
246
  end
256
247
  end
257
248
  end
data/spec/spec_helper.rb CHANGED
@@ -1,25 +1,34 @@
1
1
  require File.expand_path '../../lib/akamai_api', __FILE__
2
2
  require File.expand_path '../../lib/akamai_api/cli', __FILE__
3
- require File.expand_path '../auth.rb', __FILE__
4
3
 
4
+ begin
5
+ require File.expand_path '../auth.rb', __FILE__
6
+ rescue LoadError
7
+ AkamaiApi.config[:auth] = ['test_username', 'test_password']
8
+ end
5
9
  require 'savon/mock/spec_helper'
6
10
  require 'webmock/rspec'
7
11
  require 'vcr'
12
+ require 'coveralls'
13
+ Coveralls.wear_merged!
8
14
 
9
15
  VCR.configure do |c|
10
16
  c.cassette_library_dir = 'cassettes'
11
17
  c.hook_into :webmock
12
18
  c.default_cassette_options = {
13
- record: :once
19
+ record: :once,
20
+ match_requests_on: [:method, :uri, :body]
14
21
  }
15
22
  c.configure_rspec_metadata!
16
23
  c.after_http_request do |request|
17
24
  request.uri.gsub! AkamaiApi.config[:auth].first, 'USERNAME'
18
25
  request.uri.gsub! AkamaiApi.config[:auth].last, 'PASSWORD'
26
+ request.body.gsub! "AkamaiApi #{AkamaiApi::VERSION}", "AkamaiApi VERSION"
19
27
  end
20
28
  c.before_playback do |i|
21
29
  i.request.uri.gsub! 'USERNAME', AkamaiApi.config[:auth].first
22
30
  i.request.uri.gsub! 'PASSWORD', AkamaiApi.config[:auth].last
31
+ i.request.body.gsub! "AkamaiApi VERSION", "AkamaiApi #{AkamaiApi::VERSION}"
23
32
  end
24
33
  end
25
34
 
@@ -29,7 +38,6 @@ Dir[File.expand_path '../support/**/*.rb', __FILE__].each do |f|
29
38
  end
30
39
 
31
40
  RSpec.configure do |config|
32
- config.treat_symbols_as_metadata_keys_with_true_values = true
33
41
  config.run_all_when_everything_filtered = true
34
42
  config.filter_run :focus
35
43