kalibro_entities 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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +21 -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/base_tool/all_names.feature +8 -0
- data/features/base_tool/find_by_name.feature +12 -0
- data/features/configuration/all.feature +10 -0
- data/features/metric_configuration/find.feature +18 -0
- data/features/metric_configuration/metric_configurations_of.feature +18 -0
- data/features/metric_result/descendant_results.feature +19 -0
- data/features/metric_result/history_of.feature +20 -0
- data/features/metric_result/metric_results_of.feature +19 -0
- data/features/module_result/children.feature +18 -0
- data/features/module_result/find.feature +15 -0
- data/features/module_result/history_of.feature +11 -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 +18 -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/ranges_of.feature +22 -0
- data/features/range/save.feature +32 -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/repository/all.feature +14 -0
- data/features/repository/cancel_processing.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 +9 -0
- data/features/step_definitions/base_tool_steps.rb +28 -0
- data/features/step_definitions/configuration_steps.rb +11 -0
- data/features/step_definitions/metric_configuration_steps.rb +52 -0
- data/features/step_definitions/metric_result_steps.rb +29 -0
- data/features/step_definitions/metric_steps.rb +3 -0
- data/features/step_definitions/module_result_steps.rb +30 -0
- data/features/step_definitions/processing_steps.rb +91 -0
- data/features/step_definitions/project_steps.rb +48 -0
- data/features/step_definitions/range_steps.rb +41 -0
- data/features/step_definitions/reading_group_steps.rb +19 -0
- data/features/step_definitions/reading_steps.rb +20 -0
- data/features/step_definitions/repository_steps.rb +57 -0
- data/features/support/env.rb +25 -0
- data/features/support/kalibro_cucumber_helpers.yml.sample +10 -0
- data/kalibro_entities.gemspec +48 -0
- data/lib/kalibro_entities.rb +61 -0
- data/lib/kalibro_entities/entities.rb +37 -0
- data/lib/kalibro_entities/entities/base_tool.rb +54 -0
- data/lib/kalibro_entities/entities/configuration.rb +33 -0
- data/lib/kalibro_entities/entities/date_metric_result.rb +39 -0
- data/lib/kalibro_entities/entities/date_module_result.rb +39 -0
- data/lib/kalibro_entities/entities/metric.rb +21 -0
- data/lib/kalibro_entities/entities/metric_configuration.rb +70 -0
- data/lib/kalibro_entities/entities/metric_configuration_snapshot.rb +57 -0
- data/lib/kalibro_entities/entities/metric_result.rb +63 -0
- data/lib/kalibro_entities/entities/model.rb +162 -0
- data/lib/kalibro_entities/entities/module.rb +27 -0
- data/lib/kalibro_entities/entities/module_result.rb +69 -0
- data/lib/kalibro_entities/entities/process_time.rb +31 -0
- data/lib/kalibro_entities/entities/processing.rb +113 -0
- data/lib/kalibro_entities/entities/project.rb +34 -0
- data/lib/kalibro_entities/entities/range.rb +75 -0
- data/lib/kalibro_entities/entities/range_snapshot.rb +37 -0
- data/lib/kalibro_entities/entities/reading.rb +51 -0
- data/lib/kalibro_entities/entities/reading_group.rb +43 -0
- data/lib/kalibro_entities/entities/repository.rb +78 -0
- data/lib/kalibro_entities/entities/repository_observer.rb +50 -0
- data/lib/kalibro_entities/entities/stack_trace_element.rb +31 -0
- data/lib/kalibro_entities/entities/throwable.rb +42 -0
- data/lib/kalibro_entities/errors.rb +18 -0
- data/lib/kalibro_entities/errors/record_not_found.rb +22 -0
- data/lib/kalibro_entities/errors/standard.rb +24 -0
- data/lib/kalibro_entities/helpers/aggregation_options.rb +25 -0
- data/lib/kalibro_entities/helpers/hash_converters.rb +48 -0
- data/lib/kalibro_entities/helpers/request_methods.rb +47 -0
- data/lib/kalibro_entities/helpers/xml_converters.rb +20 -0
- data/lib/kalibro_entities/kalibro_cucumber_helpers.rb +40 -0
- data/lib/kalibro_entities/kalibro_cucumber_helpers/configuration.rb +39 -0
- data/lib/kalibro_entities/kalibro_cucumber_helpers/hooks.rb +50 -0
- data/lib/kalibro_entities/kalibro_cucumber_helpers/scripts/delete_all_kalibro_entries.sh +23 -0
- data/lib/kalibro_entities/kalibro_cucumber_helpers/scripts/prepare_kalibro_query_file.sh +38 -0
- data/lib/kalibro_entities/kalibro_cucumber_helpers/scripts/put_kalibro_on_test_mode.sh +35 -0
- data/lib/kalibro_entities/kalibro_cucumber_helpers/scripts/return_kalibro_from_test_mode.sh +26 -0
- data/lib/kalibro_entities/version.rb +19 -0
- data/lib/rake/test_task.rb +57 -0
- data/spec/entities/base_tool_spec.rb +168 -0
- data/spec/entities/configuration_spec.rb +61 -0
- data/spec/entities/date_metric_result_spec.rb +62 -0
- data/spec/entities/date_module_result_spec.rb +61 -0
- data/spec/entities/metric_configuration_snapshot_spec.rb +107 -0
- data/spec/entities/metric_configuration_spec.rb +149 -0
- data/spec/entities/metric_result_spec.rb +193 -0
- data/spec/entities/metric_spec.rb +47 -0
- data/spec/entities/model_spec.rb +275 -0
- data/spec/entities/module_result_spec.rb +135 -0
- data/spec/entities/process_time_spec.rb +33 -0
- data/spec/entities/processing_spec.rb +334 -0
- data/spec/entities/project_spec.rb +68 -0
- data/spec/entities/range_snapshot_spec.rb +50 -0
- data/spec/entities/range_spec.rb +181 -0
- data/spec/entities/reading_group_spec.rb +90 -0
- data/spec/entities/reading_spec.rb +106 -0
- data/spec/entities/repository_observer_spec.rb +123 -0
- data/spec/entities/repository_spec.rb +167 -0
- data/spec/entities/stack_trace_element_spec.rb +26 -0
- data/spec/entities/throwable_spec.rb +51 -0
- data/spec/factories/base_tools.rb +31 -0
- data/spec/factories/configurations.rb +29 -0
- data/spec/factories/date_metric_results.rb +28 -0
- data/spec/factories/date_module_results.rb +22 -0
- data/spec/factories/metric_configurations.rb +28 -0
- data/spec/factories/metric_configurations_snapshot.rb +26 -0
- data/spec/factories/metric_results.rb +24 -0
- data/spec/factories/metrics.rb +35 -0
- data/spec/factories/models.rb +20 -0
- data/spec/factories/module_results.rb +33 -0
- data/spec/factories/modules.rb +22 -0
- data/spec/factories/process_times.rb +27 -0
- data/spec/factories/processings.rb +25 -0
- data/spec/factories/projects.rb +29 -0
- data/spec/factories/ranges.rb +30 -0
- data/spec/factories/ranges_snapshot.rb +26 -0
- data/spec/factories/reading_groups.rb +23 -0
- data/spec/factories/readings.rb +25 -0
- data/spec/factories/repositories.rb +34 -0
- data/spec/factories/repository_observers.rb +24 -0
- data/spec/factories/stack_trace_elements.rb +24 -0
- data/spec/factories/throwables.rb +23 -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 +108 -0
- data/spec/savon/fixtures/config.yml +1 -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 +60 -0
- metadata +461 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
# This file is part of KalibroEntities
|
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 KalibroEntities::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
|
+
KalibroEntities::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 KalibroEntities
|
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 KalibroEntities::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 = KalibroEntities::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
|
+
KalibroEntities::Entities::Model.expects(:class_name).returns(endpoint)
|
43
|
+
KalibroEntities::Entities::Model.endpoint.should eq(endpoint)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'client' do
|
48
|
+
it 'returns a Savon::Client' do
|
49
|
+
KalibroEntities::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
|
+
KalibroEntities::Entities::Model.
|
62
|
+
expects(:client).
|
63
|
+
with(any_parameters).
|
64
|
+
returns(client)
|
65
|
+
KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::Entities::Model.to_objects_array([object]).should eq([object])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'save' do
|
98
|
+
before :each do
|
99
|
+
KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::Entities::Model.
|
139
|
+
expects(:new).
|
140
|
+
with({}).
|
141
|
+
returns(subject)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should instantiate and save the model' do
|
145
|
+
(KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::Entities::Model.exists?(0).should eq(false)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'with an existent id' do
|
191
|
+
before :each do
|
192
|
+
KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::Entities::Model.expects(:exists?).with(0).returns(false)
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should raise a RecordNotFound error' do
|
211
|
+
expect { KalibroEntities::Entities::Model.find(0)}.to raise_error(KalibroEntities::Errors::RecordNotFound)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'with an existent id' do
|
216
|
+
before :each do
|
217
|
+
KalibroEntities::Entities::Model.
|
218
|
+
expects(:exists?).with(42).
|
219
|
+
returns(true)
|
220
|
+
KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::Entities::Model.create_objects_array_from_hash({}).should eq([subject])
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# This file is part of KalibroEntities
|
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 KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::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 {KalibroEntities::Entities::ModuleResult.find(subject.id)}.
|
50
|
+
to raise_error KalibroEntities::Errors::RecordNotFound
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'children' do
|
56
|
+
before :each do
|
57
|
+
KalibroEntities::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
|
+
KalibroEntities::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
|
+
KalibroEntities::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 = KalibroEntities::Entities::ModuleResult.history_of subject.id
|
132
|
+
date_module_results.first.result.should eq date_module_result.result
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|