kalibro_gatekeeper_client 0.0.1.rc1

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 (165) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +29 -0
  6. data/AUTHORS +4 -0
  7. data/COPYING +674 -0
  8. data/COPYING.LESSER +165 -0
  9. data/Gemfile +4 -0
  10. data/README.md +77 -0
  11. data/Rakefile +6 -0
  12. data/cucumber.yml +1 -0
  13. data/features/base_tool/all_names.feature +8 -0
  14. data/features/base_tool/find_by_name.feature +12 -0
  15. data/features/configuration/all.feature +10 -0
  16. data/features/metric_configuration/find.feature +18 -0
  17. data/features/metric_configuration/metric_configurations_of.feature +18 -0
  18. data/features/metric_result/descendant_results.feature +19 -0
  19. data/features/metric_result/history_of.feature +20 -0
  20. data/features/metric_result/metric_results_of.feature +19 -0
  21. data/features/module_result/children.feature +18 -0
  22. data/features/module_result/find.feature +15 -0
  23. data/features/module_result/history_of.feature +11 -0
  24. data/features/processing/first_processing_after.feature +18 -0
  25. data/features/processing/first_processing_of.feature +18 -0
  26. data/features/processing/has_processing.feature +18 -0
  27. data/features/processing/has_processing_after.feature +18 -0
  28. data/features/processing/has_processing_before.feature +18 -0
  29. data/features/processing/has_ready_processing.feature +18 -0
  30. data/features/processing/last_processing_before.feature +18 -0
  31. data/features/processing/last_processing_of.feature +18 -0
  32. data/features/processing/last_processing_state_of.feature +18 -0
  33. data/features/processing/last_ready_processing_of.feature +18 -0
  34. data/features/processing/processing_of.feature +32 -0
  35. data/features/processing/processing_with_date_of.feature +32 -0
  36. data/features/project/all.feature +10 -0
  37. data/features/project/creation.feature +9 -0
  38. data/features/project/destroy.feature +10 -0
  39. data/features/project/exists.feature +9 -0
  40. data/features/project/find.feature +10 -0
  41. data/features/range/all.feature +14 -0
  42. data/features/range/exists.feature +13 -0
  43. data/features/range/find.feature +14 -0
  44. data/features/range/ranges_of.feature +22 -0
  45. data/features/range/save.feature +14 -0
  46. data/features/reading/all.feature +13 -0
  47. data/features/reading/exists.feature +13 -0
  48. data/features/reading/find.feature +11 -0
  49. data/features/reading/readings_of.feature +11 -0
  50. data/features/reading_group/all.feature +10 -0
  51. data/features/repository/all.feature +14 -0
  52. data/features/repository/cancel_processing.feature +14 -0
  53. data/features/repository/exists.feature +14 -0
  54. data/features/repository/find.feature +14 -0
  55. data/features/repository/of.feature +15 -0
  56. data/features/repository/process.feature +16 -0
  57. data/features/repository/types.feature +9 -0
  58. data/features/step_definitions/base_tool_steps.rb +28 -0
  59. data/features/step_definitions/configuration_steps.rb +11 -0
  60. data/features/step_definitions/metric_configuration_steps.rb +52 -0
  61. data/features/step_definitions/metric_result_steps.rb +29 -0
  62. data/features/step_definitions/metric_steps.rb +3 -0
  63. data/features/step_definitions/module_result_steps.rb +30 -0
  64. data/features/step_definitions/processing_steps.rb +91 -0
  65. data/features/step_definitions/project_steps.rb +48 -0
  66. data/features/step_definitions/range_steps.rb +68 -0
  67. data/features/step_definitions/reading_group_steps.rb +19 -0
  68. data/features/step_definitions/reading_steps.rb +39 -0
  69. data/features/step_definitions/repository_steps.rb +61 -0
  70. data/features/support/env.rb +25 -0
  71. data/features/support/kalibro_cucumber_helpers.yml.sample +10 -0
  72. data/kalibro_gatekeeper_client.gemspec +49 -0
  73. data/lib/kalibro_gatekeeper_client/entities/base_tool.rb +55 -0
  74. data/lib/kalibro_gatekeeper_client/entities/configuration.rb +34 -0
  75. data/lib/kalibro_gatekeeper_client/entities/date_metric_result.rb +39 -0
  76. data/lib/kalibro_gatekeeper_client/entities/date_module_result.rb +39 -0
  77. data/lib/kalibro_gatekeeper_client/entities/metric.rb +21 -0
  78. data/lib/kalibro_gatekeeper_client/entities/metric_configuration.rb +76 -0
  79. data/lib/kalibro_gatekeeper_client/entities/metric_configuration_snapshot.rb +57 -0
  80. data/lib/kalibro_gatekeeper_client/entities/metric_result.rb +72 -0
  81. data/lib/kalibro_gatekeeper_client/entities/model.rb +174 -0
  82. data/lib/kalibro_gatekeeper_client/entities/module.rb +27 -0
  83. data/lib/kalibro_gatekeeper_client/entities/module_result.rb +75 -0
  84. data/lib/kalibro_gatekeeper_client/entities/process_time.rb +31 -0
  85. data/lib/kalibro_gatekeeper_client/entities/processing.rb +113 -0
  86. data/lib/kalibro_gatekeeper_client/entities/project.rb +35 -0
  87. data/lib/kalibro_gatekeeper_client/entities/range.rb +100 -0
  88. data/lib/kalibro_gatekeeper_client/entities/range_snapshot.rb +37 -0
  89. data/lib/kalibro_gatekeeper_client/entities/reading.rb +67 -0
  90. data/lib/kalibro_gatekeeper_client/entities/reading_group.rb +44 -0
  91. data/lib/kalibro_gatekeeper_client/entities/repository.rb +89 -0
  92. data/lib/kalibro_gatekeeper_client/entities/repository_observer.rb +50 -0
  93. data/lib/kalibro_gatekeeper_client/entities/stack_trace_element.rb +31 -0
  94. data/lib/kalibro_gatekeeper_client/entities/throwable.rb +42 -0
  95. data/lib/kalibro_gatekeeper_client/entities.rb +37 -0
  96. data/lib/kalibro_gatekeeper_client/errors/record_not_found.rb +22 -0
  97. data/lib/kalibro_gatekeeper_client/errors/standard.rb +24 -0
  98. data/lib/kalibro_gatekeeper_client/errors.rb +18 -0
  99. data/lib/kalibro_gatekeeper_client/helpers/aggregation_options.rb +25 -0
  100. data/lib/kalibro_gatekeeper_client/helpers/hash_converters.rb +48 -0
  101. data/lib/kalibro_gatekeeper_client/helpers/request_methods.rb +47 -0
  102. data/lib/kalibro_gatekeeper_client/helpers/xml_converters.rb +20 -0
  103. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/configuration.rb +39 -0
  104. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/hooks.rb +56 -0
  105. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/delete_all_kalibro_entries.sh +23 -0
  106. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/prepare_kalibro_query_file.sh +38 -0
  107. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/put_kalibro_on_test_mode.sh +39 -0
  108. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/return_kalibro_from_test_mode.sh +26 -0
  109. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers.rb +40 -0
  110. data/lib/kalibro_gatekeeper_client/version.rb +19 -0
  111. data/lib/kalibro_gatekeeper_client.rb +61 -0
  112. data/lib/rake/test_task.rb +57 -0
  113. data/spec/entities/base_tool_spec.rb +168 -0
  114. data/spec/entities/configuration_spec.rb +61 -0
  115. data/spec/entities/date_metric_result_spec.rb +62 -0
  116. data/spec/entities/date_module_result_spec.rb +61 -0
  117. data/spec/entities/metric_configuration_snapshot_spec.rb +107 -0
  118. data/spec/entities/metric_configuration_spec.rb +173 -0
  119. data/spec/entities/metric_result_spec.rb +188 -0
  120. data/spec/entities/metric_spec.rb +47 -0
  121. data/spec/entities/model_spec.rb +322 -0
  122. data/spec/entities/module_result_spec.rb +163 -0
  123. data/spec/entities/process_time_spec.rb +33 -0
  124. data/spec/entities/processing_spec.rb +334 -0
  125. data/spec/entities/project_spec.rb +68 -0
  126. data/spec/entities/range_snapshot_spec.rb +50 -0
  127. data/spec/entities/range_spec.rb +225 -0
  128. data/spec/entities/reading_group_spec.rb +90 -0
  129. data/spec/entities/reading_spec.rb +148 -0
  130. data/spec/entities/repository_observer_spec.rb +123 -0
  131. data/spec/entities/repository_spec.rb +191 -0
  132. data/spec/entities/stack_trace_element_spec.rb +26 -0
  133. data/spec/entities/throwable_spec.rb +51 -0
  134. data/spec/factories/base_tools.rb +31 -0
  135. data/spec/factories/configurations.rb +29 -0
  136. data/spec/factories/date_metric_results.rb +28 -0
  137. data/spec/factories/date_module_results.rb +22 -0
  138. data/spec/factories/metric_configurations.rb +28 -0
  139. data/spec/factories/metric_configurations_snapshot.rb +26 -0
  140. data/spec/factories/metric_results.rb +24 -0
  141. data/spec/factories/metrics.rb +35 -0
  142. data/spec/factories/models.rb +20 -0
  143. data/spec/factories/module_results.rb +33 -0
  144. data/spec/factories/modules.rb +22 -0
  145. data/spec/factories/process_times.rb +27 -0
  146. data/spec/factories/processings.rb +25 -0
  147. data/spec/factories/projects.rb +29 -0
  148. data/spec/factories/ranges.rb +35 -0
  149. data/spec/factories/ranges_snapshot.rb +26 -0
  150. data/spec/factories/reading_groups.rb +23 -0
  151. data/spec/factories/readings.rb +25 -0
  152. data/spec/factories/repositories.rb +34 -0
  153. data/spec/factories/repository_observers.rb +24 -0
  154. data/spec/factories/stack_trace_elements.rb +24 -0
  155. data/spec/factories/throwables.rb +23 -0
  156. data/spec/helpers/aggregation_options_spec.rb +31 -0
  157. data/spec/helpers/hash_converters_spec.rb +111 -0
  158. data/spec/helpers/xml_converters_spec.rb +64 -0
  159. data/spec/kalibro_entities_spec.rb +108 -0
  160. data/spec/savon/fixtures/config.yml +1 -0
  161. data/spec/savon/fixtures/invalid_config.yml +2 -0
  162. data/spec/savon/fixtures/project/does_not_exists.xml +1 -0
  163. data/spec/savon/savon_test_helper.rb +14 -0
  164. data/spec/spec_helper.rb +56 -0
  165. metadata +466 -0
