kalibro_gatekeeper_client 0.0.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +29 -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/all.feature +14 -0
- data/features/range/exists.feature +13 -0
- data/features/range/find.feature +14 -0
- data/features/range/ranges_of.feature +22 -0
- data/features/range/save.feature +14 -0
- data/features/reading/all.feature +13 -0
- data/features/reading/exists.feature +13 -0
- data/features/reading/find.feature +11 -0
- data/features/reading/readings_of.feature +11 -0
- data/features/reading_group/all.feature +10 -0
- data/features/repository/all.feature +14 -0
- data/features/repository/cancel_processing.feature +14 -0
- data/features/repository/exists.feature +14 -0
- data/features/repository/find.feature +14 -0
- data/features/repository/of.feature +15 -0
- data/features/repository/process.feature +16 -0
- data/features/repository/types.feature +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 +68 -0
- data/features/step_definitions/reading_group_steps.rb +19 -0
- data/features/step_definitions/reading_steps.rb +39 -0
- data/features/step_definitions/repository_steps.rb +61 -0
- data/features/support/env.rb +25 -0
- data/features/support/kalibro_cucumber_helpers.yml.sample +10 -0
- data/kalibro_gatekeeper_client.gemspec +49 -0
- data/lib/kalibro_gatekeeper_client/entities/base_tool.rb +55 -0
- data/lib/kalibro_gatekeeper_client/entities/configuration.rb +34 -0
- data/lib/kalibro_gatekeeper_client/entities/date_metric_result.rb +39 -0
- data/lib/kalibro_gatekeeper_client/entities/date_module_result.rb +39 -0
- data/lib/kalibro_gatekeeper_client/entities/metric.rb +21 -0
- data/lib/kalibro_gatekeeper_client/entities/metric_configuration.rb +76 -0
- data/lib/kalibro_gatekeeper_client/entities/metric_configuration_snapshot.rb +57 -0
- data/lib/kalibro_gatekeeper_client/entities/metric_result.rb +72 -0
- data/lib/kalibro_gatekeeper_client/entities/model.rb +174 -0
- data/lib/kalibro_gatekeeper_client/entities/module.rb +27 -0
- data/lib/kalibro_gatekeeper_client/entities/module_result.rb +75 -0
- data/lib/kalibro_gatekeeper_client/entities/process_time.rb +31 -0
- data/lib/kalibro_gatekeeper_client/entities/processing.rb +113 -0
- data/lib/kalibro_gatekeeper_client/entities/project.rb +35 -0
- data/lib/kalibro_gatekeeper_client/entities/range.rb +100 -0
- data/lib/kalibro_gatekeeper_client/entities/range_snapshot.rb +37 -0
- data/lib/kalibro_gatekeeper_client/entities/reading.rb +67 -0
- data/lib/kalibro_gatekeeper_client/entities/reading_group.rb +44 -0
- data/lib/kalibro_gatekeeper_client/entities/repository.rb +89 -0
- data/lib/kalibro_gatekeeper_client/entities/repository_observer.rb +50 -0
- data/lib/kalibro_gatekeeper_client/entities/stack_trace_element.rb +31 -0
- data/lib/kalibro_gatekeeper_client/entities/throwable.rb +42 -0
- data/lib/kalibro_gatekeeper_client/entities.rb +37 -0
- data/lib/kalibro_gatekeeper_client/errors/record_not_found.rb +22 -0
- data/lib/kalibro_gatekeeper_client/errors/standard.rb +24 -0
- data/lib/kalibro_gatekeeper_client/errors.rb +18 -0
- data/lib/kalibro_gatekeeper_client/helpers/aggregation_options.rb +25 -0
- data/lib/kalibro_gatekeeper_client/helpers/hash_converters.rb +48 -0
- data/lib/kalibro_gatekeeper_client/helpers/request_methods.rb +47 -0
- data/lib/kalibro_gatekeeper_client/helpers/xml_converters.rb +20 -0
- data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/configuration.rb +39 -0
- data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/hooks.rb +56 -0
- data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/delete_all_kalibro_entries.sh +23 -0
- data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/prepare_kalibro_query_file.sh +38 -0
- data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/put_kalibro_on_test_mode.sh +39 -0
- data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/return_kalibro_from_test_mode.sh +26 -0
- data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers.rb +40 -0
- data/lib/kalibro_gatekeeper_client/version.rb +19 -0
- data/lib/kalibro_gatekeeper_client.rb +61 -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 +173 -0
- data/spec/entities/metric_result_spec.rb +188 -0
- data/spec/entities/metric_spec.rb +47 -0
- data/spec/entities/model_spec.rb +322 -0
- data/spec/entities/module_result_spec.rb +163 -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 +225 -0
- data/spec/entities/reading_group_spec.rb +90 -0
- data/spec/entities/reading_spec.rb +148 -0
- data/spec/entities/repository_observer_spec.rb +123 -0
- data/spec/entities/repository_spec.rb +191 -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 +35 -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 +56 -0
- 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
|