kalibro_client 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/features/kalibro_configuration/all.feature +6 -6
  4. data/features/kalibro_configuration/creation.feature +5 -5
  5. data/features/kalibro_configuration/destroy.feature +6 -6
  6. data/features/kalibro_configuration/metric_configurations.feature +4 -4
  7. data/features/{range → kalibro_range}/destroy.feature +2 -2
  8. data/features/{range → kalibro_range}/exists.feature +2 -2
  9. data/features/{range → kalibro_range}/find.feature +2 -2
  10. data/features/{range → kalibro_range}/ranges_of.feature +4 -4
  11. data/features/{range → kalibro_range}/save.feature +2 -2
  12. data/features/kalibro_range/update.feature +54 -0
  13. data/features/metric_configuration/creation.feature +2 -2
  14. data/features/metric_configuration/destroy.feature +2 -2
  15. data/features/metric_configuration/find.feature +2 -2
  16. data/features/metric_configuration/metric_configurations_of.feature +8 -8
  17. data/features/metric_result/descendant_values.feature +2 -2
  18. data/features/metric_result/history_of.feature +2 -2
  19. data/features/metric_result/metric_results_of.feature +2 -2
  20. data/features/module_result/children.feature +2 -2
  21. data/features/module_result/find.feature +2 -2
  22. data/features/module_result/history_of.feature +2 -2
  23. data/features/processing/first_processing_after.feature +2 -2
  24. data/features/processing/first_processing_of.feature +2 -2
  25. data/features/processing/has_processing.feature +2 -2
  26. data/features/processing/has_processing_after.feature +2 -2
  27. data/features/processing/has_processing_before.feature +2 -2
  28. data/features/processing/has_ready_processing.feature +2 -2
  29. data/features/processing/last_processing_before.feature +2 -2
  30. data/features/processing/last_processing_of.feature +2 -2
  31. data/features/processing/last_processing_state_of.feature +2 -2
  32. data/features/processing/last_ready_processing_of.feature +2 -2
  33. data/features/processing/processing_of.feature +4 -4
  34. data/features/processing/processing_with_date_of.feature +4 -4
  35. data/features/project/update.feature +13 -0
  36. data/features/repository/all.feature +1 -1
  37. data/features/repository/cancel_processing.feature +1 -1
  38. data/features/repository/destroy.feature +1 -1
  39. data/features/repository/exists.feature +1 -1
  40. data/features/repository/find.feature +1 -1
  41. data/features/repository/of.feature +1 -1
  42. data/features/repository/process.feature +2 -2
  43. data/features/step_definitions/kalibro_configuration_steps.rb +40 -0
  44. data/features/step_definitions/metric_configuration_steps.rb +9 -9
  45. data/features/step_definitions/module_result_steps.rb +1 -1
  46. data/features/step_definitions/project_steps.rb +12 -0
  47. data/features/step_definitions/range_steps.rb +25 -1
  48. data/features/step_definitions/reading_steps.rb +1 -1
  49. data/features/step_definitions/repository_steps.rb +1 -1
  50. data/lib/kalibro_client/entities/base.rb +53 -19
  51. data/lib/kalibro_client/entities/configurations/base.rb +4 -1
  52. data/lib/kalibro_client/entities/configurations/kalibro_configuration.rb +1 -1
  53. data/lib/kalibro_client/entities/configurations/kalibro_range.rb +8 -8
  54. data/lib/kalibro_client/entities/configurations/metric_configuration.rb +7 -5
  55. data/lib/kalibro_client/entities/configurations/reading.rb +4 -4
  56. data/lib/kalibro_client/entities/configurations/reading_group.rb +4 -0
  57. data/lib/kalibro_client/entities/processor/base.rb +2 -1
  58. data/lib/kalibro_client/entities/processor/kalibro_module.rb +1 -0
  59. data/lib/kalibro_client/entities/processor/metric_collector_details.rb +7 -2
  60. data/lib/kalibro_client/entities/processor/metric_result.rb +9 -10
  61. data/lib/kalibro_client/entities/processor/module_result.rb +10 -2
  62. data/lib/kalibro_client/entities/processor/processing.rb +26 -10
  63. data/lib/kalibro_client/entities/processor/project.rb +4 -0
  64. data/lib/kalibro_client/entities/processor/repository.rb +63 -4
  65. data/lib/kalibro_client/helpers/date_attributes.rb +11 -0
  66. data/lib/kalibro_client/helpers/request_methods.rb +9 -0
  67. data/lib/kalibro_client/version.rb +1 -1
  68. data/spec/entities/base_spec.rb +106 -24
  69. data/spec/entities/configurations/kalibro_configuration_spec.rb +8 -8
  70. data/spec/entities/configurations/kalibro_range_spec.rb +18 -24
  71. data/spec/entities/configurations/metric_configuration_spec.rb +22 -23
  72. data/spec/entities/configurations/reading_group_spec.rb +27 -0
  73. data/spec/entities/configurations/reading_spec.rb +15 -7
  74. data/spec/entities/processor/metric_collector_details_spec.rb +19 -7
  75. data/spec/entities/processor/metric_result_spec.rb +40 -54
  76. data/spec/entities/processor/module_result_spec.rb +52 -3
  77. data/spec/entities/processor/processing_spec.rb +35 -92
  78. data/spec/entities/processor/project_spec.rb +52 -5
  79. data/spec/entities/processor/repository_spec.rb +255 -5
  80. data/spec/factories/kalibro_configurations.rb +3 -3
  81. data/spec/factories/kalibro_ranges.rb +9 -3
  82. data/spec/factories/metrics.rb +1 -1
  83. data/spec/factories/readings.rb +1 -1
  84. data/spec/factories/repositories.rb +1 -1
  85. data/spec/helpers/date_attributes_spec.rb +30 -0
  86. metadata +21 -14
  87. data/features/step_definitions/configuration_steps.rb +0 -40
