kalibro_client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +27 -0
- data/AUTHORS +4 -0
- data/COPYING +674 -0
- data/COPYING.LESSER +165 -0
- data/Gemfile +4 -0
- data/README.md +77 -0
- data/Rakefile +6 -0
- data/cucumber.yml +1 -0
- data/features/kalibro_configuration/all.feature +10 -0
- data/features/kalibro_configuration/creation.feature +9 -0
- data/features/kalibro_configuration/destroy.feature +10 -0
- data/features/kalibro_configuration/metric_configurations.feature +12 -0
- data/features/metric_collector_details/all_names.feature +8 -0
- data/features/metric_collector_details/find_by_name.feature +12 -0
- data/features/metric_configuration/creation.feature +11 -0
- data/features/metric_configuration/destroy.feature +12 -0
- data/features/metric_configuration/find.feature +18 -0
- data/features/metric_configuration/metric_configurations_of.feature +18 -0
- data/features/metric_result/descendant_values.feature +19 -0
- data/features/metric_result/history_of.feature +20 -0
- data/features/metric_result/metric_results_of.feature +20 -0
- data/features/module_result/children.feature +19 -0
- data/features/module_result/find.feature +22 -0
- data/features/module_result/history_of.feature +19 -0
- data/features/processing/first_processing_after.feature +18 -0
- data/features/processing/first_processing_of.feature +18 -0
- data/features/processing/has_processing.feature +18 -0
- data/features/processing/has_processing_after.feature +18 -0
- data/features/processing/has_processing_before.feature +18 -0
- data/features/processing/has_ready_processing.feature +18 -0
- data/features/processing/last_processing_before.feature +18 -0
- data/features/processing/last_processing_of.feature +18 -0
- data/features/processing/last_processing_state_of.feature +18 -0
- data/features/processing/last_ready_processing_of.feature +19 -0
- data/features/processing/processing_of.feature +32 -0
- data/features/processing/processing_with_date_of.feature +32 -0
- data/features/project/all.feature +10 -0
- data/features/project/creation.feature +9 -0
- data/features/project/destroy.feature +10 -0
- data/features/project/exists.feature +9 -0
- data/features/project/find.feature +10 -0
- data/features/range/destroy.feature +14 -0
- data/features/range/exists.feature +13 -0
- data/features/range/find.feature +14 -0
- data/features/range/ranges_of.feature +22 -0
- data/features/range/save.feature +14 -0
- data/features/reading/destroy.feature +13 -0
- data/features/reading/exists.feature +13 -0
- data/features/reading/find.feature +11 -0
- data/features/reading/readings_of.feature +11 -0
- data/features/reading_group/all.feature +10 -0
- data/features/reading_group/creation.feature +9 -0
- data/features/reading_group/destroy.feature +11 -0
- data/features/repository/all.feature +14 -0
- data/features/repository/cancel_processing.feature +14 -0
- data/features/repository/destroy.feature +14 -0
- data/features/repository/exists.feature +14 -0
- data/features/repository/find.feature +14 -0
- data/features/repository/of.feature +15 -0
- data/features/repository/process.feature +16 -0
- data/features/repository/types.feature +8 -0
- data/features/step_definitions/configuration_steps.rb +40 -0
- data/features/step_definitions/metric_collector_details_steps.rb +28 -0
- data/features/step_definitions/metric_configuration_steps.rb +61 -0
- data/features/step_definitions/metric_result_steps.rb +33 -0
- data/features/step_definitions/metric_steps.rb +3 -0
- data/features/step_definitions/module_result_steps.rb +46 -0
- data/features/step_definitions/processing_steps.rb +95 -0
- data/features/step_definitions/project_steps.rb +48 -0
- data/features/step_definitions/range_steps.rb +72 -0
- data/features/step_definitions/reading_group_steps.rb +36 -0
- data/features/step_definitions/reading_steps.rb +47 -0
- data/features/step_definitions/repository_steps.rb +71 -0
- data/features/support/env.rb +25 -0
- data/features/support/kalibro_cucumber_helpers.yml.sample +3 -0
- data/kalibro_client.gemspec +49 -0
- data/lib/kalibro_client.rb +62 -0
- data/lib/kalibro_client/entities.rb +40 -0
- data/lib/kalibro_client/entities/base.rb +196 -0
- data/lib/kalibro_client/entities/configurations/base.rb +13 -0
- data/lib/kalibro_client/entities/configurations/kalibro_configuration.rb +37 -0
- data/lib/kalibro_client/entities/configurations/kalibro_range.rb +77 -0
- data/lib/kalibro_client/entities/configurations/metric_configuration.rb +93 -0
- data/lib/kalibro_client/entities/configurations/range_snapshot.rb +37 -0
- data/lib/kalibro_client/entities/configurations/reading.rb +56 -0
- data/lib/kalibro_client/entities/configurations/reading_group.rb +34 -0
- data/lib/kalibro_client/entities/miscellaneous/base.rb +57 -0
- data/lib/kalibro_client/entities/miscellaneous/compound_metric.rb +21 -0
- data/lib/kalibro_client/entities/miscellaneous/date_metric_result.rb +14 -0
- data/lib/kalibro_client/entities/miscellaneous/date_module_result.rb +18 -0
- data/lib/kalibro_client/entities/miscellaneous/granularity.rb +54 -0
- data/lib/kalibro_client/entities/miscellaneous/metric.rb +19 -0
- data/lib/kalibro_client/entities/miscellaneous/native_metric.rb +24 -0
- data/lib/kalibro_client/entities/processor/base.rb +16 -0
- data/lib/kalibro_client/entities/processor/kalibro_module.rb +27 -0
- data/lib/kalibro_client/entities/processor/metric_collector_details.rb +53 -0
- data/lib/kalibro_client/entities/processor/metric_result.rb +79 -0
- data/lib/kalibro_client/entities/processor/module_result.rb +82 -0
- data/lib/kalibro_client/entities/processor/process_time.rb +31 -0
- data/lib/kalibro_client/entities/processor/processing.rb +109 -0
- data/lib/kalibro_client/entities/processor/project.rb +34 -0
- data/lib/kalibro_client/entities/processor/repository.rb +75 -0
- data/lib/kalibro_client/errors.rb +18 -0
- data/lib/kalibro_client/errors/record_not_found.rb +22 -0
- data/lib/kalibro_client/errors/standard.rb +24 -0
- data/lib/kalibro_client/helpers/aggregation_options.rb +25 -0
- data/lib/kalibro_client/helpers/hash_converters.rb +48 -0
- data/lib/kalibro_client/helpers/request_methods.rb +55 -0
- data/lib/kalibro_client/helpers/xml_converters.rb +20 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers.rb +60 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers/configuration.rb +30 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers/hooks.rb +25 -0
- data/lib/kalibro_client/version.rb +19 -0
- data/lib/rake/test_task.rb +57 -0
- data/spec/entities/base_spec.rb +313 -0
- data/spec/entities/configurations/base_spec.rb +26 -0
- data/spec/entities/configurations/kalibro_configuration_spec.rb +91 -0
- data/spec/entities/configurations/kalibro_range_spec.rb +174 -0
- data/spec/entities/configurations/metric_configuration_spec.rb +230 -0
- data/spec/entities/configurations/range_snapshot_spec.rb +50 -0
- data/spec/entities/configurations/reading_group_spec.rb +60 -0
- data/spec/entities/configurations/reading_spec.rb +87 -0
- data/spec/entities/miscellaneous/base_spec.rb +49 -0
- data/spec/entities/miscellaneous/compound_metric_spec.rb +36 -0
- data/spec/entities/miscellaneous/date_metric_result_spec.rb +4 -0
- data/spec/entities/miscellaneous/date_module_result_spec.rb +0 -0
- data/spec/entities/miscellaneous/granularity_spec.rb +96 -0
- data/spec/entities/miscellaneous/metric_spec.rb +15 -0
- data/spec/entities/miscellaneous/native_metric_spec.rb +37 -0
- data/spec/entities/processor/base_spec.rb +26 -0
- data/spec/entities/processor/metric_collector_details_spec.rb +146 -0
- data/spec/entities/processor/metric_result_spec.rb +209 -0
- data/spec/entities/processor/module_result_spec.rb +178 -0
- data/spec/entities/processor/process_time_spec.rb +33 -0
- data/spec/entities/processor/processing_spec.rb +333 -0
- data/spec/entities/processor/project_spec.rb +68 -0
- data/spec/entities/processor/repository_spec.rb +140 -0
- data/spec/factories/date_metric_results.rb +30 -0
- data/spec/factories/date_module_results.rb +24 -0
- data/spec/factories/granularities.rb +23 -0
- data/spec/factories/kalibro_configurations.rb +34 -0
- data/spec/factories/kalibro_module.rb +28 -0
- data/spec/factories/kalibro_ranges.rb +40 -0
- data/spec/factories/metric_collector_details.rb +30 -0
- data/spec/factories/metric_configurations.rb +31 -0
- data/spec/factories/metric_results.rb +24 -0
- data/spec/factories/metrics.rb +48 -0
- data/spec/factories/models.rb +23 -0
- data/spec/factories/module_results.rb +43 -0
- data/spec/factories/process_times.rb +27 -0
- data/spec/factories/processings.rb +24 -0
- data/spec/factories/projects.rb +35 -0
- data/spec/factories/ranges_snapshot.rb +26 -0
- data/spec/factories/reading_groups.rb +28 -0
- data/spec/factories/readings.rb +30 -0
- data/spec/factories/repositories.rb +39 -0
- data/spec/helpers/aggregation_options_spec.rb +31 -0
- data/spec/helpers/hash_converters_spec.rb +111 -0
- data/spec/helpers/xml_converters_spec.rb +64 -0
- data/spec/kalibro_entities_spec.rb +112 -0
- data/spec/savon/fixtures/config.yml +2 -0
- data/spec/savon/fixtures/invalid_config.yml +2 -0
- data/spec/savon/fixtures/project/does_not_exists.xml +1 -0
- data/spec/savon/savon_test_helper.rb +14 -0
- data/spec/spec_helper.rb +111 -0
- metadata +479 -0
@@ -0,0 +1,26 @@
|
|
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::Configurations::Base do
|
20
|
+
|
21
|
+
describe 'client' do
|
22
|
+
it 'returns a Faraday::Connection' do
|
23
|
+
expect(KalibroClient::Entities::Configurations::Base.client).to be_a(Faraday::Connection)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,91 @@
|
|
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::Configurations::KalibroConfiguration do
|
20
|
+
describe 'id=' do
|
21
|
+
it 'should set the value of the attribute id as an Integer' do
|
22
|
+
subject.id = "42"
|
23
|
+
expect(subject.id).to eq(42)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'all' do
|
28
|
+
context 'with no configurations' do
|
29
|
+
before :each do
|
30
|
+
KalibroClient::Entities::Configurations::KalibroConfiguration.
|
31
|
+
expects(:request).
|
32
|
+
with('', {}, :get).
|
33
|
+
returns({'kalibro_configurations' => nil})
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should return nil' do
|
37
|
+
expect(KalibroClient::Entities::Configurations::KalibroConfiguration.all).to be_empty
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with many configurations' do
|
42
|
+
let(:configuration) { FactoryGirl.build(:configuration_with_id) }
|
43
|
+
let(:another_configuration) { FactoryGirl.build(:another_configuration) }
|
44
|
+
|
45
|
+
before :each do
|
46
|
+
KalibroClient::Entities::Configurations::KalibroConfiguration.
|
47
|
+
expects(:request).
|
48
|
+
with('', {}, :get).
|
49
|
+
returns({'kalibro_configurations' => [configuration.to_hash, another_configuration.to_hash]})
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should return the two elements' do
|
53
|
+
configurations = KalibroClient::Entities::Configurations::KalibroConfiguration.all
|
54
|
+
|
55
|
+
expect(configurations.size).to eq(2)
|
56
|
+
expect(configurations.first.name).to eq(configuration.name)
|
57
|
+
expect(configurations.last.name).to eq(another_configuration.name)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'metric_configurations' do
|
63
|
+
context 'with no metric configurations' do
|
64
|
+
before :each do
|
65
|
+
KalibroClient::Entities::Configurations::KalibroConfiguration.
|
66
|
+
expects(:request).
|
67
|
+
with(':id/metric_configurations', {id: subject.id}, :get).
|
68
|
+
returns({'metric_configurations' => []})
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should return an empty array' do
|
72
|
+
expect(subject.metric_configurations).to be_empty
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'with metric configurations' do
|
77
|
+
let(:metric_configuration_1) { FactoryGirl.build(:metric_configuration, kalibro_configuration_id: subject.id) }
|
78
|
+
let(:metric_configuration_2) { FactoryGirl.build(:metric_configuration, kalibro_configuration_id: subject.id) }
|
79
|
+
before :each do
|
80
|
+
KalibroClient::Entities::Configurations::KalibroConfiguration.
|
81
|
+
expects(:request).
|
82
|
+
with(':id/metric_configurations', {id: subject.id}, :get).
|
83
|
+
returns({'metric_configurations' => [metric_configuration_1.to_hash, metric_configuration_2.to_hash]})
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should return an empty array' do
|
87
|
+
expect(subject.metric_configurations).to eq([metric_configuration_1, metric_configuration_2])
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,174 @@
|
|
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::Configurations::KalibroRange do
|
20
|
+
subject { FactoryGirl.build(:range_with_id) }
|
21
|
+
|
22
|
+
describe 'id=' do
|
23
|
+
it 'should set the value of the attribute id as an integer' do
|
24
|
+
subject.id = "4"
|
25
|
+
expect(subject.id).to eq(4)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'reading_id=' do
|
30
|
+
it 'should set the value of the attribute reading_id as an integer' do
|
31
|
+
subject.reading_id = "12"
|
32
|
+
expect(subject.reading_id).to eq(12)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'beginning=' do
|
37
|
+
it 'should set the value of the attribute as a float' do
|
38
|
+
subject.beginning = "12.3"
|
39
|
+
expect(subject.beginning).to eq(12.3)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should set beginning to infinity' do
|
43
|
+
subject.beginning = "-INF"
|
44
|
+
expect(subject.beginning).to eq("-INF")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'end=' do
|
49
|
+
it 'should set the value of the attribute as a float' do
|
50
|
+
subject.end = "23.4"
|
51
|
+
expect(subject.end).to eq(23.4)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should set end to infinity' do
|
55
|
+
subject.end = "INF"
|
56
|
+
expect(subject.end).to eq("INF")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'getting reading attribute' do
|
61
|
+
let(:reading) { FactoryGirl.build(:reading_with_id) }
|
62
|
+
|
63
|
+
before :each do
|
64
|
+
KalibroClient::Entities::Configurations::Reading.
|
65
|
+
expects(:find).
|
66
|
+
with(subject.reading_id).
|
67
|
+
returns(reading)
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'reading' do
|
71
|
+
it 'should return the correct reading' do
|
72
|
+
expect(subject.reading).to eq(reading)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'label' do
|
77
|
+
it 'should get the label of the reading' do
|
78
|
+
expect(subject.label).to eq(reading.label)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'grade' do
|
83
|
+
it 'should get the grade of the reading' do
|
84
|
+
expect(subject.grade).to eq(reading.grade)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'color' do
|
89
|
+
it 'should get the color of the reading' do
|
90
|
+
expect(subject.color).to eq(reading.color)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'ranges_of' do
|
96
|
+
let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
|
97
|
+
|
98
|
+
context 'when does not exists the asked range' do
|
99
|
+
before :each do
|
100
|
+
KalibroClient::Entities::Configurations::KalibroRange.
|
101
|
+
expects(:request).
|
102
|
+
with('', {}, :get, "metric_configurations/#{metric_configuration.id}").
|
103
|
+
returns({'ranges' => nil})
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should return a list with the ranges' do
|
107
|
+
expect(KalibroClient::Entities::Configurations::KalibroRange.ranges_of(metric_configuration.id)).to eq([])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when exist only one range for the given metric configuration' do
|
112
|
+
before :each do
|
113
|
+
KalibroClient::Entities::Configurations::KalibroRange.
|
114
|
+
expects(:request).
|
115
|
+
with('', {}, :get, "metric_configurations/#{metric_configuration.id}").
|
116
|
+
returns({'kalibro_ranges' => subject.to_hash})
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should return a list with the range' do
|
120
|
+
expect(KalibroClient::Entities::Configurations::KalibroRange.ranges_of(metric_configuration.id).
|
121
|
+
first.beginning).to eq(subject.beginning)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'when exists many ranges for the given metric configuration' do
|
126
|
+
let(:another_range) { FactoryGirl.build(:another_range) }
|
127
|
+
|
128
|
+
before :each do
|
129
|
+
KalibroClient::Entities::Configurations::KalibroRange.
|
130
|
+
expects(:request).
|
131
|
+
with('', {}, :get, "metric_configurations/#{metric_configuration.id}").
|
132
|
+
returns({'kalibro_ranges' => [subject.to_hash, another_range.to_hash]})
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should return a list with the ranges' do
|
136
|
+
ranges = KalibroClient::Entities::Configurations::KalibroRange.ranges_of(metric_configuration.id)
|
137
|
+
expect(ranges.first.comments).to eq(subject.comments)
|
138
|
+
expect(ranges.last.comments).to eq(another_range.comments)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# The only purpose of this test is to cover the overrided save_params method
|
144
|
+
describe 'save' do
|
145
|
+
subject {FactoryGirl.build(:range)}
|
146
|
+
|
147
|
+
before :each do
|
148
|
+
KalibroClient::Entities::Configurations::KalibroRange.
|
149
|
+
expects(:request).
|
150
|
+
with('', {:kalibro_range => subject.to_hash, :metric_configuration_id => subject.metric_configuration_id}, :post, "metric_configurations/#{subject.metric_configuration_id}").
|
151
|
+
returns("kalibro_range" => { 'id' => 2, 'kalibro_errors' => []})
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should make a request to save model with id and return true without errors' do
|
155
|
+
expect(subject.save).to be(true)
|
156
|
+
expect(subject.kalibro_errors).to be_empty
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# The only purpose of this test is to cover the overrided destroy_prefix method
|
161
|
+
describe 'destroy' do
|
162
|
+
subject {FactoryGirl.build(:range_with_id)}
|
163
|
+
|
164
|
+
before :each do
|
165
|
+
KalibroClient::Entities::Configurations::KalibroRange.
|
166
|
+
expects(:request).
|
167
|
+
with(":id", {id: subject.id}, :delete, "metric_configurations/#{subject.metric_configuration_id}").returns({})
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should make a request to destroy' do
|
171
|
+
subject.destroy
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,230 @@
|
|
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::Configurations::MetricConfiguration do
|
20
|
+
describe 'id=' do
|
21
|
+
it 'should set the id as an Integer' do
|
22
|
+
subject.id = "42"
|
23
|
+
expect(subject.id).to eq(42)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'reading_group_id=' do
|
28
|
+
it 'should set the reading group id' do
|
29
|
+
subject.reading_group_id = "1"
|
30
|
+
expect(subject.reading_group_id).to eq(1)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'metric=' do
|
35
|
+
|
36
|
+
context 'with a Hash' do
|
37
|
+
context 'Metric' do
|
38
|
+
let!(:metric) { FactoryGirl.build(:metric) }
|
39
|
+
|
40
|
+
before :each do
|
41
|
+
KalibroClient::Entities::Miscellaneous::Metric.
|
42
|
+
expects(:to_object).at_least_once.
|
43
|
+
with(metric.to_hash).
|
44
|
+
returns(metric)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should convert the argument and set the metric' do
|
48
|
+
subject.metric = metric.to_hash
|
49
|
+
expect(subject.metric).to eq(metric)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'NativeMetric' do
|
54
|
+
let!(:metric) { FactoryGirl.build(:loc) }
|
55
|
+
|
56
|
+
before :each do
|
57
|
+
KalibroClient::Entities::Miscellaneous::NativeMetric.
|
58
|
+
expects(:to_object).at_least_once.
|
59
|
+
with(metric.to_hash).
|
60
|
+
returns(metric)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should convert the argument and set the metric' do
|
64
|
+
subject.metric = metric.to_hash
|
65
|
+
expect(subject.metric).to eq(metric)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'CompoundMetric' do
|
70
|
+
let!(:metric) { FactoryGirl.build(:compound_metric) }
|
71
|
+
|
72
|
+
before :each do
|
73
|
+
KalibroClient::Entities::Miscellaneous::CompoundMetric.
|
74
|
+
expects(:to_object).at_least_once.
|
75
|
+
with(metric.to_hash).
|
76
|
+
returns(metric)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should convert the argument and set the metric' do
|
80
|
+
subject.metric = metric.to_hash
|
81
|
+
expect(subject.metric).to eq(metric)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'with a Metric' do
|
87
|
+
let!(:metric) { FactoryGirl.build(:metric) }
|
88
|
+
|
89
|
+
it 'should convert the argument and set the metric' do
|
90
|
+
subject.metric = metric
|
91
|
+
expect(subject.metric).to eq(metric)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'with something else' do
|
96
|
+
let!(:repository) { FactoryGirl.build(:repository) }
|
97
|
+
|
98
|
+
it 'should convert the argument and set the metric' do
|
99
|
+
expect { subject.metric=(repository) }.to raise_error(TypeError).with_message("Cannot cast #{repository.inspect} into Metric")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'weight=' do
|
105
|
+
it 'should set the weight' do
|
106
|
+
subject.weight = "10"
|
107
|
+
expect(subject.weight).to eq(10)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe 'update_attributes' do
|
112
|
+
let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
|
113
|
+
|
114
|
+
before :each do
|
115
|
+
KalibroClient::Entities::Configurations::MetricConfiguration.any_instance.
|
116
|
+
expects(:save).
|
117
|
+
returns(true)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should set the attributes and save' do
|
121
|
+
subject.update_attributes(metric_configuration.to_hash)
|
122
|
+
expect(subject.weight).to eq(metric_configuration.weight)
|
123
|
+
expect(subject.aggregation_form).to eq(metric_configuration.aggregation_form)
|
124
|
+
expect(subject.reading_group_id).to eq(metric_configuration.reading_group_id)
|
125
|
+
expect(subject.kalibro_configuration_id).to eq(metric_configuration.kalibro_configuration_id)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'to_hash' do
|
130
|
+
subject {FactoryGirl.build(:metric_configuration_with_id)}
|
131
|
+
|
132
|
+
it 'should not include the configuration_id' do
|
133
|
+
expect(subject.to_hash[:configuration_id]).to be_nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe 'metric_configurations_of' do
|
138
|
+
let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
|
139
|
+
let(:configuration) { FactoryGirl.build(:configuration_with_id) }
|
140
|
+
|
141
|
+
before :each do
|
142
|
+
KalibroClient::Entities::Configurations::MetricConfiguration.
|
143
|
+
expects(:request).
|
144
|
+
with('', {}, :get, "kalibro_configurations/#{configuration.id}").
|
145
|
+
returns({'metric_configurations' => [metric_configuration.to_hash]})
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should return a array with a metric configuration' do
|
149
|
+
metric_configurations = KalibroClient::Entities::Configurations::MetricConfiguration.metric_configurations_of(configuration.id)
|
150
|
+
|
151
|
+
expect(metric_configurations).to be_an(Array)
|
152
|
+
expect(metric_configurations.first.id).to eq(metric_configuration.id)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# The only purpose of this test is to cover the overrided save_params method
|
157
|
+
describe 'save' do
|
158
|
+
subject {FactoryGirl.build(:metric_configuration)}
|
159
|
+
|
160
|
+
before :each do
|
161
|
+
KalibroClient::Entities::Configurations::MetricConfiguration.
|
162
|
+
expects(:request).
|
163
|
+
with('', {:metric_configuration => subject.to_hash, :kalibro_configuration_id => subject.kalibro_configuration_id}, :post, '').
|
164
|
+
returns("metric_configuration" => {'id' => 1, 'kalibro_errors' => []})
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should make a request to save model with id and return true without errors' do
|
168
|
+
expect(subject.save).to be_truthy
|
169
|
+
expect(subject.kalibro_errors).to be_empty
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe 'exists?' do
|
174
|
+
subject {FactoryGirl.build(:metric_configuration_with_id)}
|
175
|
+
|
176
|
+
context 'when the metric configuration exists' do
|
177
|
+
before :each do
|
178
|
+
KalibroClient::Entities::Configurations::MetricConfiguration.expects(:find).with(subject.id).returns(subject)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should return true' do
|
182
|
+
expect(KalibroClient::Entities::Configurations::MetricConfiguration.exists?(subject.id)).to be_truthy
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context 'when the metric configuration does not exist' do
|
187
|
+
before :each do
|
188
|
+
KalibroClient::Entities::Configurations::MetricConfiguration.expects(:find).with(subject.id).raises(KalibroClient::Errors::RecordNotFound)
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'should return false' do
|
192
|
+
expect(KalibroClient::Entities::Configurations::MetricConfiguration.exists?(subject.id)).to be_falsey
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe 'find' do
|
198
|
+
let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
|
199
|
+
|
200
|
+
context 'with an existant MetricConfiguration' do
|
201
|
+
before :each do
|
202
|
+
KalibroClient::Entities::Configurations::MetricConfiguration.
|
203
|
+
expects(:request).
|
204
|
+
with(':id', {id: metric_configuration.id}, :get).
|
205
|
+
returns({'metric_configuration' => metric_configuration.to_hash})
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should return the metric_configuration' do
|
209
|
+
expect(KalibroClient::Entities::Configurations::MetricConfiguration.find(metric_configuration.id).
|
210
|
+
id).to eq(metric_configuration.id)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context 'with an inexistant MetricConfiguration' do
|
215
|
+
before :each do
|
216
|
+
any_code = rand(Time.now.to_i)
|
217
|
+
any_error_message = ""
|
218
|
+
KalibroClient::Entities::Configurations::MetricConfiguration.
|
219
|
+
expects(:request).
|
220
|
+
with(':id', {id: metric_configuration.id}, :get).
|
221
|
+
returns({'error' => 'RecordNotFound'})
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'should raise the RecordNotFound error' do
|
225
|
+
expect {KalibroClient::Entities::Configurations::MetricConfiguration.find(metric_configuration.id)}.
|
226
|
+
to raise_error(KalibroClient::Errors::RecordNotFound)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|