kalibro_gem 0.0.1.rc7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) 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 +21 -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/ranges_of.feature +22 -0
  42. data/features/range/save.feature +32 -0
  43. data/features/reading/find.feature +11 -0
  44. data/features/reading/readings_of.feature +11 -0
  45. data/features/reading_group/all.feature +10 -0
  46. data/features/repository/all.feature +14 -0
  47. data/features/repository/cancel_processing.feature +14 -0
  48. data/features/repository/exists.feature +14 -0
  49. data/features/repository/find.feature +14 -0
  50. data/features/repository/of.feature +15 -0
  51. data/features/repository/process.feature +16 -0
  52. data/features/repository/types.feature +9 -0
  53. data/features/step_definitions/base_tool_steps.rb +28 -0
  54. data/features/step_definitions/configuration_steps.rb +11 -0
  55. data/features/step_definitions/metric_configuration_steps.rb +52 -0
  56. data/features/step_definitions/metric_result_steps.rb +29 -0
  57. data/features/step_definitions/metric_steps.rb +3 -0
  58. data/features/step_definitions/module_result_steps.rb +30 -0
  59. data/features/step_definitions/processing_steps.rb +91 -0
  60. data/features/step_definitions/project_steps.rb +48 -0
  61. data/features/step_definitions/range_steps.rb +41 -0
  62. data/features/step_definitions/reading_group_steps.rb +19 -0
  63. data/features/step_definitions/reading_steps.rb +20 -0
  64. data/features/step_definitions/repository_steps.rb +61 -0
  65. data/features/support/env.rb +25 -0
  66. data/features/support/kalibro_cucumber_helpers.yml.sample +10 -0
  67. data/kalibro_gem.gemspec +48 -0
  68. data/lib/kalibro_gem.rb +61 -0
  69. data/lib/kalibro_gem/entities.rb +37 -0
  70. data/lib/kalibro_gem/entities/base_tool.rb +54 -0
  71. data/lib/kalibro_gem/entities/configuration.rb +33 -0
  72. data/lib/kalibro_gem/entities/date_metric_result.rb +39 -0
  73. data/lib/kalibro_gem/entities/date_module_result.rb +39 -0
  74. data/lib/kalibro_gem/entities/metric.rb +21 -0
  75. data/lib/kalibro_gem/entities/metric_configuration.rb +70 -0
  76. data/lib/kalibro_gem/entities/metric_configuration_snapshot.rb +57 -0
  77. data/lib/kalibro_gem/entities/metric_result.rb +74 -0
  78. data/lib/kalibro_gem/entities/model.rb +162 -0
  79. data/lib/kalibro_gem/entities/module.rb +27 -0
  80. data/lib/kalibro_gem/entities/module_result.rb +77 -0
  81. data/lib/kalibro_gem/entities/process_time.rb +31 -0
  82. data/lib/kalibro_gem/entities/processing.rb +113 -0
  83. data/lib/kalibro_gem/entities/project.rb +34 -0
  84. data/lib/kalibro_gem/entities/range.rb +75 -0
  85. data/lib/kalibro_gem/entities/range_snapshot.rb +37 -0
  86. data/lib/kalibro_gem/entities/reading.rb +51 -0
  87. data/lib/kalibro_gem/entities/reading_group.rb +43 -0
  88. data/lib/kalibro_gem/entities/repository.rb +86 -0
  89. data/lib/kalibro_gem/entities/repository_observer.rb +50 -0
  90. data/lib/kalibro_gem/entities/stack_trace_element.rb +31 -0
  91. data/lib/kalibro_gem/entities/throwable.rb +42 -0
  92. data/lib/kalibro_gem/errors.rb +18 -0
  93. data/lib/kalibro_gem/errors/record_not_found.rb +22 -0
  94. data/lib/kalibro_gem/errors/standard.rb +24 -0
  95. data/lib/kalibro_gem/helpers/aggregation_options.rb +25 -0
  96. data/lib/kalibro_gem/helpers/hash_converters.rb +48 -0
  97. data/lib/kalibro_gem/helpers/request_methods.rb +47 -0
  98. data/lib/kalibro_gem/helpers/xml_converters.rb +20 -0
  99. data/lib/kalibro_gem/kalibro_cucumber_helpers.rb +40 -0
  100. data/lib/kalibro_gem/kalibro_cucumber_helpers/configuration.rb +39 -0
  101. data/lib/kalibro_gem/kalibro_cucumber_helpers/hooks.rb +50 -0
  102. data/lib/kalibro_gem/kalibro_cucumber_helpers/scripts/delete_all_kalibro_entries.sh +23 -0
  103. data/lib/kalibro_gem/kalibro_cucumber_helpers/scripts/prepare_kalibro_query_file.sh +38 -0
  104. data/lib/kalibro_gem/kalibro_cucumber_helpers/scripts/put_kalibro_on_test_mode.sh +35 -0
  105. data/lib/kalibro_gem/kalibro_cucumber_helpers/scripts/return_kalibro_from_test_mode.sh +26 -0
  106. data/lib/kalibro_gem/version.rb +19 -0
  107. data/lib/rake/test_task.rb +57 -0
  108. data/spec/entities/base_tool_spec.rb +168 -0
  109. data/spec/entities/configuration_spec.rb +61 -0
  110. data/spec/entities/date_metric_result_spec.rb +62 -0
  111. data/spec/entities/date_module_result_spec.rb +61 -0
  112. data/spec/entities/metric_configuration_snapshot_spec.rb +107 -0
  113. data/spec/entities/metric_configuration_spec.rb +149 -0
  114. data/spec/entities/metric_result_spec.rb +201 -0
  115. data/spec/entities/metric_spec.rb +47 -0
  116. data/spec/entities/model_spec.rb +275 -0
  117. data/spec/entities/module_result_spec.rb +163 -0
  118. data/spec/entities/process_time_spec.rb +33 -0
  119. data/spec/entities/processing_spec.rb +334 -0
  120. data/spec/entities/project_spec.rb +68 -0
  121. data/spec/entities/range_snapshot_spec.rb +50 -0
  122. data/spec/entities/range_spec.rb +181 -0
  123. data/spec/entities/reading_group_spec.rb +90 -0
  124. data/spec/entities/reading_spec.rb +106 -0
  125. data/spec/entities/repository_observer_spec.rb +123 -0
  126. data/spec/entities/repository_spec.rb +191 -0
  127. data/spec/entities/stack_trace_element_spec.rb +26 -0
  128. data/spec/entities/throwable_spec.rb +51 -0
  129. data/spec/factories/base_tools.rb +31 -0
  130. data/spec/factories/configurations.rb +29 -0
  131. data/spec/factories/date_metric_results.rb +28 -0
  132. data/spec/factories/date_module_results.rb +22 -0
  133. data/spec/factories/metric_configurations.rb +28 -0
  134. data/spec/factories/metric_configurations_snapshot.rb +26 -0
  135. data/spec/factories/metric_results.rb +24 -0
  136. data/spec/factories/metrics.rb +35 -0
  137. data/spec/factories/models.rb +20 -0
  138. data/spec/factories/module_results.rb +33 -0
  139. data/spec/factories/modules.rb +22 -0
  140. data/spec/factories/process_times.rb +27 -0
  141. data/spec/factories/processings.rb +25 -0
  142. data/spec/factories/projects.rb +29 -0
  143. data/spec/factories/ranges.rb +30 -0
  144. data/spec/factories/ranges_snapshot.rb +26 -0
  145. data/spec/factories/reading_groups.rb +23 -0
  146. data/spec/factories/readings.rb +25 -0
  147. data/spec/factories/repositories.rb +34 -0
  148. data/spec/factories/repository_observers.rb +24 -0
  149. data/spec/factories/stack_trace_elements.rb +24 -0
  150. data/spec/factories/throwables.rb +23 -0
  151. data/spec/helpers/aggregation_options_spec.rb +31 -0
  152. data/spec/helpers/hash_converters_spec.rb +111 -0
  153. data/spec/helpers/xml_converters_spec.rb +64 -0
  154. data/spec/kalibro_entities_spec.rb +108 -0
  155. data/spec/savon/fixtures/config.yml +1 -0
  156. data/spec/savon/fixtures/invalid_config.yml +2 -0
  157. data/spec/savon/fixtures/project/does_not_exists.xml +1 -0
  158. data/spec/savon/savon_test_helper.rb +14 -0
  159. data/spec/spec_helper.rb +60 -0
  160. metadata +463 -0