@@ -17,9 +17,8 @@
17
17
  require 'spec_helper'
18
18
 
19
19
  describe KalibroClient::Entities::Processor::Project do
20
+ subject { FactoryGirl.build(:project, {id: 42}) }
20
21
  describe 'initialize' do
21
- subject { FactoryGirl.build(:project, {id: 42}) }
22
-
23
22
  it 'should have the id set to 42' do
24
23
  expect(subject.id).to eq(42)
25
24
  end
@@ -52,9 +51,9 @@ describe KalibroClient::Entities::Processor::Project do
52
51
 
53
52
  before :each do
54
53
  KalibroClient::Entities::Processor::Project.
55
- expects(:request).
56
- with('', {}, :get).
57
- returns({"projects" => [project.to_hash, another_project.to_hash]})
54
+ expects(:request).
55
+ with('', {}, :get).
56
+ returns({"projects" => [project.to_hash, another_project.to_hash]})
58
57
  end
59
58
 
60
59
  it 'should return a list with projects' do
@@ -65,4 +64,52 @@ describe KalibroClient::Entities::Processor::Project do
65
64
  end
66
65
  end
67
66
  end
67
+
68
+ describe 'repositories' do
69
+ let(:project) { FactoryGirl.build(:project) }
70
+ let(:repository) { FactoryGirl.build(:repository) }
71
+
72
+ context 'with a repository' do
73
+
74
+ before :each do
75
+ KalibroClient::Entities::Processor::Project.
76
+ expects(:request).
77
+ with(':id/repositories', {id: project.id}, :get).
78
+ returns({"repositories" => [repository.to_hash]})
79
+ end
80
+
81
+ it 'should return a list with repositories' do
82
+ expect(project.repositories).to eq([repository])
83
+ end
84
+ end
85
+
86
+ context 'without a repository' do
87
+ before :each do
88
+ KalibroClient::Entities::Processor::Project.
89
+ expects(:request).
90
+ with(':id/repositories', {id: project.id}, :get).
91
+ returns({"repositories" => []})
92
+ end
93
+
94
+ it 'should return an empty list' do
95
+ expect(project.repositories).to eq([])
96
+ end
97
+ end
98
+ end
99
+
100
+ describe 'update' do
101
+ context 'with attributes' do
102
+ before :each do
103
+ KalibroClient::Entities::Processor::Project.
104
+ expects(:request).
105
+ with(':id', {project: {"name" => "Another Name", "description" => subject.description, "id" => subject.id.to_s}, id: subject.id}, :put, '').
106
+ returns({"project" => {"id" => subject.id, "name" => "Another Name", "kalibro_errors" => []}})
107
+ end
108
+
109
+ it 'is expected to have name Another Name' do
110
+ subject.update(name: "Another Name")
111
+ expect(subject.name).to eq("Another Name")
112
+ end
113
+ end
114
+ end
68
115
  end
@@ -18,6 +18,7 @@ require 'spec_helper'
18
18
 
19
19
  describe KalibroClient::Entities::Processor::Repository do
20
20
  subject { FactoryGirl.build(:repository) }
21
+ let(:date) { DateTime.now }
21
22
 
22
23
  describe 'repository_types' do
23
24
  before :each do
@@ -67,10 +68,10 @@ describe KalibroClient::Entities::Processor::Repository do
67
68
  end
