kalibro_client 1.4.1 → 2.0.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +8 -6
- data/features/kalibro_range/find.feature +1 -1
- data/features/kalibro_range/update.feature +1 -2
- data/features/metric_result/hotspot_related_results.feature +17 -0
- data/features/metric_result/{descendant_values.feature → tree/descendant_values.feature} +0 -0
- data/features/metric_result/{history_of.feature → tree/history_of.feature} +0 -0
- data/features/step_definitions/hotspot_metric_result_step.rb +15 -0
- data/features/step_definitions/metric_result_steps.rb +3 -3
- data/features/step_definitions/processing_steps.rb +5 -7
- data/features/step_definitions/repository_steps.rb +5 -0
- data/lib/kalibro_client/entities.rb +3 -1
- data/lib/kalibro_client/entities/base.rb +45 -44
- data/lib/kalibro_client/entities/configurations/metric_configuration.rb +7 -3
- data/lib/kalibro_client/entities/processor/hotspot_metric_result.rb +41 -0
- data/lib/kalibro_client/entities/processor/metric_result.rb +12 -32
- data/lib/kalibro_client/entities/processor/module_result.rb +20 -2
- data/lib/kalibro_client/entities/processor/tree_metric_result.rb +54 -0
- data/lib/kalibro_client/errors.rb +3 -1
- data/lib/kalibro_client/errors/record_invalid.rb +19 -0
- data/lib/kalibro_client/errors/record_not_found.rb +2 -2
- data/lib/kalibro_client/errors/request_error.rb +27 -0
- data/lib/kalibro_client/helpers/aggregation_options.rb +1 -1
- data/lib/kalibro_client/version.rb +1 -1
- data/spec/entities/base_spec.rb +292 -201
- data/spec/entities/configurations/metric_configuration_spec.rb +1 -1
- data/spec/entities/processor/hotspot_metric_result_spec.rb +49 -0
- data/spec/entities/processor/metric_result_spec.rb +31 -89
- data/spec/entities/processor/module_result_spec.rb +90 -61
- data/spec/entities/processor/tree_metric_result_spec.rb +128 -0
- data/spec/errors/record_invalid_spec.rb +45 -0
- data/spec/factories/hotspot_metric_results.rb +24 -0
- data/spec/factories/metric_configurations.rb +1 -1
- data/spec/factories/metric_results.rb +0 -1
- data/spec/factories/tree_metric_results.rb +24 -0
- data/spec/helpers/aggregation_options_spec.rb +1 -1
- metadata +24 -6
@@ -216,7 +216,7 @@ describe KalibroClient::Entities::Configurations::MetricConfiguration do
|
|
216
216
|
KalibroClient::Entities::Configurations::MetricConfiguration.
|
217
217
|
expects(:request).
|
218
218
|
with(':id', {id: metric_configuration.id}, :get).
|
219
|
-
|
219
|
+
raises(KalibroClient::Errors::RequestError)
|
220
220
|
end
|
221
221
|
|
222
222
|
it 'should raise the RecordNotFound error' do
|
@@ -0,0 +1,49 @@
|
|
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::HotspotMetricResult do
|
20
|
+
describe 'new' do
|
21
|
+
context 'with the expected attributes' do
|
22
|
+
let(:attributes) { FactoryGirl.build(:hotspot_metric_result).to_hash }
|
23
|
+
subject { KalibroClient::Entities::Processor::HotspotMetricResult.new attributes }
|
24
|
+
|
25
|
+
it 'should cast the line_number attribute to an integer' do
|
26
|
+
expect(subject.line_number).to be_a Integer
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'related_results' do
|
32
|
+
subject { FactoryGirl.build(:hotspot_metric_result) }
|
33
|
+
context 'with related metric results' do
|
34
|
+
let(:related_result) { FactoryGirl.build(:hotspot_metric_result) }
|
35
|
+
|
36
|
+
before do
|
37
|
+
KalibroClient::Entities::Processor::HotspotMetricResult.expects(:request).with(':id/related_results', {id: subject.id}, :get).returns({"hotspot_metric_results" => [subject.to_hash, related_result.to_hash]})
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return the related metric results and itself' do
|
41
|
+
results = subject.related_results
|
42
|
+
expect(results).to include(subject)
|
43
|
+
expect(results).to include(related_result)
|
44
|
+
expect(results.size).to eq(2)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -27,20 +27,6 @@ describe KalibroClient::Entities::Processor::MetricResult do
|
|
27
27
|
returns({'metric_configuration' => metric_configuration.to_hash})
|
28
28
|
end
|
29
29
|
|
30
|
-
describe 'new' do
|
31
|
-
before :each do
|
32
|
-
subject.metric_configuration_id = metric_configuration.id
|
33
|
-
end
|
34
|
-
context 'with value NaN' do
|
35
|
-
it 'should set the value with aggregated_value' do
|
36
|
-
attributes_hash = FactoryGirl.build(:metric_result, {"aggregated_value" => 1.6}).to_hash
|
37
|
-
attributes_hash["value"] = "NaN"
|
38
|
-
metric_result = KalibroClient::Entities::Processor::MetricResult.new(attributes_hash)
|
39
|
-
expect(metric_result.value).to eq(1.6)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
30
|
describe 'id=' do
|
45
31
|
it 'should set the value of the attribute id' do
|
46
32
|
subject.id = 42
|
@@ -59,96 +45,52 @@ describe KalibroClient::Entities::Processor::MetricResult do
|
|
59
45
|
end
|
60
46
|
end
|
61
47
|
|
62
|
-
describe '
|
63
|
-
|
64
|
-
subject.value = 42
|
65
|
-
expect(subject.value).to eq(42)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe 'aggregated_value=' do
|
70
|
-
it 'should set the value of the attribute aggregated_value' do
|
71
|
-
subject.aggregated_value = 42
|
72
|
-
expect(subject.aggregated_value).to eq(42)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'descendant_values' do
|
77
|
-
context 'when there is one descendant value for the given metric_result' do
|
48
|
+
describe 'metric_configuration' do
|
49
|
+
context 'when metric_configuration_id is nil' do
|
78
50
|
before :each do
|
79
|
-
|
80
|
-
expects(:request).
|
81
|
-
with(':id/descendant_values', { id: subject.id }, :get).
|
82
|
-
returns({'descendant_values' => [13.3]})
|
51
|
+
subject.metric_configuration_id = nil
|
83
52
|
end
|
84
53
|
|
85
|
-
it '
|
86
|
-
expect(subject.
|
54
|
+
it 'is expected to return nil' do
|
55
|
+
expect(subject.metric_configuration).to be_nil
|
87
56
|
end
|
88
57
|
end
|
89
58
|
|
90
|
-
context 'when
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
with(':id/descendant_values', { id: subject.id }, :get).
|
95
|
-
returns({'descendant_values' => []})
|
96
|
-
end
|
59
|
+
context 'when metric_configuration_id is not nil' do
|
60
|
+
subject { FactoryGirl.build(:metric_result,
|
61
|
+
metric_configuration: nil,
|
62
|
+
metric_configuration_id: metric_configuration.id) }
|
97
63
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
describe 'history_of' do
|
105
|
-
let(:kalibro_module) { FactoryGirl.build(:kalibro_module_with_id) }
|
106
|
-
let(:metric) { FactoryGirl.build(:metric) }
|
107
|
-
let(:repository) { FactoryGirl.build(:repository_with_id) }
|
64
|
+
context 'and it has already been memoized' do
|
65
|
+
before :each do
|
66
|
+
subject.metric_configuration = metric_configuration
|
67
|
+
end
|
108
68
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
expects(:request).
|
113
|
-
with(':id/metric_result_history_of', {:metric_name => metric.name, :kalibro_module_id => kalibro_module.id, id: repository.id}).
|
114
|
-
returns({'metric_result_history_of' => []})
|
69
|
+
it 'is expected to return the memoized instance' do
|
70
|
+
expect(subject.metric_configuration).to eq(metric_configuration)
|
71
|
+
end
|
115
72
|
end
|
116
73
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
74
|
+
context 'and it has not been memoized' do
|
75
|
+
before do
|
76
|
+
subject.metric_configuration_id = metric_configuration.id
|
77
|
+
end
|
121
78
|
|
122
|
-
|
123
|
-
|
79
|
+
it 'is expected to find the metric configuration from its id' do
|
80
|
+
KalibroClient::Entities::Configurations::MetricConfiguration.expects(:find).
|
81
|
+
with(subject.metric_configuration_id).
|
82
|
+
returns(metric_configuration)
|
124
83
|
|
125
|
-
|
126
|
-
|
127
|
-
expects(:request).with(':id/metric_result_history_of', {:metric_name => metric.name, :kalibro_module_id => kalibro_module.id, id: repository.id})
|
128
|
-
.returns({'metric_result_history_of' => [date_metric_result.to_hash]})
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'should return the date metric result as an object into a list' do
|
132
|
-
expect(KalibroClient::Entities::Processor::MetricResult.history_of(metric.name, kalibro_module.id, repository.id).first.metric_result.id).to eq(subject.id)
|
84
|
+
expect(subject.metric_configuration).to eq(metric_configuration)
|
85
|
+
end
|
133
86
|
end
|
134
87
|
end
|
88
|
+
end
|
135
89
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
before :each do
|
141
|
-
KalibroClient::Entities::Processor::Repository.
|
142
|
-
expects(:request).
|
143
|
-
with(':id/metric_result_history_of', {:metric_name => metric.name, :kalibro_module_id => kalibro_module.id, id: repository.id}).
|
144
|
-
returns({'metric_result_history_of' => [date_metric_result.to_hash, another_date_metric_result.to_hash]})
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'should return a list of date metric results as objects' do
|
148
|
-
response = KalibroClient::Entities::Processor::MetricResult.history_of(metric.name, kalibro_module.id, repository.id)
|
149
|
-
expect(response.first.metric_result.id).to eq(date_metric_result.metric_result.id)
|
150
|
-
expect(response.last.metric_result.id).to eq(another_date_metric_result.metric_result.id)
|
151
|
-
end
|
90
|
+
describe 'value=' do
|
91
|
+
it 'should set the value of the attribute value' do
|
92
|
+
subject.value = 42
|
93
|
+
expect(subject.value).to eq(42)
|
152
94
|
end
|
153
95
|
end
|
154
96
|
end
|
@@ -19,40 +19,6 @@ require 'spec_helper'
|
|
19
19
|
describe KalibroClient::Entities::Processor::ModuleResult do
|
20
20
|
subject { FactoryGirl.build(:module_result, id: rand(Time.now.to_i)) }
|
21
21
|
|
22
|
-
describe 'find' do
|
23
|
-
context 'when there is a module result for the given id' do
|
24
|
-
before :each do
|
25
|
-
KalibroClient::Entities::Processor::ModuleResult.
|
26
|
-
expects(:request).
|
27
|
-
with(':id/exists', { id: subject.id }, :get).
|
28
|
-
returns("exists" => true)
|
29
|
-
KalibroClient::Entities::Processor::ModuleResult.
|
30
|
-
expects(:request).
|
31
|
-
with(':id', { id: subject.id }, :get).
|
32
|
-
returns("module_result" => subject.to_hash)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should return a hash with module result' do
|
36
|
-
expect(KalibroClient::Entities::Processor::ModuleResult.
|
37
|
-
find(subject.id).id).to eq(subject.id)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "when there isn't a module result for the given id" do
|
42
|
-
before :each do
|
43
|
-
KalibroClient::Entities::Processor::ModuleResult.
|
44
|
-
expects(:request).
|
45
|
-
with(':id/exists', { id: subject.id }, :get).
|
46
|
-
returns("exists" => false)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should raise an error' do
|
50
|
-
expect {KalibroClient::Entities::Processor::ModuleResult.find(subject.id)}.
|
51
|
-
to raise_error KalibroClient::Errors::RecordNotFound
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
22
|
describe 'children' do
|
57
23
|
before :each do
|
58
24
|
KalibroClient::Entities::Processor::ModuleResult.
|
@@ -71,14 +37,7 @@ describe KalibroClient::Entities::Processor::ModuleResult do
|
|
71
37
|
|
72
38
|
context 'when module result has a parent' do
|
73
39
|
before :each do
|
74
|
-
|
75
|
-
expects(:request).
|
76
|
-
with(':id/exists', { id: subject.parent_id }, :get).
|
77
|
-
returns("exists" => true)
|
78
|
-
KalibroClient::Entities::Processor::ModuleResult.
|
79
|
-
expects(:request).at_least_once.
|
80
|
-
with(':id', { id: subject.parent_id }, :get).
|
81
|
-
returns("module_result" => root_module_result.to_hash)
|
40
|
+
subject.class.expects(:find).with(subject.parent_id).returns(root_module_result)
|
82
41
|
end
|
83
42
|
|
84
43
|
it 'should return its parent' do
|
@@ -178,39 +137,68 @@ describe KalibroClient::Entities::Processor::ModuleResult do
|
|
178
137
|
end
|
179
138
|
end
|
180
139
|
|
181
|
-
describe '
|
140
|
+
describe 'tree_metric_results' do
|
141
|
+
subject { FactoryGirl.build(:root_module_result) }
|
142
|
+
let(:metric_configuration) { FactoryGirl.build(:metric_configuration, :with_id) }
|
143
|
+
let(:tree_metric_result_1) { FactoryGirl.build(:tree_metric_result, metric_configuration: metric_configuration) }
|
144
|
+
let(:tree_metric_result_2) { FactoryGirl.build(:tree_metric_result, metric_configuration: metric_configuration) }
|
145
|
+
|
146
|
+
context 'with tree metric results' do
|
147
|
+
before :each do
|
148
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
149
|
+
expects(:request).
|
150
|
+
with(':id/metric_results', {id: subject.id}, :get).
|
151
|
+
returns({'tree_metric_results' => [tree_metric_result_1.to_hash, tree_metric_result_2.to_hash]})
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should return the tree metric results' do
|
155
|
+
expect(subject.tree_metric_results).to eq([tree_metric_result_1, tree_metric_result_2])
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'without tree metric results' do
|
160
|
+
before :each do
|
161
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
162
|
+
expects(:request).
|
163
|
+
with(':id/metric_results', {id: subject.id}, :get).
|
164
|
+
returns({'tree_metric_results' => []})
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should return an empty array' do
|
168
|
+
expect(subject.tree_metric_results).to eq([])
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe 'hotspot_metric_results' do
|
182
174
|
subject { FactoryGirl.build(:root_module_result) }
|
183
175
|
let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
|
184
|
-
let(:
|
185
|
-
let(:
|
176
|
+
let(:hotspot_metric_result_1) { FactoryGirl.build(:hotspot_metric_result, metric_configuration: metric_configuration) }
|
177
|
+
let(:hotspot_metric_result_2) { FactoryGirl.build(:hotspot_metric_result, metric_configuration: metric_configuration) }
|
186
178
|
|
187
|
-
context 'with metric results' do
|
179
|
+
context 'with hotspot metric results' do
|
188
180
|
before :each do
|
189
181
|
KalibroClient::Entities::Processor::ModuleResult.
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
KalibroClient::Entities::Configurations::MetricConfiguration.
|
194
|
-
expects(:request).
|
195
|
-
with(':id', {id: metric_configuration.id}, :get).twice.
|
196
|
-
returns({'metric_configuration' => metric_configuration.to_hash})
|
182
|
+
expects(:request).
|
183
|
+
with(':id/hotspot_metric_results', {id: subject.id}, :get).
|
184
|
+
returns({'hotspot_metric_results' => [hotspot_metric_result_1.to_hash, hotspot_metric_result_2.to_hash]})
|
197
185
|
end
|
198
186
|
|
199
|
-
it 'should return the metric results' do
|
200
|
-
expect(subject.
|
187
|
+
it 'should return the hotspot metric results' do
|
188
|
+
expect(subject.hotspot_metric_results).to eq([hotspot_metric_result_1, hotspot_metric_result_2])
|
201
189
|
end
|
202
190
|
end
|
203
191
|
|
204
|
-
context 'without metric results' do
|
192
|
+
context 'without hotspot metric results' do
|
205
193
|
before :each do
|
206
194
|
KalibroClient::Entities::Processor::ModuleResult.
|
207
|
-
|
208
|
-
|
209
|
-
|
195
|
+
expects(:request).
|
196
|
+
with(':id/hotspot_metric_results', {id: subject.id}, :get).
|
197
|
+
returns({'hotspot_metric_results' => []})
|
210
198
|
end
|
211
199
|
|
212
|
-
it 'should return
|
213
|
-
expect(subject.
|
200
|
+
it 'should return an empty array' do
|
201
|
+
expect(subject.hotspot_metric_results).to eq([])
|
214
202
|
end
|
215
203
|
end
|
216
204
|
end
|
@@ -224,4 +212,45 @@ describe KalibroClient::Entities::Processor::ModuleResult do
|
|
224
212
|
expect(subject.processing).to eq(processing)
|
225
213
|
end
|
226
214
|
end
|
215
|
+
|
216
|
+
describe 'find' do
|
217
|
+
let(:id) { 1 }
|
218
|
+
|
219
|
+
context 'when the ModuleResult exists' do
|
220
|
+
let!(:module_result) { FactoryGirl.build(:module_result) }
|
221
|
+
before :each do
|
222
|
+
KalibroClient::Entities::Base.expects(:find).with(id).returns(module_result)
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'is expected to return the found module result' do
|
226
|
+
expect(described_class.find(id)).to eq(module_result)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'when the ModuleResult does not exist' do
|
231
|
+
before :each do
|
232
|
+
response = mock('response')
|
233
|
+
response.expects(:status).at_least_once.returns(422)
|
234
|
+
|
235
|
+
KalibroClient::Entities::Base.expects(:find).with(id).raises(KalibroClient::Errors::RequestError.new(response: response))
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'is expected to raise a RecordNotFound error' do
|
239
|
+
expect { described_class.find(id) }.to raise_error(KalibroClient::Errors::RecordNotFound)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
context 'when there is an unexpected server error' do
|
244
|
+
before :each do
|
245
|
+
response = mock('response')
|
246
|
+
response.expects(:status).at_least_once.returns(500)
|
247
|
+
|
248
|
+
KalibroClient::Entities::Base.expects(:find).with(id).raises(KalibroClient::Errors::RequestError.new(response: response))
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'is expected to raise a RequestError' do
|
252
|
+
expect { described_class.find(id) }.to raise_error(KalibroClient::Errors::RequestError)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
227
256
|
end
|
@@ -0,0 +1,128 @@
|
|
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::TreeMetricResult do
|
20
|
+
let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
|
21
|
+
|
22
|
+
before do
|
23
|
+
KalibroClient::Entities::Configurations::MetricConfiguration.
|
24
|
+
stubs(:request).
|
25
|
+
with(':id', {id: metric_configuration.id}, :get).
|
26
|
+
returns({'metric_configuration' => metric_configuration.to_hash})
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'new' do
|
30
|
+
before :each do
|
31
|
+
subject.metric_configuration_id = metric_configuration.id
|
32
|
+
end
|
33
|
+
context 'with value NaN' do
|
34
|
+
it 'should set the value with aggregated_value' do
|
35
|
+
attributes_hash = FactoryGirl.build(:tree_metric_result, {"aggregated_value" => 1.6}).to_hash
|
36
|
+
attributes_hash["value"] = "NaN"
|
37
|
+
metric_result = KalibroClient::Entities::Processor::TreeMetricResult.new(attributes_hash)
|
38
|
+
expect(metric_result.value).to eq(1.6)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'aggregated_value=' do
|
44
|
+
it 'should set the value of the attribute aggregated_value' do
|
45
|
+
subject.aggregated_value = 42
|
46
|
+
expect(subject.aggregated_value).to eq(42)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'descendant_values' do
|
51
|
+
context 'when there is one descendant value for the given metric_result' do
|
52
|
+
before :each do
|
53
|
+
KalibroClient::Entities::Processor::TreeMetricResult.
|
54
|
+
expects(:request).
|
55
|
+
with(':id/descendant_values', { id: subject.id }, :get).
|
56
|
+
returns({'descendant_values' => [13.3]})
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should return an unitary list with the descendant value' do
|
60
|
+
expect(subject.descendant_values).to eq([13.3])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when there is no descendant value for the given metric_result' do
|
65
|
+
before :each do
|
66
|
+
KalibroClient::Entities::Processor::TreeMetricResult.
|
67
|
+
expects(:request).
|
68
|
+
with(':id/descendant_values', { id: subject.id }, :get).
|
69
|
+
returns({'descendant_values' => []})
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should return an empty list' do
|
73
|
+
expect(subject.descendant_values).to eq([])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe 'history_of' do
|
79
|
+
let(:kalibro_module) { FactoryGirl.build(:kalibro_module_with_id) }
|
80
|
+
let(:metric) { FactoryGirl.build(:metric) }
|
81
|
+
let(:repository) { FactoryGirl.build(:repository_with_id) }
|
82
|
+
|
83
|
+
context 'when there is not a date metric result' do
|
84
|
+
before :each do
|
85
|
+
KalibroClient::Entities::Processor::Repository.
|
86
|
+
expects(:request).
|
87
|
+
with(':id/metric_result_history_of', {:metric_name => metric.name, :kalibro_module_id => kalibro_module.id, id: repository.id}).
|
88
|
+
returns({'metric_result_history_of' => []})
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should return an empty list' do
|
92
|
+
expect(KalibroClient::Entities::Processor::TreeMetricResult.history_of(metric.name, kalibro_module.id, repository.id)).to eq([])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when there is only one date metric result' do
|
97
|
+
let!(:date_metric_result) { FactoryGirl.build(:date_metric_result, metric_result: subject.to_hash) }
|
98
|
+
|
99
|
+
before :each do
|
100
|
+
KalibroClient::Entities::Processor::Repository.
|
101
|
+
expects(:request).with(':id/metric_result_history_of', {:metric_name => metric.name, :kalibro_module_id => kalibro_module.id, id: repository.id})
|
102
|
+
.returns({'metric_result_history_of' => [date_metric_result.to_hash]})
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should return the date metric result as an object into a list' do
|
106
|
+
expect(KalibroClient::Entities::Processor::TreeMetricResult.history_of(metric.name, kalibro_module.id, repository.id).first.metric_result.id).to eq(subject.id)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when there are many date metric results' do
|
111
|
+
let(:date_metric_result) { FactoryGirl.build(:date_metric_result, {metric_result: subject.to_hash}) }
|
112
|
+
let(:another_date_metric_result) { FactoryGirl.build(:another_date_metric_result, {metric_result: subject.to_hash}) }
|
113
|
+
|
114
|
+
before :each do
|
115
|
+
KalibroClient::Entities::Processor::Repository.
|
116
|
+
expects(:request).
|
117
|
+
with(':id/metric_result_history_of', {:metric_name => metric.name, :kalibro_module_id => kalibro_module.id, id: repository.id}).
|
118
|
+
returns({'metric_result_history_of' => [date_metric_result.to_hash, another_date_metric_result.to_hash]})
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should return a list of date metric results as objects' do
|
122
|
+
response = KalibroClient::Entities::Processor::TreeMetricResult.history_of(metric.name, kalibro_module.id, repository.id)
|
123
|
+
expect(response.first.metric_result.id).to eq(date_metric_result.metric_result.id)
|
124
|
+
expect(response.last.metric_result.id).to eq(another_date_metric_result.metric_result.id)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|