@@ -0,0 +1,107 @@
1
+ # This file is part of KalibroGatekeeperClient
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 KalibroGatekeeperClient::Entities::MetricConfigurationSnapshot do
20
+ describe 'weight=' do
21
+ it 'should set the value of the attribute weight' do
22
+ subject.weight = "0.6"
23
+ subject.weight.should eq(0.6)
24
+ end
25
+ end
26
+
27
+ describe 'metric=' do
28
+ let(:metric) { FactoryGirl.build(:metric) }
29
+
30
+ context 'when it is not a hash' do
31
+ it 'should set the value of the attribute metric' do
32
+ subject.metric = metric
33
+ subject.metric.should eq(metric)
34
+ end
35
+ end
36
+
37
+ context 'When it is a hash' do
38
+ before :each do
39
+ KalibroGatekeeperClient::Entities::Metric.
40
+ expects(:to_object).
41
+ at_least_once.
42
+ with(metric.to_hash).
43
+ returns(metric)
44
+ end
45
+
46
+ it 'should set the value of the attribute metric as an object' do
47
+ subject.metric = metric.to_hash
48
+ subject.metric.should eq(metric)
49
+ end
50
+ end
51
+ end
52
+
53
+ describe 'range=' do
54
+ let(:range_snapshot) { FactoryGirl.build(:range_snapshot) }
55
+ let(:range_snapshot_hash) { range_snapshot.to_hash }
56
+
57
+ context 'with a single range' do
58
+ before :each do
59
+ KalibroGatekeeperClient::Entities::RangeSnapshot.
60
+ expects(:to_object).
61
+ with(range_snapshot_hash).
62
+ returns(range_snapshot)
63
+ end
64
+
65
+ it 'should set the value of the attribute range' do
66
+ subject.range = range_snapshot_hash
67
+ subject.range.should eq([range_snapshot])
68
+ end
69
+ end
70
+
71
+ context 'with a list of many ranges' do
72
+ before :each do
73
+ KalibroGatekeeperClient::Entities::RangeSnapshot.
74
+ expects(:to_object).
75
+ twice.with(range_snapshot_hash).
76
+ returns(range_snapshot)
77
+ end
78
+
79
+ it 'should set the value of the attribute range' do
80
+ subject.range = [range_snapshot_hash, range_snapshot_hash]
81
+ ranges = subject.range
82
+ ranges.size.should eq(2)
83
+ ranges.first.should eq (range_snapshot)
84
+ ranges.last.should eq (range_snapshot)
85
+ end
86
+ end
87
+ end
88
+
89
+ describe 'range_snapshot' do
90
+ subject { FactoryGirl.build(:metric_configuration_snapshot) }
91
+
92
+ it 'should return the value of the range attribute' do
93
+ subject.range_snapshot.should eq(subject.range)
94
+ end
95
+ end
96
+
97
+ describe 'to_hash' do
98
+ subject {FactoryGirl.build(:metric_configuration_snapshot)}
99
+
100
+ it 'should override the default to_hash method' do
101
+ hash = subject.to_hash
102
+ hash[:attributes!][:range].
103
+ should eq({'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
104
+ 'xsi:type' => 'kalibro:rangeSnapshotXml' })
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,173 @@
1
+ # This file is part of KalibroGatekeeperClient
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 KalibroGatekeeperClient::Entities::MetricConfiguration do
20
+ describe 'id=' do
21
+ it 'should set the id as an Integer' do
22
+ subject.id = "42"
23
+ subject.id.should 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
+ subject.reading_group_id.should eq(1)
31
+ end
32
+ end
33
+
34
+ describe 'metric=' do
35
+ let(:metric) { FactoryGirl.build(:metric) }
36
+
37
+ before :each do
38
+ KalibroGatekeeperClient::Entities::Metric.
39
+ expects(:to_object).at_least_once.
40
+ with(metric.to_hash).
41
+ returns(metric)
42
+ end
43
+
44
+ it 'should convert the argument and set the metric' do
45
+ subject.metric = metric.to_hash
46
+ subject.metric.should eq(metric)
47
+ end
48
+ end
49
+
50
+ describe 'weight=' do
51
+ it 'should set the weight' do
52
+ subject.weight = "10"
53
+ subject.weight.should eq(10)
54
+ end
55
+ end
56
+
57
+ describe 'update_attributes' do
58
+ let(:metric_configuration) { FactoryGirl.build(:metric_configuration) }
59
+
60
+ before :each do
61
+ KalibroGatekeeperClient::Entities::MetricConfiguration.any_instance.
62
+ expects(:save).
63
+ returns(true)
64
+ end
65
+
66
+ it 'should set the attributes and save' do
67
+ subject.update_attributes(metric_configuration.to_hash)
68
+ subject.code.should eq(metric_configuration.code)
69
+ end
70
+ end
71
+
72
+ describe 'to_hash' do
73
+ subject {FactoryGirl.build(:metric_configuration)}
74
+
75
+ it 'should not include the configuration_id' do
76
+ subject.to_hash[:configuration_id].should be_nil
77
+ end
78
+ end
79
+
80
+ describe 'metric_configurations_of' do
81
+ let(:metric_configuration) { FactoryGirl.build(:metric_configuration) }
82
+ let(:configuration) { FactoryGirl.build(:configuration) }
83
+
84
+ before :each do
85
+ KalibroGatekeeperClient::Entities::MetricConfiguration.
86
+ expects(:request).
87
+ with(:of, {:configuration_id => configuration.id}).
88
+ returns({'metric_configurations' => [metric_configuration.to_hash]})
89
+ end
90
+
91
+ it 'should return a array with a metric configuration' do
92
+ metric_configurations = KalibroGatekeeperClient::Entities::MetricConfiguration.metric_configurations_of(configuration.id)
93
+
94
+ metric_configurations.should be_an(Array)
95
+ metric_configurations.first.id.should eq(metric_configuration.id)
96
+ end
97
+ end
98
+
99
+ # The only purpose of this test is to cover the overrided save_params method
100
+ describe 'save' do
101
+ subject {FactoryGirl.build(:metric_configuration, {id: nil})}
102
+
103
+ before :each do
104
+ KalibroGatekeeperClient::Entities::MetricConfiguration.
105
+ expects(:request).
106
+ with('save', {:metric_configuration => subject.to_hash, :configuration_id => subject.configuration_id}).
107
+ returns({'id' => 1})
108
+ end
109
+
110
+ it 'should make a request to save model with id and return true without errors' do
111
+ subject.save.should be_true
112
+ subject.kalibro_errors.should be_empty
113
+ end
114
+ end
115
+
116
+ describe 'exists?' do
117
+ subject {FactoryGirl.build(:metric_configuration)}
118
+
119
+ context 'when the metric configuration exists' do
120
+ before :each do
121
+ KalibroGatekeeperClient::Entities::MetricConfiguration.expects(:find).with(subject.id).returns(subject)
122
+ end
123
+
124
+ it 'should return true' do
125
+ KalibroGatekeeperClient::Entities::MetricConfiguration.exists?(subject.id).should be_true
126
+ end
127
+ end
128
+
129
+ context 'when the metric configuration does not exist' do
130
+ before :each do
131
+ KalibroGatekeeperClient::Entities::MetricConfiguration.expects(:find).with(subject.id).raises(KalibroGatekeeperClient::Errors::RecordNotFound)
132
+ end
133
+
134
+ it 'should return false' do
135
+ KalibroGatekeeperClient::Entities::MetricConfiguration.exists?(subject.id).should be_false
136
+ end
137
+ end
138
+ end
139
+
140
+ describe 'find' do
141
+ let(:metric_configuration) { FactoryGirl.build(:metric_configuration) }
142
+
143
+ context 'with an existant MetricConfiguration' do
144
+ before :each do
145
+ KalibroGatekeeperClient::Entities::MetricConfiguration.
146
+ expects(:request).
147
+ with(:get, {id: metric_configuration.id}).
148
+ returns(metric_configuration.to_hash)
149
+ end
150
+
151
+ it 'should return the metric_configuration' do
152
+ KalibroGatekeeperClient::Entities::MetricConfiguration.find(metric_configuration.id).
153
+ id.should eq(metric_configuration.id)
154
+ end
155
+ end
156
+
157
+ context 'with an inexistant MetricConfiguration' do
158
+ before :each do
159
+ any_code = rand(Time.now.to_i)
160
+ any_error_message = ""
161
+ KalibroGatekeeperClient::Entities::MetricConfiguration.
162
+ expects(:request).
163
+ with(:get, {id: metric_configuration.id}).
164
+ returns({'error' => 'RecordNotFound'})
165
+ end
166
+
167
+ it 'should raise the RecordNotFound error' do
168
+ expect {KalibroGatekeeperClient::Entities::MetricConfiguration.find(metric_configuration.id)}.
169
+ to raise_error(KalibroGatekeeperClient::Errors::RecordNotFound)
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,188 @@
1
+ # This file is part of KalibroGatekeeperClient
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 KalibroGatekeeperClient::Entities::MetricResult do
20
+ subject { FactoryGirl.build(:metric_result) }
21
+ let(:metric_configuration_snapshot) { FactoryGirl.build(:metric_configuration_snapshot) }
22
+
23
+ describe 'new' do
24
+ context 'with value NaN' do
25
+ it 'should set the value with aggregated_value' do
26
+ metric_result = KalibroGatekeeperClient::Entities::MetricResult.new( FactoryGirl.attributes_for(:metric_result, {value: "NaN", aggregated_value: 1.6}) )
27
+ metric_result.value.should eq(1.6)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe 'id=' do
33
+ it 'should set the value of the attribute id' do
34
+ subject.id = 42
35
+ subject.id.should eq(42)
36
+ end
37
+ end
38
+
39
+ describe 'configuration=' do
40
+ it 'should set the configuration' do
41
+ subject.configuration = metric_configuration_snapshot.to_hash
42
+ subject.configuration.code.should eq(metric_configuration_snapshot.code)
43
+ end
44
+ end
45
+
46
+ describe 'metric_configuration_snapshot' do
47
+ it 'should be an alias to configuration' do
48
+ subject.configuration = metric_configuration_snapshot.to_hash
49
+ subject.metric_configuration_snapshot.code.should eq(metric_configuration_snapshot.code)
50
+ end
51
+ end
52
+
53
+ describe 'value=' do
54
+ it 'should set the value of the attribute value' do
55
+ subject.value = 42
56
+ subject.value.should eq(42)
57
+ end
58
+ end
59
+
60
+ describe 'aggregated_value=' do
61
+ it 'should set the value of the attribute aggregated_value' do
62
+ subject.aggregated_value = 42
63
+ subject.aggregated_value.should eq(42)
64
+ end
65
+ end
66
+
67
+ describe 'descendant_results_of' do
68
+ context 'when there is one descendant result for the given metric_result' do
69
+ before :each do
70
+ KalibroGatekeeperClient::Entities::MetricResult.
71
+ expects(:request).
72
+ with('descendant_results_of', { id: subject.id }).
73
+ returns({'descendant_results' => [13.3]})
74
+ end
75
+
76
+ it 'should return an unitary list with the descendant result' do
77
+ subject.descendant_results.should eq([13.3])
78
+ end
79
+ end
80
+
81
+ context 'when there is no descendant result for the given metric_result' do
82
+ before :each do
83
+ KalibroGatekeeperClient::Entities::MetricResult.
84
+ expects(:request).
85
+ with('descendant_results_of', { id: subject.id }).
86
+ returns({'descendant_results' => []})
87
+ end
88
+
89
+ it 'should return an empty list' do
90
+ subject.descendant_results.should eq([])
91
+ end
92
+ end
93
+ end
94
+
95
+ describe 'metric_results_of' do
96
+ context 'when there is one metric result for the given module_result' do
97
+ before :each do
98
+ KalibroGatekeeperClient::Entities::MetricResult.
99
+ expects(:request).
100
+ with('of', { module_result_id: 123 }).
101
+ returns({'metric_results' => [subject.to_hash]})
102
+ end
103
+
104
+ it 'should return an unitary list with the metric result' do
105
+ KalibroGatekeeperClient::Entities::MetricResult.metric_results_of(123).first.value.should eq(subject.value)
106
+ end
107
+ end
108
+
109
+ context 'when there is no metric result for the given module_result' do
110
+ before :each do
111
+ KalibroGatekeeperClient::Entities::MetricResult.
112
+ expects(:request).
113
+ with('of', { :module_result_id => 42 }).
114
+ returns({'metric_results' => []})
115
+ end
116
+
117
+ it 'should return an empty list' do
118
+ KalibroGatekeeperClient::Entities::MetricResult.metric_results_of(42).should eq([])
119
+ end
120
+ end
121
+
122
+ context 'when there are many metric results for the given module_result' do
123
+ let(:metric_results) { KalibroGatekeeperClient::Entities::MetricResult.metric_results_of(28) }
124
+ before :each do
125
+ KalibroGatekeeperClient::Entities::MetricResult.
126
+ expects(:request).
127
+ with('of', { :module_result_id => 28 }).
128
+ returns({'metric_results' => [subject.to_hash, subject.to_hash]})
129
+ end
130
+
131
+ it 'should return a list with the descendant results' do
132
+ metric_results.first.value.should eq(subject.value)
133
+ end
134
+ end
135
+ end
136
+
137
+ describe 'history_of' do
138
+ let(:module_result) { FactoryGirl.build(:module_result) }
139
+ let(:metric) { FactoryGirl.build(:metric) }
140
+
141
+ context 'when there is not a date metric result' do
142
+ before :each do
143
+ KalibroGatekeeperClient::Entities::MetricResult.
144
+ expects(:request).
145
+ with('history_of_metric', {:metric_name => metric.name, :module_result_id => module_result.id}).
146
+ returns({date_metric_results: []})
147
+ end
148
+
149
+ it 'should return an empty list' do
150
+ KalibroGatekeeperClient::Entities::MetricResult.history_of(metric.name, module_result.id).should eq([])
151
+ end
152
+ end
153
+
154
+ context 'when there is only one date metric result' do
155
+ let(:date_metric_result) { FactoryGirl.build(:date_metric_result, {metric_result: subject}) }
156
+
157
+ before :each do
158
+ KalibroGatekeeperClient::Entities::MetricResult.
159
+ expects(:request).
160
+ with('history_of_metric', {:metric_name => metric.name, :module_result_id => module_result.id}).
161
+ returns({'date_metric_results' => [date_metric_result.to_hash]})
162
+ end
163
+
164
+ it 'should return the date metric result as an object into a list' do
165
+ KalibroGatekeeperClient::Entities::MetricResult.history_of(metric.name, module_result.id).
166
+ first.metric_result.id.should eq(subject.id)
167
+ end
168
+ end
169
+
170
+ context 'when there is many date metric results' do
171
+ let(:date_metric_result) { FactoryGirl.build(:date_metric_result, {metric_result: subject}) }
172
+ let(:another_date_metric_result) { FactoryGirl.build(:another_date_metric_result, {metric_result: subject}) }
173
+
174
+ before :each do
175
+ KalibroGatekeeperClient::Entities::MetricResult.
176
+ expects(:request).
177
+ with('history_of_metric', {:metric_name => metric.name, :module_result_id => module_result.id}).
178
+ returns({'date_metric_results' => [date_metric_result.to_hash, another_date_metric_result.to_hash]})
179
+ end
180
+
181
+ it 'should return a list of date metric results as objects' do
182
+ response = KalibroGatekeeperClient::Entities::MetricResult.history_of(metric.name, module_result.id)
183
+ response.first.metric_result.id.should eq(date_metric_result.metric_result.id)
184
+ response.last.metric_result.id.should eq(another_date_metric_result.metric_result.id)
185
+ end
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,47 @@
1
+ # This file is part of KalibroGatekeeperClient
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 KalibroGatekeeperClient::Entities::Metric do
20
+ describe 'languages' do
21
+ subject { FactoryGirl.build(:metric) }
22
+
23
+ it 'should return the value of the language attribute' do
24
+ subject.languages.should eq(["C", "CPP", "JAVA"])
25
+ end
26
+ end
27
+
28
+ describe 'languages=' do
29
+ it 'should set the value of the attribute language' do
30
+ subject.languages = ["Java", "C"]
31
+ subject.languages.should eq(["Java", "C"])
32
+ end
33
+ end
34
+
35
+ describe 'language=' do
36
+ before :each do
37
+ KalibroGatekeeperClient::Entities::Metric.
38
+ expects(:to_objects_array).
39
+ returns(["Java"])
40
+ end
41
+
42
+ it 'should convert the value to an array of objects' do
43
+ subject.language = "Java"
44
+ subject.languages.should eq(["Java"])
45
+ end
46
+ end
47
+ end