68
69
  end
69
70
 
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)
71
+ describe "kalibro_configuration_id=" do
72
+ it 'should set the kalibro_configuration_id attribute values as integer' do
73
+ subject.kalibro_configuration_id = "222"
74
+ expect(subject.kalibro_configuration_id).to eq(222)
74
75
  end
75
76
  end
76
77
 
@@ -90,7 +91,7 @@ describe KalibroClient::Entities::Processor::Repository do
90
91
  before :each do
91
92
  KalibroClient::Entities::Processor::Repository.
92
93
  expects(:request).
93
- with('cancel_process', {id: subject.id})
94
+ with(':id/cancel_process', {id: subject.id}, :get)
94
95
  end
95
96
 
96
97
  it 'should call the request method' do
@@ -137,4 +138,253 @@ describe KalibroClient::Entities::Processor::Repository do
137
138
  expect(subject.kalibro_errors).to be_empty
138
139
  end
139
140
  end
141
+
142
+ describe 'has_processing' do
143
+ before :each do
144
+ KalibroClient::Entities::Processor::Repository.
145
+ expects(:request).once.
146
+ with("#{subject.id}/has_processing", {}, :get).
147
+ returns({'has_processing' => false})
148
+ end
149
+
150
+ it 'should convert the hash to a Boolean class' do
151
+ response = subject.has_processing
152
+ expect(response).to be_a_kind_of(FalseClass)
153
+ end
154
+ end
155
+
156
+ describe 'has_ready_processing' do
157
+ before :each do
158
+ KalibroClient::Entities::Processor::Repository.
159
+ expects(:request).once.
160
+ with("#{subject.id}/has_ready_processing", {}, :get).
161
+ returns({'has_ready_processing' => false})
162
+ end
163
+
164
+ it 'should convert the hash to a Boolean class' do
165
+ response = subject.has_ready_processing
166
+ expect(response).to be_a_kind_of(FalseClass)
167
+ end
168
+ end
169
+
170
+ describe 'has_processing_after' do
171
+ before :each do
172
+ KalibroClient::Entities::Processor::Repository.
173
+ expects(:request).once.
174
+ with("#{subject.id}/has_processing/after", {date: date}).
175
+ returns({'has_processing_in_time' => false})
176
+ end
177
+
178
+ it 'should convert the hash to a Boolean class' do
179
+ response = subject.has_processing_after(date)
180
+ expect(response).to be_a_kind_of(FalseClass)
181
+ end
182
+ end
183
+
184
+ describe 'has_processing_before' do
185
+ before :each do
186
+ KalibroClient::Entities::Processor::Repository.
187
+ expects(:request).once.
188
+ with("#{subject.id}/has_processing/before", {date: date}).
189
+ returns({'has_processing_in_time' => false})
190
+ end
191
+
192
+ it 'should convert the hash to a Boolean class' do
193
+ response = subject.has_processing_before(date)
194
+ expect(response).to be_a_kind_of(FalseClass)
195
+ end
196
+ end
197
+
198
+ describe 'last_processing_state' do
199
+ let(:any_state) { "READY" }
200
+ before :each do
201
+ KalibroClient::Entities::Processor::Repository.
202
+ expects(:request).once.
203
+ with("#{subject.id}/last_processing_state", {}, :get).
204
+ returns({'processing_state' => any_state})
205
+ end
206
+
207
+ it 'should return the state as string' do
208
+ response = subject.last_processing_state
209
+ expect(response).to eq(any_state)
210
+ end
211
+ end
212
+
213
+ context 'getting processing entity from Kalibro web service' do
214
+ let(:processing) { FactoryGirl.build(:processing) }
215
+
216
+ describe 'processing' do
217
+ context 'when the repository has a ready processing' do
218
+ before do
219
+ KalibroClient::Entities::Processor::Repository.
220
+ expects(:request).once.
221
+ with("#{subject.id}/has_ready_processing", {}, :get).
222
+ returns({'has_ready_processing' => true})
223
+
224
+ KalibroClient::Entities::Processor::Repository.
225
+ expects(:request).once.
226
+ with(':id/last_ready_processing', {id: subject.id}, :get).
227
+ returns({'last_ready_processing' => processing.to_hash})
228
+ end
229
+
230
+ it 'should return the last ready processing' do
231
+ response = subject.processing
232
+ expect(response.state).to eq(processing.state)
233
+ end
234
+ end
235
+
236
+ context 'when the repository has not a ready processing' do
237
+ before do
238
+ KalibroClient::Entities::Processor::Repository.
239
+ expects(:request).once.
240
+ with("#{subject.id}/has_ready_processing", {}, :get).
241
+ returns({'exists' => false})
242
+
243
+ KalibroClient::Entities::Processor::Repository.
244
+ expects(:request).once.
245
+ with("#{subject.id}/last_processing").
246
+ returns({'processing' => processing.to_hash})
247
+ end
248
+
249
+ it 'should return the last processing' do
250
+ response = subject.processing
251
+ expect(response.state).to eq(processing.state)
252
+ end
253
+ end
254
+ end
255
+
256
+ describe 'processing_with_date' do
257
+ context 'when the repository has a processing after the given date' do
258
+ before do
259
+ KalibroClient::Entities::Processor::Repository.
260
+ expects(:request).once.
261
+ with("#{subject.id}/has_processing/after", {date: date}).
262
+ returns({'has_processing_in_time' => true})
263
+
264
+ KalibroClient::Entities::Processor::Repository.
265
+ expects(:request).once.
266
+ with("#{subject.id}/first_processing/after", {date: date}).
267
+ returns({'processing' => processing.to_hash})
268
+ end
269
+
270
+ it 'should return the first processing after the given date' do
271
+ response = subject.processing_with_date(date)
272
+ expect(response.state).to eq(processing.state)
273
+ end
274
+ end
275
+
276
+ context 'when the repository has a processing before the given date' do
277
+ before do
278
+ KalibroClient::Entities::Processor::Repository.
279
+ expects(:request).once.
280
+ with("#{subject.id}/has_processing/after", {date: date}).
281
+ returns({'has_processing_in_time' => false})
282
+
283
+ KalibroClient::Entities::Processor::Repository.
284
+ expects(:request).once.
285
+ with("#{subject.id}/has_processing/before", {date: date}).
286
+ returns({'has_processing_in_time' => true})
287
+
288
+ KalibroClient::Entities::Processor::Repository.
289
+ expects(:request).once.
290
+ with("#{subject.id}/last_processing/before", {date: date}).
291
+ returns({'processing' => processing.to_hash})
292
+ end
293
+
294
+ it 'should return the last ready processing' do
295
+ response = subject.processing_with_date(date)
296
+ expect(response.state).to eq(processing.state)
297
+ end
298
+ end
299
+
300
+ context 'when the repository has not a processing after or before the given date' do
301
+ before do
302
+ KalibroClient::Entities::Processor::Repository.
303
+ expects(:request).once.
304
+ with("#{subject.id}/has_processing/after", {date: date}).
305
+ returns({'has_processing_in_time' => false})
306
+
307
+ KalibroClient::Entities::Processor::Repository.
308
+ expects(:request).once.
309
+ with("#{subject.id}/has_processing/before", {date: date}).
310
+ returns({'has_processing_in_time' => false})
311
+ end
312
+
313
+ it 'should return the last ready processing' do
314
+ response = subject.processing_with_date(date)
315
+ expect(response).to be_nil
316
+ end
317
+ end
318
+ end
319
+
320
+ describe 'last_ready_processing' do
321
+ before :each do
322
+ KalibroClient::Entities::Processor::Repository.
323
+ expects(:request).once.
324
+ with(':id/last_ready_processing', {id: subject.id}, :get).
325
+ returns({'last_ready_processing' => processing.to_hash})
326
+ end
327
+
328
+ it 'should return a processing object' do
329
+ response = subject.last_ready_processing
330
+ expect(response.state).to eq(processing.state)
331
+ end
332
+ end
333
+
334
+ describe 'first_processing' do
335
+ before :each do
336
+ KalibroClient::Entities::Processor::Repository.
337
+ expects(:request).once.
338
+ with("#{subject.id}/first_processing").
339
+ returns({'processing' => processing.to_hash})
340
+ end
341
+
342
+ it 'should return a processing object' do
343
+ response = subject.first_processing
344
+ expect(response.state).to eq(processing.state)
345
+ end
346
+ end
347
+
348
+ describe 'last_processing' do
349
+ before :each do
350
+ KalibroClient::Entities::Processor::Repository.
351
+ expects(:request).once.
352
+ with("#{subject.id}/last_processing").
353
+ returns({'processing' => processing.to_hash})
354
+ end
355
+
356
+ it 'should return a processing object' do
357
+ response = subject.last_processing
358
+ expect(response.state).to eq(processing.state)
359
+ end
360
+ end
361
+
362
+ describe 'first_processing_after' do
363
+ before :each do
364
+ KalibroClient::Entities::Processor::Repository.
365
+ expects(:request).once.
366
+ with("#{subject.id}/first_processing/after", {date: date}).
367
+ returns({'processing' => processing.to_hash})
368
+ end
369
+
370
+ it 'should return a processing object' do
371
+ response = subject.first_processing_after(date)
372
+ expect(response.state).to eq(processing.state)
373
+ end
374
+ end
375
+
376
+ describe 'last_processing_before' do
377
+ before :each do
378
+ KalibroClient::Entities::Processor::Repository.
379
+ expects(:request).once.
380
+ with("#{subject.id}/last_processing/before", {date: date}).
381
+ returns({'processing' => processing.to_hash})
382
+ end
383
+
384
+ it 'should return a processing object' do
385
+ response = subject.last_processing_before(date)
386
+ expect(response.state).to eq(processing.state)
387
+ end
388
+ end
389
+ end
140
390
  end
