kalibro_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +27 -0
  7. data/AUTHORS +4 -0
  8. data/COPYING +674 -0
  9. data/COPYING.LESSER +165 -0
  10. data/Gemfile +4 -0
  11. data/README.md +77 -0
  12. data/Rakefile +6 -0
  13. data/cucumber.yml +1 -0
  14. data/features/kalibro_configuration/all.feature +10 -0
  15. data/features/kalibro_configuration/creation.feature +9 -0
  16. data/features/kalibro_configuration/destroy.feature +10 -0
  17. data/features/kalibro_configuration/metric_configurations.feature +12 -0
  18. data/features/metric_collector_details/all_names.feature +8 -0
  19. data/features/metric_collector_details/find_by_name.feature +12 -0
  20. data/features/metric_configuration/creation.feature +11 -0
  21. data/features/metric_configuration/destroy.feature +12 -0
  22. data/features/metric_configuration/find.feature +18 -0
  23. data/features/metric_configuration/metric_configurations_of.feature +18 -0
  24. data/features/metric_result/descendant_values.feature +19 -0
  25. data/features/metric_result/history_of.feature +20 -0
  26. data/features/metric_result/metric_results_of.feature +20 -0
  27. data/features/module_result/children.feature +19 -0
  28. data/features/module_result/find.feature +22 -0
  29. data/features/module_result/history_of.feature +19 -0
  30. data/features/processing/first_processing_after.feature +18 -0
  31. data/features/processing/first_processing_of.feature +18 -0
  32. data/features/processing/has_processing.feature +18 -0
  33. data/features/processing/has_processing_after.feature +18 -0
  34. data/features/processing/has_processing_before.feature +18 -0
  35. data/features/processing/has_ready_processing.feature +18 -0
  36. data/features/processing/last_processing_before.feature +18 -0
  37. data/features/processing/last_processing_of.feature +18 -0
  38. data/features/processing/last_processing_state_of.feature +18 -0
  39. data/features/processing/last_ready_processing_of.feature +19 -0
  40. data/features/processing/processing_of.feature +32 -0
  41. data/features/processing/processing_with_date_of.feature +32 -0
  42. data/features/project/all.feature +10 -0
  43. data/features/project/creation.feature +9 -0
  44. data/features/project/destroy.feature +10 -0
  45. data/features/project/exists.feature +9 -0
  46. data/features/project/find.feature +10 -0
  47. data/features/range/destroy.feature +14 -0
  48. data/features/range/exists.feature +13 -0
  49. data/features/range/find.feature +14 -0
  50. data/features/range/ranges_of.feature +22 -0
  51. data/features/range/save.feature +14 -0
  52. data/features/reading/destroy.feature +13 -0
  53. data/features/reading/exists.feature +13 -0
  54. data/features/reading/find.feature +11 -0
  55. data/features/reading/readings_of.feature +11 -0
  56. data/features/reading_group/all.feature +10 -0
  57. data/features/reading_group/creation.feature +9 -0
  58. data/features/reading_group/destroy.feature +11 -0
  59. data/features/repository/all.feature +14 -0
  60. data/features/repository/cancel_processing.feature +14 -0
  61. data/features/repository/destroy.feature +14 -0
  62. data/features/repository/exists.feature +14 -0
  63. data/features/repository/find.feature +14 -0
  64. data/features/repository/of.feature +15 -0
  65. data/features/repository/process.feature +16 -0
  66. data/features/repository/types.feature +8 -0
  67. data/features/step_definitions/configuration_steps.rb +40 -0
  68. data/features/step_definitions/metric_collector_details_steps.rb +28 -0
  69. data/features/step_definitions/metric_configuration_steps.rb +61 -0
  70. data/features/step_definitions/metric_result_steps.rb +33 -0
  71. data/features/step_definitions/metric_steps.rb +3 -0
  72. data/features/step_definitions/module_result_steps.rb +46 -0
  73. data/features/step_definitions/processing_steps.rb +95 -0
  74. data/features/step_definitions/project_steps.rb +48 -0
  75. data/features/step_definitions/range_steps.rb +72 -0
  76. data/features/step_definitions/reading_group_steps.rb +36 -0
  77. data/features/step_definitions/reading_steps.rb +47 -0
  78. data/features/step_definitions/repository_steps.rb +71 -0
  79. data/features/support/env.rb +25 -0
  80. data/features/support/kalibro_cucumber_helpers.yml.sample +3 -0
  81. data/kalibro_client.gemspec +49 -0
  82. data/lib/kalibro_client.rb +62 -0
  83. data/lib/kalibro_client/entities.rb +40 -0
  84. data/lib/kalibro_client/entities/base.rb +196 -0
  85. data/lib/kalibro_client/entities/configurations/base.rb +13 -0
  86. data/lib/kalibro_client/entities/configurations/kalibro_configuration.rb +37 -0
  87. data/lib/kalibro_client/entities/configurations/kalibro_range.rb +77 -0
  88. data/lib/kalibro_client/entities/configurations/metric_configuration.rb +93 -0
  89. data/lib/kalibro_client/entities/configurations/range_snapshot.rb +37 -0
  90. data/lib/kalibro_client/entities/configurations/reading.rb +56 -0
  91. data/lib/kalibro_client/entities/configurations/reading_group.rb +34 -0
  92. data/lib/kalibro_client/entities/miscellaneous/base.rb +57 -0
  93. data/lib/kalibro_client/entities/miscellaneous/compound_metric.rb +21 -0
  94. data/lib/kalibro_client/entities/miscellaneous/date_metric_result.rb +14 -0
  95. data/lib/kalibro_client/entities/miscellaneous/date_module_result.rb +18 -0
  96. data/lib/kalibro_client/entities/miscellaneous/granularity.rb +54 -0
  97. data/lib/kalibro_client/entities/miscellaneous/metric.rb +19 -0
  98. data/lib/kalibro_client/entities/miscellaneous/native_metric.rb +24 -0
  99. data/lib/kalibro_client/entities/processor/base.rb +16 -0
  100. data/lib/kalibro_client/entities/processor/kalibro_module.rb +27 -0
  101. data/lib/kalibro_client/entities/processor/metric_collector_details.rb +53 -0
  102. data/lib/kalibro_client/entities/processor/metric_result.rb +79 -0
  103. data/lib/kalibro_client/entities/processor/module_result.rb +82 -0
  104. data/lib/kalibro_client/entities/processor/process_time.rb +31 -0
  105. data/lib/kalibro_client/entities/processor/processing.rb +109 -0
  106. data/lib/kalibro_client/entities/processor/project.rb +34 -0
  107. data/lib/kalibro_client/entities/processor/repository.rb +75 -0
  108. data/lib/kalibro_client/errors.rb +18 -0
  109. data/lib/kalibro_client/errors/record_not_found.rb +22 -0
  110. data/lib/kalibro_client/errors/standard.rb +24 -0
  111. data/lib/kalibro_client/helpers/aggregation_options.rb +25 -0
  112. data/lib/kalibro_client/helpers/hash_converters.rb +48 -0
  113. data/lib/kalibro_client/helpers/request_methods.rb +55 -0
  114. data/lib/kalibro_client/helpers/xml_converters.rb +20 -0
  115. data/lib/kalibro_client/kalibro_cucumber_helpers.rb +60 -0
  116. data/lib/kalibro_client/kalibro_cucumber_helpers/configuration.rb +30 -0
  117. data/lib/kalibro_client/kalibro_cucumber_helpers/hooks.rb +25 -0
  118. data/lib/kalibro_client/version.rb +19 -0
  119. data/lib/rake/test_task.rb +57 -0
  120. data/spec/entities/base_spec.rb +313 -0
  121. data/spec/entities/configurations/base_spec.rb +26 -0
  122. data/spec/entities/configurations/kalibro_configuration_spec.rb +91 -0
  123. data/spec/entities/configurations/kalibro_range_spec.rb +174 -0
  124. data/spec/entities/configurations/metric_configuration_spec.rb +230 -0
  125. data/spec/entities/configurations/range_snapshot_spec.rb +50 -0
  126. data/spec/entities/configurations/reading_group_spec.rb +60 -0
  127. data/spec/entities/configurations/reading_spec.rb +87 -0
  128. data/spec/entities/miscellaneous/base_spec.rb +49 -0
  129. data/spec/entities/miscellaneous/compound_metric_spec.rb +36 -0
  130. data/spec/entities/miscellaneous/date_metric_result_spec.rb +4 -0
  131. data/spec/entities/miscellaneous/date_module_result_spec.rb +0 -0
  132. data/spec/entities/miscellaneous/granularity_spec.rb +96 -0
  133. data/spec/entities/miscellaneous/metric_spec.rb +15 -0
  134. data/spec/entities/miscellaneous/native_metric_spec.rb +37 -0
  135. data/spec/entities/processor/base_spec.rb +26 -0
  136. data/spec/entities/processor/metric_collector_details_spec.rb +146 -0
  137. data/spec/entities/processor/metric_result_spec.rb +209 -0
  138. data/spec/entities/processor/module_result_spec.rb +178 -0
  139. data/spec/entities/processor/process_time_spec.rb +33 -0
  140. data/spec/entities/processor/processing_spec.rb +333 -0
  141. data/spec/entities/processor/project_spec.rb +68 -0
  142. data/spec/entities/processor/repository_spec.rb +140 -0
  143. data/spec/factories/date_metric_results.rb +30 -0
  144. data/spec/factories/date_module_results.rb +24 -0
  145. data/spec/factories/granularities.rb +23 -0
  146. data/spec/factories/kalibro_configurations.rb +34 -0
  147. data/spec/factories/kalibro_module.rb +28 -0
  148. data/spec/factories/kalibro_ranges.rb +40 -0
  149. data/spec/factories/metric_collector_details.rb +30 -0
  150. data/spec/factories/metric_configurations.rb +31 -0
  151. data/spec/factories/metric_results.rb +24 -0
  152. data/spec/factories/metrics.rb +48 -0
  153. data/spec/factories/models.rb +23 -0
  154. data/spec/factories/module_results.rb +43 -0
  155. data/spec/factories/process_times.rb +27 -0
  156. data/spec/factories/processings.rb +24 -0
  157. data/spec/factories/projects.rb +35 -0
  158. data/spec/factories/ranges_snapshot.rb +26 -0
  159. data/spec/factories/reading_groups.rb +28 -0
  160. data/spec/factories/readings.rb +30 -0
  161. data/spec/factories/repositories.rb +39 -0
  162. data/spec/helpers/aggregation_options_spec.rb +31 -0
  163. data/spec/helpers/hash_converters_spec.rb +111 -0
  164. data/spec/helpers/xml_converters_spec.rb +64 -0
  165. data/spec/kalibro_entities_spec.rb +112 -0
  166. data/spec/savon/fixtures/config.yml +2 -0
  167. data/spec/savon/fixtures/invalid_config.yml +2 -0
  168. data/spec/savon/fixtures/project/does_not_exists.xml +1 -0
  169. data/spec/savon/savon_test_helper.rb +14 -0
  170. data/spec/spec_helper.rb +111 -0
  171. metadata +479 -0