@@ -0,0 +1,47 @@
1
+ # This file is part of KalibroGem
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 KalibroGem::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
+ KalibroGem::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
@@ -0,0 +1,275 @@
1
+ # This file is part of KalibroGem
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 KalibroGem::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 = KalibroGem::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 = 'test'
42
+ KalibroGem::Entities::Model.expects(:class_name).returns(endpoint)
43
+ KalibroGem::Entities::Model.endpoint.should eq(endpoint)
44
+ end
45
+ end
46
+
47
+ describe 'client' do
48
+ it 'returns a Savon::Client' do
49
+ KalibroGem::Entities::Model.client('Model').should be_a(Savon::Client)
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
+
57
+ it 'should successfully get the Kalibro version' do
58
+ client.expects(:call).
59
+ with(:project_exists, message: {project_id: 1}).
60
+ returns(mock_savon_response(fixture))
61
+ KalibroGem::Entities::Model.
62
+ expects(:client).
63
+ with(any_parameters).
64
+ returns(client)
65
+ KalibroGem::Entities::Model.
66
+ request(:project_exists, {project_id: 1})[:exists].should eq(false)
67
+ end
68
+ end
69
+
70
+ describe 'to_hash' do
71
+ it 'should return an empty hash' do
72
+ subject.to_hash.should be_empty
73
+ end
74
+ end
75
+
76
+ describe 'to_object' do
77
+ it 'should return an Object with an empty hash' do
78
+ KalibroGem::Entities::Model.to_object({}).should eq(FactoryGirl.build(:model))
79
+ end
80
+
81
+ it "should remain an object if it isn't a Hash" do
82
+ KalibroGem::Entities::Model.to_object(Object.new).should be_an(Object)
83
+ end
84
+ end
85
+
86
+ describe 'to_objects_array' do
87
+ it 'should convert [{}] to [Model]' do
88
+ KalibroGem::Entities::Model.to_objects_array({}).should eq([FactoryGirl.build(:model)])
89
+ end
90
+
91
+ it 'should remain an array if it already is one' do
92
+ object = Object.new
93
+ KalibroGem::Entities::Model.to_objects_array([object]).should eq([object])
94
+ end
95
+ end
96
+
97
+ describe 'save' do
98
+ before :each do
99
+ KalibroGem::Entities::Model.
100
+ expects(:request).
101
+ with(:save_model, {:model=>{}}).returns({:model_id => 42})
102
+ end
103
+
104
+ context "when it doesn't have the method id=" do
105
+ it 'should make a request to save model with id returning false and an error' do
106
+ subject.save.should be(false)
107
+ subject.kalibro_errors[0].should be_a(NoMethodError)
108
+ end
109
+ end
110
+
111
+ context 'when it has the method id=' do
112
+ before :each do
113
+ KalibroGem::Entities::Model.
114
+ any_instance.expects(:id=).
115
+ with(42).
116
+ returns(42)
117
+ end
118
+
119
+ it 'should make a request to save model with id and return true without errors' do
120
+ subject.save.should be(true)
121
+ subject.kalibro_errors.should be_empty
122
+ end
123
+ end
124
+ end
125
+
126
+ describe 'save!' do
127
+ subject { FactoryGirl.build(:project) }
128
+
129
+ it 'should call save' do
130
+ subject.expects(:save)
131
+ subject.save!
132
+ end
133
+ end
134
+
135
+ describe 'create' do
136
+ before :each do
137
+ subject.expects(:save)
138
+ KalibroGem::Entities::Model.
139
+ expects(:new).
140
+ with({}).
141
+ returns(subject)
142
+ end
143
+
144
+ it 'should instantiate and save the model' do
145
+ (KalibroGem::Entities::Model.create {}).should eq(subject)
146
+ end
147
+ end
148
+
149
+ describe '==' do
150
+ context 'comparing objects from different classes' do
151
+ it 'should return false' do
152
+ subject.should_not eq(Object.new)
153
+ end
154
+ end
155
+
156
+ context 'with two models with different attribute values' do
157
+ let(:another_model) { FactoryGirl.build(:model) }
158
+ before :each do
159
+ subject.expects(:variable_names).returns(["answer"])
160
+ subject.expects(:send).with("answer").returns(42)
161
+ another_model.expects(:send).with("answer").returns(41)
162
+ end
163
+
164
+ it 'should return false' do
165
+ subject.should_not eq(another_model)
166
+ end
167
+ end
168
+
169
+ context 'with two empty models' do
170
+ it 'should return true' do
171
+ subject.should eq(FactoryGirl.build(:model))
172
+ end
173
+ end
174
+ end
175
+
176
+ describe 'exists?' do
177
+ context 'with an inexistent id' do
178
+ before :each do
179
+ KalibroGem::Entities::Model.
180
+ expects(:request).
181
+ with(:model_exists,{:model_id=>0}).
182
+ returns({:exists => false})
183
+ end
184
+
185
+ it 'should return false' do
186
+ KalibroGem::Entities::Model.exists?(0).should eq(false)
187
+ end
188
+ end
189
+
190
+ context 'with an existent id' do
191
+ before :each do
192
+ KalibroGem::Entities::Model.
193
+ expects(:request).
194
+ with(:model_exists,{:model_id=>42}).
195
+ returns({:exists => true})
196
+ end
197
+
198
+ it 'should return false' do
199
+ KalibroGem::Entities::Model.exists?(42).should eq(true)
200
+ end
201
+ end
202
+ end
203
+
204
+ describe 'find' do
205
+ context 'with an inexistent id' do
206
+ before :each do
207
+ KalibroGem::Entities::Model.expects(:exists?).with(0).returns(false)
208
+ end
209
+
210
+ it 'should raise a RecordNotFound error' do
211
+ expect { KalibroGem::Entities::Model.find(0)}.to raise_error(KalibroGem::Errors::RecordNotFound)
212
+ end
213
+ end
214
+
215
+ context 'with an existent id' do
216
+ before :each do
217
+ KalibroGem::Entities::Model.
218
+ expects(:exists?).with(42).
219
+ returns(true)
220
+ KalibroGem::Entities::Model.
221
+ expects(:request).
222
+ with(:get_model,{:model_id => 42}).returns({:model => {}})
223
+ end
224
+
225
+ it 'should return an empty model' do
226
+ KalibroGem::Entities::Model.find(42).should eq(subject)
227
+ end
228
+ end
229
+ end
230
+
231
+ describe 'destroy' do
232
+ context 'when it gets successfully destroyed' do
233
+ before :each do
234
+ subject.expects(:id).at_least_once.returns(42)
235
+ KalibroGem::Entities::Model.
236
+ expects(:request).
237
+ with(:delete_model,{:model_id => subject.id})
238
+ end
239
+
240
+ it 'should remain with the errors array empty' do
241
+ subject.destroy
242
+ subject.kalibro_errors.should be_empty
243
+ end
244
+ end
245
+
246
+ context 'when the destruction fails' do
247
+ before :each do
248
+ subject.expects(:id).at_least_once.returns(42)
249
+ KalibroGem::Entities::Model.
250
+ expects(:request).
251
+ with(:delete_model,{:model_id => subject.id}).raises(Exception.new)
252
+ end
253
+
254
+ it "should have an exception inside it's errors" do
255
+ subject.destroy
256
+
257
+ subject.kalibro_errors[0].should be_an(Exception)
258
+ end
259
+ end
260
+ end
261
+
262
+ describe 'create_objects_array_from_hash' do
263
+ context 'with nil' do
264
+ it 'should return an empty array' do
265
+ KalibroGem::Entities::Model.create_objects_array_from_hash(nil).should eq([])
266
+ end
267
+ end
268
+
269
+ context 'with a Hash' do
270
+ it 'should return the correspondent object to the given hash inside of an Array' do
271
+ KalibroGem::Entities::Model.create_objects_array_from_hash({}).should eq([subject])
272
+ end
273
+ end
274
+ end
275
+ end
@@ -0,0 +1,163 @@
1
+ # This file is part of KalibroGem
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 KalibroGem::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
+ KalibroGem::Entities::ModuleResult.
26
+ expects(:request).
27
+ with(:get_module_result, { :module_result_id => subject.id }).
28
+ returns({module_result: subject.to_hash})
29
+ end
30
+
31
+ it 'should return a hash with module result' do
32
+ KalibroGem::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
+ KalibroGem::Entities::ModuleResult.
43
+ expects(:request).
44
+ with(:get_module_result, { :module_result_id => subject.id }).
45
+ raises(Savon::SOAPFault.new(any_error_message, any_code))
46
+ end
47
+
48
+ it 'should raise an error' do
49
+ expect {KalibroGem::Entities::ModuleResult.find(subject.id)}.
50
+ to raise_error KalibroGem::Errors::RecordNotFound
51
+ end
52
+ end
53
+ end
54
+
55
+ describe 'children' do
56
+ before :each do
57
+ KalibroGem::Entities::ModuleResult.
58
+ expects(:request).
59
+ with(:children_of, {:module_result_id => subject.id}).
60
+ returns({module_result: 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
+ KalibroGem::Entities::ModuleResult.
74
+ expects(:request).at_least_once.
75
+ with(:get_module_result, { :module_result_id => subject.parent_id }).
76
+ returns({module_result: 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
+ KalibroGem::Entities::ModuleResult.
125
+ expects(:request).
126
+ with(:history_of_module, {:module_result_id => subject.id}).
127
+ returns({date_module_result: date_module_result.to_hash})
128
+ end
129
+
130
+ it 'should return a list of date_module_results' do
131
+ date_module_results = KalibroGem::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