1 | require File.dirname(__FILE__) + '/../../../../../spec_helper'
|
---|
2 | require File.dirname(__FILE__) + '/shared_examples_spec'
|
---|
3 | include OpenEHR::RM::Common::ChangeControl
|
---|
4 | include OpenEHR::RM::Common::Generic
|
---|
5 | include OpenEHR::RM::DataTypes::Quantity::DateTime
|
---|
6 |
|
---|
7 | describe VersionedObject do
|
---|
8 | before(:each) do
|
---|
9 | uid1 = ObjectVersionID.new(:value => 'ABC::DEF::1')
|
---|
10 | defining_code1 = stub(CodePhrase, :code_string => '532')
|
---|
11 | lifecycle_state1 = stub(DvCodedText, :defining_code => defining_code1)
|
---|
12 | time_committed1 = DvDateTime.new(:value => '2008-11-12T18:24:32')
|
---|
13 | audit_details1 = stub(AuditDetails, :time_committed => time_committed1)
|
---|
14 | version1 = stub(Version, :commit_audit => audit_details1,
|
---|
15 | :lifecycle_state => lifecycle_state1,
|
---|
16 | :uid => uid1)
|
---|
17 | uid2 = ObjectVersionID.new(:value => 'GHI::JKL::2')
|
---|
18 | defining_code2 = stub(CodePhrase, :code_string => '553')
|
---|
19 | lifecycle_state2 = stub(DvCodedText, :defining_code => defining_code2)
|
---|
20 | time_committed2 = DvDateTime.new(:value => '2008-12-12T19:32:14')
|
---|
21 | audit_details2 = stub(AuditDetails, :time_committed => time_committed2)
|
---|
22 | attestation = stub(Attestation)
|
---|
23 | attestations = Array.new([attestation])
|
---|
24 | contribution = stub(ObjectRef, :empty? => false, :type => 'CONTRIBUTION')
|
---|
25 | version2 = OriginalVersion.new(:commit_audit => audit_details2,
|
---|
26 | :lifecycle_state => lifecycle_state2,
|
---|
27 | :preceding_version_uid => uid1,
|
---|
28 | :uid => uid2,
|
---|
29 | :contribution => contribution,
|
---|
30 | :attestations => attestations)
|
---|
31 | uid3 = ObjectVersionID.new(:value => 'MNO::PQR::3')
|
---|
32 | defining_code3 = stub(CodePhrase, :code_string => '523')
|
---|
33 | lifecycle_state3 = stub(DvCodedText, :defining_code => defining_code3)
|
---|
34 | time_committed3 = DvDateTime.new(:value => '2009-07-15T09:24:26')
|
---|
35 | audit_details3 = stub(AuditDetails, :time_committed => time_committed3)
|
---|
36 | version3 = stub(Version, :commit_audit => audit_details3,
|
---|
37 | :lifecycle_state => lifecycle_state3,
|
---|
38 | :uid => uid3)
|
---|
39 | uid = HierObjectID.new(:value => 'STU::VWX::5')
|
---|
40 | owner_id = stub(ObjectRef, :namespace => 'test')
|
---|
41 | time_created = DvDateTime.new(:value => '2009-11-09T09:53:22')
|
---|
42 | object_id = stub(ObjectID, :value => 'unique')
|
---|
43 | all_versions = [version1, version2, version3]
|
---|
44 | @versioned_object = VersionedObject.new(:uid => uid,
|
---|
45 | :owner_id => owner_id,
|
---|
46 | :time_created => time_created,
|
---|
47 | :all_versions => all_versions)
|
---|
48 | end
|
---|
49 |
|
---|
50 | it 'should be an instance of VersionedObject' do
|
---|
51 | @versioned_object.should be_an_instance_of VersionedObject
|
---|
52 | end
|
---|
53 |
|
---|
54 | it 'uid value should be STU::VWX::5' do
|
---|
55 | @versioned_object.uid.value.should == 'STU::VWX::5'
|
---|
56 | end
|
---|
57 |
|
---|
58 | it 'owner_id namespace should be test' do
|
---|
59 | @versioned_object.owner_id.namespace.should == 'test'
|
---|
60 | end
|
---|
61 |
|
---|
62 | it 'all_versions.size should be 3' do
|
---|
63 | @versioned_object.all_versions.size.should == 3
|
---|
64 | end
|
---|
65 |
|
---|
66 | it 'version_count should be 3' do
|
---|
67 | @versioned_object.version_count.should == 3
|
---|
68 | end
|
---|
69 |
|
---|
70 | it 'time_created should equal 2009-11-09T09:53:22' do
|
---|
71 | @versioned_object.time_created.value.should == '2009-11-09T09:53:22'
|
---|
72 | end
|
---|
73 |
|
---|
74 | it 'all_version_ids should return all ids of versions' do
|
---|
75 | ids = @versioned_object.all_version_ids
|
---|
76 | ids.each do |id|
|
---|
77 | %w(ABC::DEF::1 GHI::JKL::2 MNO::PQR::3).should include id.value
|
---|
78 | end
|
---|
79 | end
|
---|
80 |
|
---|
81 | it 'should have version id ABC::DEF::1' do
|
---|
82 | object_version_id = ObjectVersionID.new(:value => 'ABC::DEF::1')
|
---|
83 | @versioned_object.has_version_id?(object_version_id).should be_true
|
---|
84 | end
|
---|
85 |
|
---|
86 | it 'should not have version id BCD::EFG::12' do
|
---|
87 | object_version_id = ObjectVersionID.new(:value => 'BCD::EFG::12')
|
---|
88 | @versioned_object.has_version_id?(object_version_id).should be_false
|
---|
89 | end
|
---|
90 |
|
---|
91 | it 'ABC::DEF::1 should not be original version' do
|
---|
92 | object_version_id = ObjectVersionID.new(:value => 'ABC::DEF::1')
|
---|
93 | @versioned_object.is_original_version?(object_version_id).should be_false
|
---|
94 | end
|
---|
95 |
|
---|
96 | it 'GHI::JKL::2 should be original version' do
|
---|
97 | object_version_id = ObjectVersionID.new(:value => 'GHI::JKL::2')
|
---|
98 | @versioned_object.is_original_version?(object_version_id).should be_true
|
---|
99 | end
|
---|
100 |
|
---|
101 | it 'should have 2009-07-15T09:24:26 committed version' do
|
---|
102 | exist_time = DvDateTime.new(:value => '2009-07-15T09:24:26')
|
---|
103 | @versioned_object.has_version_at_time?(exist_time).should be_true
|
---|
104 | end
|
---|
105 |
|
---|
106 | it 'should retrun version3 with id MNO::PQR::3' do
|
---|
107 | uid = ObjectVersionID.new(:value => 'MNO::PQR::3')
|
---|
108 | @versioned_object.version_with_id(uid).commit_audit.time_committed.
|
---|
109 | should == DvDateTime.new(:value => '2009-07-15T09:24:26')
|
---|
110 | end
|
---|
111 |
|
---|
112 | it 'should return version2 with 2008-12-12T19:32:14' do
|
---|
113 | exist_date = DvDateTime.new(:value => '2008-12-12T19:32:14')
|
---|
114 | @versioned_object.version_at_time(exist_date).lifecycle_state.
|
---|
115 | defining_code.code_string.should == '553'
|
---|
116 | end
|
---|
117 |
|
---|
118 | it 'latest_version should return version3' do
|
---|
119 | @versioned_object.latest_version.uid.value.should == 'MNO::PQR::3'
|
---|
120 | end
|
---|
121 |
|
---|
122 | it 'latest_trunk_version should return ABC::DEF::1' do
|
---|
123 | @versioned_object.latest_trunk_version.uid.value.should ==
|
---|
124 | 'ABC::DEF::1'
|
---|
125 | end
|
---|
126 |
|
---|
127 | it 'trunk_lifecycle_state should return 532' do
|
---|
128 | @versioned_object.trunk_lifecycle_state.defining_code.
|
---|
129 | code_string.should == '532'
|
---|
130 | end
|
---|
131 |
|
---|
132 | it 'revision_history items are 3' do
|
---|
133 | @versioned_object.revision_history.items.size.should == 3
|
---|
134 | end
|
---|
135 |
|
---|
136 | it 'should be able to commit original version' do
|
---|
137 | contribution = stub(ObjectRef, :empty? => false, :type => 'CONTRIBUTION')
|
---|
138 | uid = ObjectVersionID.new(:value => 'EFG::HIJ::7')
|
---|
139 | preceding_version_uid = ObjectVersionID.new(:value => 'ABC::DEF::1')
|
---|
140 | audit = stub(AuditDetails)
|
---|
141 | defining_code = stub(CodePhrase, :code_string => '523')
|
---|
142 | lifecycle_state = stub(DvCodedText, :defining_code => defining_code)
|
---|
143 | attestations = stub(Array, :empty? => false)
|
---|
144 | @versioned_object.
|
---|
145 | commit_original_version(:contribution => contribution,
|
---|
146 | :uid => uid,
|
---|
147 | :preceding_version_uid => preceding_version_uid,
|
---|
148 | :commit_audit => audit,
|
---|
149 | :lifecycle_state => lifecycle_state,
|
---|
150 | :data => 'data',
|
---|
151 | :attestations => attestations,
|
---|
152 | :signature => 'A41bdad')
|
---|
153 | @versioned_object.all_versions.size.should == 4
|
---|
154 | end
|
---|
155 |
|
---|
156 | it 'should raise ArgumentError with invalid preceeding version' do
|
---|
157 | contribution = stub(ObjectRef, :empty? => false, :type => 'CONTRIBUTION')
|
---|
158 | uid = ObjectVersionID.new(:value => 'EFG::HIJ::7')
|
---|
159 | preceding_version_uid = ObjectVersionID.new(:value => 'BCD::EFG::8')
|
---|
160 | audit = stub(AuditDetails)
|
---|
161 | defining_code = stub(CodePhrase, :code_string => '523')
|
---|
162 | lifecycle_state = stub(DvCodedText, :defining_code => defining_code)
|
---|
163 | attestations = stub(Array, :empty? => false)
|
---|
164 | lambda {
|
---|
165 | @versioned_object.
|
---|
166 | commit_original_version(:contribution => contribution,
|
---|
167 | :uid => uid,
|
---|
168 | :preceding_version_uid => preceding_version_uid,
|
---|
169 | :commit_audit => audit,
|
---|
170 | :lifecycle_state => lifecycle_state,
|
---|
171 | :data => 'data',
|
---|
172 | :attestations => attestations,
|
---|
173 | :signature => 'A41bdad')
|
---|
174 | }.should raise_error ArgumentError
|
---|
175 | end
|
---|
176 |
|
---|
177 | it 'should be able to commit original merged version' do
|
---|
178 | contribution = stub(ObjectRef, :empty? => false, :type => 'CONTRIBUTION')
|
---|
179 | uid = ObjectVersionID.new(:value => 'KLM::NOP::9')
|
---|
180 | preceding_version_uid = ObjectVersionID.new(:value => 'ABC::DEF::1')
|
---|
181 | time_committed = DvDateTime.new(:value => '2009-11-09T23:42:18')
|
---|
182 | audit = stub(AuditDetails, :time_committed => time_committed)
|
---|
183 | defining_code = stub(CodePhrase, :code_string => '523')
|
---|
184 | lifecycle_state = stub(DvCodedText, :defining_code => defining_code)
|
---|
185 | attestations = stub(Array, :empty? => false)
|
---|
186 | @versioned_object.
|
---|
187 | commit_original_merged_version(:contribution => contribution,
|
---|
188 | :uid => uid,
|
---|
189 | :preceding_version_uid => preceding_version_uid,
|
---|
190 | :commit_audit => audit,
|
---|
191 | :lifecycle_state => lifecycle_state,
|
---|
192 | :data => 'merged data',
|
---|
193 | :attestations => attestations,
|
---|
194 | :signature => 'dc3dbdad')
|
---|
195 | @versioned_object.latest_version.data.should == 'merged data'
|
---|
196 | end
|
---|
197 |
|
---|
198 | it 'should be able to commit imported_version' do
|
---|
199 | contribution = stub(ObjectRef, :empty? => false, :type => 'CONTRIBUTION')
|
---|
200 | time_committed = DvDateTime.new(:value => '2009-11-09T23:42:18')
|
---|
201 | audit = stub(AuditDetails, :time_committed => time_committed)
|
---|
202 | uid = ObjectVersionID.new(:value => 'QRS::TUV::10')
|
---|
203 | preceding_version_uid = ObjectVersionID.new(:value => 'ABC::DEF::1')
|
---|
204 | defining_code = stub(CodePhrase, :code_string => '523')
|
---|
205 | lifecycle_state = stub(DvCodedText, :defining_code => defining_code)
|
---|
206 | attestations = stub(Array, :empty? => false)
|
---|
207 | original_version = OriginalVersion.new(:uid => uid,
|
---|
208 | :contribution => contribution,
|
---|
209 | :commit_audit => audit,
|
---|
210 | :preceding_version_uid => preceding_version_uid,
|
---|
211 | :data => 'original data',
|
---|
212 | :lifecycle_state => lifecycle_state,
|
---|
213 | :attestations => attestations)
|
---|
214 | @versioned_object.commit_imported_version(:contribution => contribution,
|
---|
215 | :commit_audit => audit,
|
---|
216 | :item => original_version)
|
---|
217 | @versioned_object.latest_version.commit_audit.time_committed.value.
|
---|
218 | should == '2009-11-09T23:42:18'
|
---|
219 | end
|
---|
220 |
|
---|
221 | it 'should be able to commit attestation' do
|
---|
222 | attestation = stub(Attestation)
|
---|
223 | uid = ObjectVersionID.new(:value => 'GHI::JKL::2')
|
---|
224 | @versioned_object.commit_attestation(:attestation => attestation,
|
---|
225 | :uid => uid,
|
---|
226 | :signature => 'CDAEbad')
|
---|
227 | @versioned_object.version_with_id(uid).signature.
|
---|
228 | should == 'CDAEbad'
|
---|
229 | end
|
---|
230 |
|
---|
231 | it 'should raise ArgumentError when time_created is nil' do
|
---|
232 | lambda {
|
---|
233 | @versioned_object.time_created = nil
|
---|
234 | }.should raise_error ArgumentError
|
---|
235 | end
|
---|
236 |
|
---|
237 | it 'should raise ArgumentError when all_versions are nil' do
|
---|
238 | lambda {
|
---|
239 | @versioned_object.all_versions = nil
|
---|
240 | }.should raise_error ArgumentError
|
---|
241 | end
|
---|
242 |
|
---|
243 | it 'should raise ArgumentError when is_original_version argument is nil' do
|
---|
244 | lambda {
|
---|
245 | @versioned_object.is_original_version?(nil)
|
---|
246 | }.should raise_error ArgumentError
|
---|
247 | end
|
---|
248 |
|
---|
249 | it 'should not has time data' do
|
---|
250 | unexisted_time = DvDateTime.new(:value => '2009-11-10T00:43:59')
|
---|
251 | lambda {
|
---|
252 | @versioned_object.version_at_time(unexisted_time)
|
---|
253 | }.should raise_error ArgumentError
|
---|
254 | end
|
---|
255 |
|
---|
256 | it 'should raise ArgumentError with nil argument to commit_attestations' do
|
---|
257 | lambda {
|
---|
258 | @versioned_object.commit_attestation(:attestation => nil)
|
---|
259 | }.should raise_error ArgumentError
|
---|
260 | end
|
---|
261 |
|
---|
262 | it 'should raise ArgumentError with not orinigal version id' do
|
---|
263 | uid = ObjectVersionID.new(:value => 'ABC::DEF::1')
|
---|
264 | attestation = stub(Attestation)
|
---|
265 | lambda {
|
---|
266 | @versioned_object.commit_attestation(:attestation => attestation,
|
---|
267 | :uid => uid,
|
---|
268 | :signature => 'DEADBEAFE81')
|
---|
269 | }.should raise_error ArgumentError
|
---|
270 | end
|
---|
271 |
|
---|
272 | it 'should raise ArgumentError with nil argument to version with id' do
|
---|
273 | lambda {
|
---|
274 | @versioned_object.version_with_id(nil)
|
---|
275 | }.should raise_error ArgumentError
|
---|
276 | end
|
---|
277 |
|
---|
278 | it 'should raise ArgumentError with unexsited version with id ' do
|
---|
279 | uid = ObjectVersionID.new(:value => 'CBA::FED::1')
|
---|
280 | lambda {
|
---|
281 | @versioned_object.version_with_id(uid)
|
---|
282 | }.should raise_error ArgumentError
|
---|
283 | end
|
---|
284 | end
|
---|