@@ -15,7 +15,7 @@
15
15
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
17
  FactoryGirl.define do
18
- factory :configuration, class: KalibroClient::Entities::Configurations::KalibroConfiguration do
18
+ factory :kalibro_configuration, class: KalibroClient::Entities::Configurations::KalibroConfiguration do
19
19
  name "Java"
20
20
  description "Code metrics for Java."
21
21
 
@@ -23,10 +23,10 @@ FactoryGirl.define do
23
23
  id 1
24
24
  end
25
25
 
26
- factory :configuration_with_id, traits: [:with_id]
26
+ factory :kalibro_configuration_with_id, traits: [:with_id]
27
27
  end
28
28
 
29
- factory :another_configuration, class: KalibroClient::Entities::Configurations::KalibroConfiguration do
29
+ factory :another_kalibro_configuration, class: KalibroClient::Entities::Configurations::KalibroConfiguration do
30
30
  id 12
31
31
  name "Perl"
32
32
  description "Code metrics for Perl."
@@ -16,8 +16,8 @@
16
16
 
17
17
  FactoryGirl.define do
18
18
  factory :range, class: KalibroClient::Entities::Configurations::KalibroRange do
19
- beginning 1.1
20
- self.end 5.1
19
+ beginning "1.1"
20
+ self.end "5.1"
21
21
  reading_id 3