@@ -0,0 +1,33 @@
1
+ # This file is part of KalibroClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'spec_helper'
18
+
19
+ describe KalibroClient::Entities::Processor::ProcessTime do
20
+ describe 'time=' do
21
+ subject {FactoryGirl.build(:process_time)}
22
+
23
+ it 'should set the time attribute to 6' do
24
+ subject.time = 6
25
+ expect(subject.time).to eq 6
26
+ end
27
+
28
+ it 'should convert to integer' do
29
+ subject.time = "5"
30
+ expect(subject.time).to eq 5
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,333 @@
1
+ # This file is part of KalibroClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'spec_helper'
18
+
19
+ describe KalibroClient::Entities::Processor::Processing do
20
+ subject {FactoryGirl.build(:processing)}
21
+ let(:date) { DateTime.now }
22
+ describe 'id=' do
23
+ it 'should convert the id attribute to integer' do
24
+ subject.id = "41"
25
+ expect(subject.id).to eq 41
26
+ end
27
+ end
28
+
29
+ describe 'date=' do
30
+ it 'should set the date attribute' do
31
+ subject.date = date
32
+ expect(subject.date).to eq date
33
+ end
34
+
35
+ it 'should convert strings to date format' do
36
+ subject.date = "2013-09-17T18:26:43.151+00:00"
37
+ expect(subject.date).to be_kind_of(DateTime)
38
+ end
39
+ end
40
+
41
+ describe "repository_id=" do
42
+ it 'should set the repository_id attribute values as integer' do
43
+ subject.repository_id = "222"
44
+ expect(subject.repository_id).to eq(222)
45
+ end
46
+ end
47
+
48
+ describe 'process_times' do
49
+ let(:process_time) { FactoryGirl.build(:analyzing_process_time) }
50
+
51
+ context 'When the process_times is nil' do
52
+ before :each do
53
+ KalibroClient::Entities::Processor::Processing.expects(:request).with(":id/process_times", {id: subject.id}, :get).returns({"process_times" => [process_time.to_hash]})
54
+ end
55
+
56
+ it 'should set the process_times attribute as a list of objects' do
57
+ expect(subject.process_times).to eq [process_time]
58
+ end
59
+ end
60
+
61
+ context 'When the process_times is not nil' do
62
+ before :each do
63
+ KalibroClient::Entities::Processor::Processing.expects(:request).once.with(":id/process_times", {id: subject.id}, :get).returns({"process_times" => [process_time.to_hash]})
64
+ end
65
+
66
+ it 'should return the process_times' do
67
+ subject.process_times
68
+ expect(subject.process_times).to eq [process_time]
69
+ end
70
+ end
71
+ end
72
+
73
+ describe 'root_module_result_id=' do
74
+ it 'should set the attribute results root id as an integer' do
75
+ subject.root_module_result_id = "36"
76
+ expect(subject.root_module_result_id).to eq 36
77
+ end
78
+ end
79
+
80
+ context 'static methods' do
81
+ context 'using repository as parametter' do
82
+ let(:repository) { FactoryGirl.build(:repository) }
83
+ describe 'has_processing' do
84
+ before :each do
85
+ KalibroClient::Entities::Processor::Repository.
86
+ expects(:request).once.
87
+ with("#{repository.id}/has_processing").
88
+ returns({'has_processing' => false})
89
+ end
90
+
91
+ it 'should convert the hash to a Boolean class' do
92
+ response = KalibroClient::Entities::Processor::Processing.has_processing repository.id
93
+ expect(response).to be_a_kind_of(FalseClass)
94
+ end
95
+ end
96
+
97
+ describe 'has_ready_processing' do
98
+ before :each do
99
+ KalibroClient::Entities::Processor::Repository.
100
+ expects(:request).once.
101
+ with("#{repository.id}/has_ready_processing", {}, :get).
102
+ returns({'has_ready_processing' => false})
103
+ end
104
+
105
+ it 'should convert the hash to a Boolean class' do
106
+ response = KalibroClient::Entities::Processor::Processing.has_ready_processing repository.id
107
+ expect(response).to be_a_kind_of(FalseClass)
108
+ end
109
+ end
110
+
111
+ describe 'has_processing_after' do
112
+ before :each do
113
+ KalibroClient::Entities::Processor::Repository.
114
+ expects(:request).once.
115
+ with("#{repository.id}/has_processing/after", {date: date}).
116
+ returns({'has_processing_in_time' => false})
117
+ end
118
+
119
+ it 'should convert the hash to a Boolean class' do
120
+ response = KalibroClient::Entities::Processor::Processing.has_processing_after(repository.id, date)
121
+ expect(response).to be_a_kind_of(FalseClass)
122
+ end
123
+ end
124
+
125
+ describe 'has_processing_before' do
126
+ before :each do
127
+ KalibroClient::Entities::Processor::Repository.
128
+ expects(:request).once.
129
+ with("#{repository.id}/has_processing/before", {date: date}).
130
+ returns({'has_processing_in_time' => false})
131
+ end
132
+
133
+ it 'should convert the hash to a Boolean class' do
134
+ response = KalibroClient::Entities::Processor::Processing.has_processing_before(repository.id, date)
135
+ expect(response).to be_a_kind_of(FalseClass)
136
+ end
137
+ end
138
+
139
+ describe 'last_processing_state_of' do
140
+ let(:any_state) { "READY" }
141
+ before :each do
142
+ KalibroClient::Entities::Processor::Repository.
143
+ expects(:request).once.
144
+ with("#{repository.id}/last_processing_state", {}, :get).
145
+ returns({'processing_state' => any_state})
146
+ end
147
+
148
+ it 'should return the state as string' do
149
+ response = KalibroClient::Entities::Processor::Processing.last_processing_state_of repository.id
150
+ expect(response).to eq(any_state)
151
+ end
152
+ end
153
+
154
+ context 'getting processing entity from Kalibro web service' do
155
+ let(:processing) { FactoryGirl.build(:processing) }
156
+
157
+ describe 'processing_of' do
158
+ context 'when the repository has a ready processing' do
159
+ before do
160
+ KalibroClient::Entities::Processor::Repository.
161
+ expects(:request).once.
162
+ with("#{repository.id}/has_ready_processing", {}, :get).
163
+ returns({'has_ready_processing' => true})
164
+
165
+ KalibroClient::Entities::Processor::Repository.
166
+ expects(:request).once.
167
+ with(':id/last_ready_processing', {id: repository.id}, :get).
168
+ returns({'last_ready_processing' => processing.to_hash})
169
+ end
170
+
171
+ it 'should return the last ready processing' do
172
+ response = KalibroClient::Entities::Processor::Processing.processing_of repository.id
173
+ expect(response.state).to eq(processing.state)
174
+ end
175
+ end
176
+
177
+ context 'when the repository has not a ready processing' do
178
+ before do
179
+ KalibroClient::Entities::Processor::Repository.
180
+ expects(:request).once.
181
+ with("#{repository.id}/has_ready_processing", {}, :get).
182
+ returns({'exists' => false})
183
+
184
+ KalibroClient::Entities::Processor::Repository.
185
+ expects(:request).once.
186
+ with("#{repository.id}/last_processing").
187
+ returns({'processing' => processing.to_hash})
188
+ end
189
+
190
+ it 'should return the last processing' do
191
+ response = KalibroClient::Entities::Processor::Processing.processing_of repository.id
192
+ expect(response.state).to eq(processing.state)
193
+ end
194
+ end
195
+ end
196
+
197
+ describe 'processing_with_date_of' do
198
+ context 'when the repository has a processing after the given date' do
199
+ before do
200
+ KalibroClient::Entities::Processor::Repository.
201
+ expects(:request).once.
202
+ with("#{repository.id}/has_processing/after", {date: date}).
203
+ returns({'has_processing_in_time' => true})
204
+
205
+ KalibroClient::Entities::Processor::Repository.
206
+ expects(:request).once.
207
+ with("#{repository.id}/first_processing/after", {date: date}).
208
+ returns({'processing' => processing.to_hash})
209
+ end
210
+
211
+ it 'should return the first processing after the given date' do
212
+ response = KalibroClient::Entities::Processor::Processing.processing_with_date_of(repository.id, date)
213
+ expect(response.state).to eq(processing.state)
214
+ end
215
+ end
216
+
217
+ context 'when the repository has a processing before the given date' do
218
+ before do
219
+ KalibroClient::Entities::Processor::Repository.
220
+ expects(:request).once.
221
+ with("#{repository.id}/has_processing/after", {date: date}).
222
+ returns({'has_processing_in_time' => false})
223
+
224
+ KalibroClient::Entities::Processor::Repository.
225
+ expects(:request).once.
226
+ with("#{repository.id}/has_processing/before", {date: date}).
227
+ returns({'has_processing_in_time' => true})
228
+
229
+ KalibroClient::Entities::Processor::Repository.
230
+ expects(:request).once.
231
+ with("#{repository.id}/last_processing/before", {date: date}).
232
+ returns({'processing' => processing.to_hash})
233
+ end
234
+
235
+ it 'should return the last ready processing' do
236
+ response = KalibroClient::Entities::Processor::Processing.processing_with_date_of(repository.id, date)
237
+ expect(response.state).to eq(processing.state)
238
+ end
239
+ end
240
+
241
+ context 'when the repository has not a processing after or before the given date' do
242
+ before do
243
+ KalibroClient::Entities::Processor::Repository.
244
+ expects(:request).once.
245
+ with("#{repository.id}/has_processing/after", {date: date}).
246
+ returns({'has_processing_in_time' => false})
247
+
248
+ KalibroClient::Entities::Processor::Repository.
249
+ expects(:request).once.
250
+ with("#{repository.id}/has_processing/before", {date: date}).
251
+ returns({'has_processing_in_time' => false})
252
+ end
253
+
254
+ it 'should return the last ready processing' do
255
+ response = KalibroClient::Entities::Processor::Processing.processing_with_date_of(repository.id, date)
256
+ expect(response).to be_nil
257
+ end
258
+ end
259
+ end
260
+
261
+ describe 'last_ready_processing_of' do
262
+ before :each do
263
+ KalibroClient::Entities::Processor::Repository.
264
+ expects(:request).once.
265
+ with(':id/last_ready_processing', {id: repository.id}, :get).
266
+ returns({'last_ready_processing' => processing.to_hash})
267
+ end
268
+
269
+ it 'should return a processing object' do
270
+ response = KalibroClient::Entities::Processor::Processing.last_ready_processing_of repository.id
271
+ expect(response.state).to eq(processing.state)
272
+ end
273
+ end
274
+
275
+ describe 'first_processing_of' do
276
+ before :each do
277
+ KalibroClient::Entities::Processor::Repository.
278
+ expects(:request).once.
279
+ with("#{repository.id}/first_processing").
280
+ returns({'processing' => processing.to_hash})
281
+ end
282
+
283
+ it 'should return a processing object' do
284
+ response = KalibroClient::Entities::Processor::Processing.first_processing_of repository.id
285
+ expect(response.state).to eq(processing.state)
286
+ end
287
+ end
288
+
289
+ describe 'last_processing_of' do
290
+ before :each do
291
+ KalibroClient::Entities::Processor::Repository.
292
+ expects(:request).once.
293
+ with("#{repository.id}/last_processing").
294
+ returns({'processing' => processing.to_hash})
295
+ end
296
+
297
+ it 'should return a processing object' do
298
+ response = KalibroClient::Entities::Processor::Processing.last_processing_of repository.id
299
+ expect(response.state).to eq(processing.state)
300
+ end
301
+ end
302
+
303
+ describe 'first_processing_after' do
304
+ before :each do
305
+ KalibroClient::Entities::Processor::Repository.
306
+ expects(:request).once.
307
+ with("#{repository.id}/first_processing/after", {date: date}).
308
+ returns({'processing' => processing.to_hash})
309
+ end
310
+
311
+ it 'should return a processing object' do
312
+ response = KalibroClient::Entities::Processor::Processing.first_processing_after(repository.id, date)
313
+ expect(response.state).to eq(processing.state)
314
+ end
315
+ end
316
+
317
+ describe 'last_processing_before' do
318
+ before :each do
319
+ KalibroClient::Entities::Processor::Repository.
320
+ expects(:request).once.
321
+ with("#{repository.id}/last_processing/before", {date: date}).
322
+ returns({'processing' => processing.to_hash})
323
+ end
324
+
325
+ it 'should return a processing object' do
326
+ response = KalibroClient::Entities::Processor::Processing.last_processing_before(repository.id, date)
327
+ expect(response.state).to eq(processing.state)
328
+ end
329
+ end
330
+ end
331
+ end
332
+ end
333
+ end
@@ -0,0 +1,68 @@
1
+ # This file is part of KalibroClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'spec_helper'
18
+
19
+ describe KalibroClient::Entities::Processor::Project do
20
+ describe 'initialize' do
21
+ subject { FactoryGirl.build(:project, {id: 42}) }
22
+
23
+ it 'should have the id set to 42' do
24
+ expect(subject.id).to eq(42)
25
+ end
26
+ end
27
+
28
+ describe 'id=' do
29
+ it 'should set the value of the attribute id as integer' do
30
+ subject.id = "42"
31
+ expect(subject.id).to eq(42)
32
+ end
33
+ end
34
+
35
+ describe 'all' do
36
+ context 'with no projects' do
37
+ before :each do
38
+ KalibroClient::Entities::Processor::Project.
39
+ expects(:request).
40
+ with('', {}, :get).
41
+ returns({"projects" => nil})
42
+ end
43
+
44
+ it 'should return nil' do
45
+ expect(KalibroClient::Entities::Processor::Project.all).to be_empty
46
+ end
47
+ end
48
+
49
+ context 'with many projects' do
50
+ let(:project) { FactoryGirl.build(:project) }
51
+ let(:another_project) { FactoryGirl.build(:another_project) }
52
+
53
+ before :each do
54
+ KalibroClient::Entities::Processor::Project.
55
+ expects(:request).
56
+ with('', {}, :get).
57
+ returns({"projects" => [project.to_hash, another_project.to_hash]})
58
+ end
59
+
60
+ it 'should return a list with projects' do
61
+ projects = KalibroClient::Entities::Processor::Project.all
62
+
63
+ expect(projects.first.name).to eq(project.name)
64
+ expect(projects.last.name).to eq(another_project.name)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,140 @@
1
+ # This file is part of KalibroClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'spec_helper'
18
+
19
+ describe KalibroClient::Entities::Processor::Repository do
20
+ subject { FactoryGirl.build(:repository) }
21
+
22
+ describe 'repository_types' do
23
+ before :each do
24
+ KalibroClient::Entities::Processor::Repository.
25
+ expects(:request).
26
+ with('types', {}, :get).
27
+ returns({'types'=>["BAZAAR", "GIT", "MERCURIAL", "REMOTE_TARBALL", "REMOTE_ZIP"]})
28
+ end
29
+
30
+ it 'should return an array of repository types' do
31
+ expect(KalibroClient::Entities::Processor::Repository.repository_types).to eq(["BAZAAR", "GIT", "MERCURIAL", "REMOTE_TARBALL", "REMOTE_ZIP"])
32
+ end
33
+ end
34
+
35
+ describe 'repositories_of' do
36
+ let!(:project) { FactoryGirl.build(:project_with_id) }
37
+ let!(:repository_hash) { FactoryGirl.attributes_for(:repository_with_id) }
38
+ before :each do
39
+ KalibroClient::Entities::Processor::Repository.
40
+ expects(:request).
41
+ with('', {}, :get, "projects/#{project.id}").
42
+ returns({'repositories' => [repository_hash]})
43
+ end
44
+
45
+ it 'should return an array' do
46
+ expect(KalibroClient::Entities::Processor::Repository.repositories_of(project.id)).to be_an(Array)
47
+ end
48
+
49
+ it 'should set the repository_id' do
50
+ KalibroClient::Entities::Processor::Repository.repositories_of(project.id).each do |repository|
51
+ expect(repository.project_id).to eq(project.id)
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "id=" do
57
+ it 'should set the id attribute values as integer' do
58
+ subject.id = "222"
59
+ expect(subject.id).to eq(222)
60
+ end
61
+ end
62
+
63
+ describe "period=" do
64
+ it 'should set the period attribute values as integer' do
65
+ subject.period = "222"
66
+ expect(subject.period).to eq(222)
67
+ end
68
+ end
69
+
70
+ describe "configuration_id=" do
71
+ it 'should set the configuration_id attribute values as integer' do
72
+ subject.configuration_id = "222"
73
+ expect(subject.configuration_id).to eq(222)
74
+ end
75
+ end
76
+
77
+ describe 'process' do
78
+ before :each do
79
+ KalibroClient::Entities::Processor::Repository.
80
+ expects(:request).
81
+ with("#{subject.id}/process", {}, :get)
82
+ end
83
+
84
+ it 'should call the request method' do
85
+ subject.process
86
+ end
87
+ end
88
+
89
+ describe 'cancel_processing_of_repository' do
90
+ before :each do
91
+ KalibroClient::Entities::Processor::Repository.
92
+ expects(:request).
93
+ with('cancel_process', {id: subject.id})
94
+ end
95
+
96
+ it 'should call the request method' do
97
+ subject.cancel_processing_of_repository
98
+ end
99
+ end
100
+
101
+ describe 'all' do
102
+ let(:project) { FactoryGirl.build(:project) }
103
+
104
+ before :each do
105
+ KalibroClient::Entities::Processor::Project.
106
+ expects(:all).
107
+ returns([project])
108
+ KalibroClient::Entities::Processor::Repository.
109
+ expects(:repositories_of).
110
+ with(project.id).
111
+ returns([subject])
112
+ end
113
+
114
+ it 'should list all the repositories' do
115
+ expect(KalibroClient::Entities::Processor::Repository.all).to include(subject)
116
+ end
117
+ end
118
+
119
+ # The only purpose of this test is to cover the overrided save_params method
120
+ describe 'save' do
121
+ subject {FactoryGirl.build(:repository)}
122
+
123
+ before :each do
124
+ KalibroClient::Entities::Processor::Repository.
125
+ expects(:request).
126
+ with('', {:repository => subject.to_hash, :project_id => 1}, :post, '').
127
+ returns("repository" => {'id' => 1, 'kalibro_errors' => []})
128
+
129
+ KalibroClient::Entities::Processor::Repository.any_instance.
130
+ expects(:id=).
131
+ with(1).
132
+ returns(1)
133
+ end
134
+
135
+ it 'should make a request to save model with id and return true without errors' do
136
+ expect(subject.save).to be(true)
137
+ expect(subject.kalibro_errors).to be_empty
138
+ end
139
+ end
140
+ end