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,322 @@
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::Model do
20
+ subject { FactoryGirl.build(:model) }
21
+
22
+ describe 'new' do
23
+ it 'should create a model from an empty hash' do
24
+ subject = KalibroGatekeeperClient::Entities::Model.new {}
25
+ subject.kalibro_errors.should eq([])
26
+ end
27
+ end
28
+
29
+ describe 'class_name' do
30
+ it 'should be a String' do
31
+ subject.class.class_name.should be_a(String)
32
+ end
33
+
34
+ it 'should return Model' do
35
+ subject.class.class_name.should eq('Model')
36
+ end
37
+ end
38
+
39
+ describe 'endpoint' do
40
+ it 'should return the class_name' do
41
+ endpoint = 'tests'
42
+ KalibroGatekeeperClient::Entities::Model.expects(:class_name).returns(endpoint)
43
+ KalibroGatekeeperClient::Entities::Model.endpoint.should eq(endpoint)
44
+ end
45
+ end
46
+
47
+ describe 'client' do
48
+ it 'returns a Faraday::Connection' do
49
+ KalibroGatekeeperClient::Entities::Model.client.should be_a(Faraday::Connection)
50
+ end
51
+ end
52
+
53
+ describe 'request' do
54
+ let(:fixture) { File.read("spec/savon/fixtures/project/does_not_exists.xml") }
55
+ let(:client) { mock('client') }
56
+ let(:response) { mock('response') }
57
+
58
+ context 'for the KalibroGatekeeperClient::Entitie class' do
59
+ it 'should successfully get the Kalibro version' do
60
+ response.expects(:body).returns({exists: false})
61
+ client.expects(:post).
62
+ with('/models/exists', {id: 1}).
63
+ returns(response)
64
+ KalibroGatekeeperClient::Entities::Model.
65
+ expects(:client).
66
+ with(any_parameters).
67
+ returns(client)
68
+ KalibroGatekeeperClient::Entities::Model.
69
+ request('exists', {id: 1})[:exists].should eq(false)
70
+ end
71
+ end
72
+
73
+ context 'with a children class from outside' do
74
+ class Child < KalibroGatekeeperClient::Entities::Model; end
75
+
76
+ it 'should successfully get the Kalibro version' do
77
+ response.expects(:body).returns({exists: false})
78
+ client.expects(:post).
79
+ with('/models/exists', {id: 1}).
80
+ returns(response)
81
+ Child.
82
+ expects(:client).
83
+ with(any_parameters).
84
+ returns(client)
85
+ Child.
86
+ request('exists', {id: 1})[:exists].should eq(false)
87
+ end
88
+ end
89
+ end
90
+
91
+ describe 'to_hash' do
92
+ it 'should return an empty hash' do
93
+ subject.to_hash.should be_empty
94
+ end
95
+ end
96
+
97
+ describe 'to_object' do
98
+ it 'should return an Object with an empty hash' do
99
+ KalibroGatekeeperClient::Entities::Model.to_object({}).should eq(FactoryGirl.build(:model))
100
+ end
101
+
102
+ it "should remain an object if it isn't a Hash" do
103
+ KalibroGatekeeperClient::Entities::Model.to_object(Object.new).should be_an(Object)
104
+ end
105
+ end
106
+
107
+ describe 'to_objects_array' do
108
+ it 'should convert [{}] to [Model]' do
109
+ KalibroGatekeeperClient::Entities::Model.to_objects_array({}).should eq([FactoryGirl.build(:model)])
110
+ end
111
+
112
+ it 'should remain an array if it already is one' do
113
+ object = Object.new
114
+ KalibroGatekeeperClient::Entities::Model.to_objects_array([object]).should eq([object])
115
+ end
116
+ end
117
+
118
+ describe 'save' do
119
+ before :each do
120
+ KalibroGatekeeperClient::Entities::Model.
121
+ expects(:request).
122
+ with('save', {model: {}}).returns({'id' => 42})
123
+ end
124
+
125
+ context "when it doesn't have the method id=" do
126
+ it 'should make a request to save model with id returning false and an error' do
127
+ subject.save.should be(false)
128
+ subject.kalibro_errors[0].should be_a(NoMethodError)
129
+ end
130
+ end
131
+
132
+ context 'when it has the method id=' do
133
+ before :each do
134
+ KalibroGatekeeperClient::Entities::Model.
135
+ any_instance.expects(:id=).
136
+ with(42).
137
+ returns(42)
138
+ end
139
+
140
+ it 'should make a request to save model with id and return true without errors' do
141
+ subject.save.should be(true)
142
+ subject.kalibro_errors.should be_empty
143
+ end
144
+ end
145
+ end
146
+
147
+ describe 'save!' do
148
+ subject { FactoryGirl.build(:project) }
149
+
150
+ it 'should call save' do
151
+ subject.expects(:save)
152
+ subject.save!
153
+ end
154
+ end
155
+
156
+ describe 'create' do
157
+ before :each do
158
+ subject.expects(:save)
159
+ KalibroGatekeeperClient::Entities::Model.
160
+ expects(:new).
161
+ with({}).
162
+ returns(subject)
163
+ end
164
+
165
+ it 'should instantiate and save the model' do
166
+ (KalibroGatekeeperClient::Entities::Model.create {}).should eq(subject)
167
+ end
168
+ end
169
+
170
+ describe '==' do
171
+ context 'comparing objects from different classes' do
172
+ it 'should return false' do
173
+ subject.should_not eq(Object.new)
174
+ end
175
+ end
176
+
177
+ context 'with two models with different attribute values' do
178
+ let(:another_model) { FactoryGirl.build(:model) }
179
+ before :each do
180
+ subject.expects(:variable_names).returns(["answer"])
181
+ subject.expects(:send).with("answer").returns(42)
182
+ another_model.expects(:send).with("answer").returns(41)
183
+ end
184
+
185
+ it 'should return false' do
186
+ subject.should_not eq(another_model)
187
+ end
188
+ end
189
+
190
+ context 'with two empty models' do
191
+ it 'should return true' do
192
+ subject.should eq(FactoryGirl.build(:model))
193
+ end
194
+ end
195
+ end
196
+
197
+ describe 'exists?' do
198
+ context 'with an inexistent id' do
199
+ before :each do
200
+ KalibroGatekeeperClient::Entities::Model.
201
+ expects(:request).
202
+ with('exists', {id: 0}).
203
+ returns({'exists' => false})
204
+ end
205
+
206
+ it 'should return false' do
207
+ KalibroGatekeeperClient::Entities::Model.exists?(0).should eq(false)
208
+ end
209
+ end
210
+
211
+ context 'with an existent id' do
212
+ before :each do
213
+ KalibroGatekeeperClient::Entities::Model.
214
+ expects(:request).
215
+ with('exists', {id: 42}).
216
+ returns({'exists' => true})
217
+ end
218
+
219
+ it 'should return false' do
220
+ KalibroGatekeeperClient::Entities::Model.exists?(42).should eq(true)
221
+ end
222
+ end
223
+ end
224
+
225
+ describe 'find' do
226
+ context 'with an inexistent id' do
227
+ before :each do
228
+ KalibroGatekeeperClient::Entities::Model.expects(:exists?).with(0).returns(false)
229
+ end
230
+
231
+ it 'should raise a RecordNotFound error' do
232
+ expect { KalibroGatekeeperClient::Entities::Model.find(0)}.to raise_error(KalibroGatekeeperClient::Errors::RecordNotFound)
233
+ end
234
+ end
235
+
236
+ context 'with an existent id' do
237
+ before :each do
238
+ KalibroGatekeeperClient::Entities::Model.
239
+ expects(:exists?).with(42).
240
+ returns(true)
241
+ KalibroGatekeeperClient::Entities::Model.
242
+ expects(:request).
243
+ with('get',{id: 42}).returns({})
244
+ end
245
+
246
+ it 'should return an empty model' do
247
+ KalibroGatekeeperClient::Entities::Model.find(42).should eq(subject)
248
+ end
249
+ end
250
+ end
251
+
252
+ describe 'destroy' do
253
+ context 'when it gets successfully destroyed' do
254
+ before :each do
255
+ subject.expects(:id).at_least_once.returns(42)
256
+ KalibroGatekeeperClient::Entities::Model.
257
+ expects(:request).
258
+ with('destroy',{id: subject.id})
259
+ end
260
+
261
+ it 'should remain with the errors array empty' do
262
+ subject.destroy
263
+ subject.kalibro_errors.should be_empty
264
+ end
265
+ end
266
+
267
+ context 'when the destruction fails' do
268
+ before :each do
269
+ subject.expects(:id).at_least_once.returns(42)
270
+ KalibroGatekeeperClient::Entities::Model.
271
+ expects(:request).
272
+ with('destroy',{id: subject.id}).raises(Exception.new)
273
+ end
274
+
275
+ it "should have an exception inside it's errors" do
276
+ subject.destroy
277
+
278
+ subject.kalibro_errors[0].should be_an(Exception)
279
+ end
280
+ end
281
+ end
282
+
283
+ describe 'create_objects_array_from_hash' do
284
+ context 'with nil' do
285
+ it 'should return an empty array' do
286
+ KalibroGatekeeperClient::Entities::Model.create_objects_array_from_hash(nil).should eq([])
287
+ end
288
+ end
289
+
290
+ context 'with a Hash' do
291
+ it 'should return the correspondent object to the given hash inside of an Array' do
292
+ KalibroGatekeeperClient::Entities::Model.create_objects_array_from_hash({}).should eq([subject])
293
+ end
294
+ end
295
+ end
296
+
297
+ describe 'is_valid?' do
298
+ context 'with a global var' do
299
+ it 'should return false' do
300
+ KalibroGatekeeperClient::Entities::Model.is_valid?('@test').should be_false
301
+ end
302
+ end
303
+
304
+ context 'with the attributes var' do
305
+ it 'should return false' do
306
+ KalibroGatekeeperClient::Entities::Model.is_valid?(:attributes!).should be_false
307
+ end
308
+ end
309
+
310
+ context 'with a xsi var' do
311
+ it 'should return false' do
312
+ KalibroGatekeeperClient::Entities::Model.is_valid?('test_xsi').should be_false
313
+ end
314
+ end
315
+
316
+ context 'with a valid var' do
317
+ it 'should return true' do
318
+ KalibroGatekeeperClient::Entities::Model.is_valid?('test').should be_true
319
+ end
320
+ end
321
+ end
322
+ end
@@ -0,0 +1,163 @@
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::ModuleResult do
20
+ subject { FactoryGirl.build(:module_result, id: rand(Time.now.to_i)) }
21
+
22
+ describe 'find' do
23
+ context 'when there is a module result for the given id' do
24
+ before :each do
25
+ KalibroGatekeeperClient::Entities::ModuleResult.
26
+ expects(:request).
27
+ with('get', { id: subject.id }).
28
+ returns(subject.to_hash)
29
+ end
30
+
31
+ it 'should return a hash with module result' do
32
+ KalibroGatekeeperClient::Entities::ModuleResult.
33
+ find(subject.id).id.should eq(subject.id)
34
+ end
35
+ end
36
+
37
+ context "when there isn't a module result for the given id" do
38
+ before :each do
39
+ any_code = rand(Time.now.to_i)
40
+ any_error_message = ""
41
+
42
+ KalibroGatekeeperClient::Entities::ModuleResult.
43
+ expects(:request).
44
+ with('get', { id: subject.id }).
45
+ returns({ 'error' => 'Error'})
46
+ end
47
+
48
+ it 'should raise an error' do
49
+ expect {KalibroGatekeeperClient::Entities::ModuleResult.find(subject.id)}.
50
+ to raise_error KalibroGatekeeperClient::Errors::RecordNotFound
51
+ end
52
+ end
53
+ end
54
+
55
+ describe 'children' do
56
+ before :each do
57
+ KalibroGatekeeperClient::Entities::ModuleResult.
58
+ expects(:request).
59
+ with('children_of', {id: subject.id}).
60
+ returns({'module_results' => subject.to_hash})
61
+ end
62
+
63
+ it 'should return a list of a objects' do
64
+ subject.children.should eq [subject]
65
+ end
66
+ end
67
+
68
+ describe 'parents' do
69
+ let(:root_module_result) { FactoryGirl.build(:root_module_result) }
70
+
71
+ context 'when module result has a parent' do
72
+ before :each do
73
+ KalibroGatekeeperClient::Entities::ModuleResult.
74
+ expects(:request).at_least_once.
75
+ with('get', { id: subject.parent_id }).
76
+ returns(root_module_result.to_hash)
77
+ end
78
+
79
+ it 'should return its parent' do
80
+ subject.parents.should eq [root_module_result]
81
+ end
82
+ end
83
+
84
+ context 'when module result does not have a parent' do
85
+ it 'should return an empty list' do
86
+ root_module_result.parents.should eq []
87
+ end
88
+ end
89
+ end
90
+
91
+ describe 'id=' do
92
+ it 'should set the id attribute as integer' do
93
+ subject.id = "23"
94
+ subject.id.should eq 23
95
+ end
96
+ end
97
+
98
+ describe 'module=' do
99
+ let(:another_module) { FactoryGirl.build(:module, name: 'ANOTHER') }
100
+
101
+ it 'should set the module attribute as a Module object' do
102
+ subject.module = another_module.to_hash
103
+ subject.module.should eq another_module
104
+ end
105
+ end
106
+
107
+ describe 'grade=' do
108
+ it 'should set the grade attribute as float' do
109
+ subject.grade = "12.5"
110
+ subject.grade.should eq 12.5
111
+ end
112
+ end
113
+
114
+ describe 'parent_id=' do
115
+ it 'should set the parent_id attribute as integer' do
116
+ subject.parent_id = "73"
117
+ subject.parent_id.should eq 73
118
+ end
119
+ end
120
+
121
+ describe 'history_of' do
122
+ let(:date_module_result) { FactoryGirl.build(:date_module_result) }
123
+ before :each do
124
+ KalibroGatekeeperClient::Entities::ModuleResult.
125
+ expects(:request).
126
+ with('history_of', {id: subject.id}).
127
+ returns({'date_module_results' => date_module_result.to_hash})
128
+ end
129
+
130
+ it 'should return a list of date_module_results' do
131
+ date_module_results = KalibroGatekeeperClient::Entities::ModuleResult.history_of subject.id
132
+ date_module_results.first.result.should eq date_module_result.result
133
+ end
134
+ end
135
+
136
+ describe 'folder? & file?' do
137
+ context 'when the module result has childrens' do
138
+ subject { FactoryGirl.build(:root_module_result) }
139
+
140
+ before :each do
141
+ subject.expects(:children).twice.returns([FactoryGirl.build(:module_result)])
142
+ end
143
+
144
+ it 'should return true for folder? and false for file?' do
145
+ subject.folder?.should be_true
146
+ subject.file?.should be_false
147
+ end
148
+ end
149
+
150
+ context 'when the module result has no childrens' do
151
+ subject { FactoryGirl.build(:module_result) }
152
+
153
+ before :each do
154
+ subject.expects(:children).twice.returns([])
155
+ end
156
+
157
+ it 'should return true for folder? and false for file?' do
158
+ subject.folder?.should be_false
159
+ subject.file?.should be_true
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,33 @@
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::ProcessTime do
20
+ describe 'time=' do
21
+ subject {FactoryGirl.build(:process_time)}
22
+
23
+ it 'should set the time attribute to 6' do
24
+ subject.time = 6
25
+ subject.time.should eq 6
26
+ end
27
+
28
+ it 'should convert to integer' do
29
+ subject.time = "5"
30
+ subject.time.should eq 5
31
+ end
32
+ end
33
+ end