22
22
  comments "Comment"
23
23
  metric_configuration_id 1
@@ -34,7 +34,13 @@ FactoryGirl.define do
34
34
  id 2
35
35
  end
36
36
 
37
+ trait :another_threshold do
38
+ beginning "0"
39
+ self.end "1.1"
40
+ end
41
+
37
42
  factory :range_with_id, traits: [:with_id]
38
- factory :another_range, traits: [:another_comment, :another_id]
43
+ factory :another_range, traits: [:another_comment, :another_threshold]
44
+ factory :another_range_with_id, traits: [:another_comment, :another_threshold, :another_id]
39
45
  end
40
46
  end
@@ -18,7 +18,7 @@ FactoryGirl.define do
18
18
  factory :metric, class: KalibroClient::Entities::Miscellaneous::Metric do
19
19
  name "Total Abstract Classes"
20
20
  code "total_abstract_classes"
21
- type :native
21
+ type "native"
22
22
  scope "SOFTWARE"
23
23
  description ""
24
24
 
@@ -17,7 +17,7 @@
17
17
  FactoryGirl.define do
18
18
  factory :reading, class: KalibroClient::Entities::Configurations::Reading do
19
19
  label "Good"
20
- grade 10.5
20
+ grade "10.5"
21
21
  color "33dd33"
22
22
  reading_group_id 31
23
23
 
@@ -22,7 +22,7 @@ FactoryGirl.define do
22
22
  period 1
23
23
  scm_type "SVN"
24
24
  address "svn://svn.code.sf.net/p/qt-calculator/code/trunk"
25
- configuration_id 1
25
+ kalibro_configuration_id 1
26
26
  project_id 1
27
27
  send_email "test@test.com"
28
28
 
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'kalibro_client/helpers/date_attributes'
3
+
4
+ include DateAttributes
5
+
6
+ class Klass
7
+ include DateAttributes
8
+ end
9
+
10
+
11
+ describe 'DateAttributes' do
12
+ subject { Klass.new }
13
+ let(:time){ "2015-02-04T15:53:18.452Z" }
14
+
15
+ describe 'created_at=' do
16
+ it 'is expected to parse it to DateTime' do
17
+ DateTime.expects(:parse).with(time)
18
+
19
+ subject.created_at = time
20
+ end
21
+ end
22
+
23
+ describe 'updated_at=' do
24
+ it 'is expected to parse it to DateTime' do
25
+ DateTime.expects(:parse).with(time)
26
+
27
+ subject.updated_at = time
28
+ end
29
+ end
30
+ end