1 | require File.dirname(__FILE__) + '/../../../../spec_helper'
|
---|
2 | include OpenEHR::RM::Demographic
|
---|
3 | include OpenEHR::RM::DataTypes::Text
|
---|
4 | include OpenEHR::RM::Support::Identification
|
---|
5 | include OpenEHR::RM::DataStructures::ItemStructure
|
---|
6 |
|
---|
7 | describe Party do
|
---|
8 | before(:each) do
|
---|
9 | name = DvText.new(:value => 'PARTY')
|
---|
10 | uid = HierObjectID.new(:value => '01')
|
---|
11 | identities = stub(Set, :empty? => false, :size => 2)
|
---|
12 | contacts = stub(Set, :size => 3, :empty? => false)
|
---|
13 | cur_id = stub(ObjectID, :value => '01')
|
---|
14 | cur_source = stub(PartyRef, :id => cur_id)
|
---|
15 | id1 = stub(ObjectID, :value => '03')
|
---|
16 | targ1 = stub(PartyRef, :id => id1)
|
---|
17 | rel1 = stub(PartyRelationship, :source => cur_source,
|
---|
18 | :target => targ1)
|
---|
19 | id2 = stub(ObjectID, :value => '04')
|
---|
20 | targ2 = stub(PartyRef, :id => id2)
|
---|
21 | rel2 = stub(PartyRelationship, :source => cur_source,
|
---|
22 | :target => targ2)
|
---|
23 | id3 = stub(ObjectID, :value => '05')
|
---|
24 | targ3 = stub(PartyRef, :id => id3)
|
---|
25 | rel3 = stub(PartyRelationship, :source => cur_source,
|
---|
26 | :target => targ3)
|
---|
27 | id4 = stub(ObjectID, :value => '06')
|
---|
28 | targ4 = stub(PartyRef, :id => id4)
|
---|
29 | rel4 = stub(PartyRelationship, :source => cur_source,
|
---|
30 | :target => targ4)
|
---|
31 | relationships = [rel1, rel2, rel3, rel4].to_set
|
---|
32 | reverse_relationships = stub(Set, :empty? => false, :size => 5)
|
---|
33 | details = stub(ItemStructure, :archetype_node_id => 'at0005')
|
---|
34 | @party = Party.new(:archetype_node_id => 'at0001',
|
---|
35 | :name => name,
|
---|
36 | :uid => uid,
|
---|
37 | :identities => identities,
|
---|
38 | :contacts => contacts,
|
---|
39 | :relationships => relationships,
|
---|
40 | :reverse_relationships => reverse_relationships,
|
---|
41 | :details => details)
|
---|
42 | end
|
---|
43 |
|
---|
44 | it 'should be an instance of Party' do
|
---|
45 | @party.should be_an_instance_of Party
|
---|
46 | end
|
---|
47 |
|
---|
48 | it 'uid should be assigned properly' do
|
---|
49 | @party.uid.value.should == '01'
|
---|
50 | end
|
---|
51 |
|
---|
52 | it 'should raise ArgumentError with nil uid' do
|
---|
53 | lambda {
|
---|
54 | @party.uid = nil
|
---|
55 | }.should raise_error ArgumentError
|
---|
56 | end
|
---|
57 |
|
---|
58 | it 'identities should be assigned properly' do
|
---|
59 | @party.identities.size.should be_equal 2
|
---|
60 | end
|
---|
61 |
|
---|
62 | it 'should raise ArgumentError when nil identities are assigned' do
|
---|
63 | lambda {
|
---|
64 | @party.identities = nil
|
---|
65 | }.should raise_error ArgumentError
|
---|
66 | end
|
---|
67 |
|
---|
68 | it 'should raise ArgumentError when identities are empty' do
|
---|
69 | lambda {
|
---|
70 | @party.identities = Set.new
|
---|
71 | }
|
---|
72 | end
|
---|
73 |
|
---|
74 | it 'type should be alias of name' do
|
---|
75 | @party.type.value.should == 'PARTY'
|
---|
76 | end
|
---|
77 |
|
---|
78 | it 'contacts should be assigned properly' do
|
---|
79 | @party.contacts.size.should be_equal 3
|
---|
80 | end
|
---|
81 |
|
---|
82 | it 'should raise ArgumentError with empty contacts' do
|
---|
83 | lambda {
|
---|
84 | @party.contacts = Set.new
|
---|
85 | }.should raise_error ArgumentError
|
---|
86 | end
|
---|
87 |
|
---|
88 | it 'relationships should be assigned properly' do
|
---|
89 | target_ids = Set.new
|
---|
90 | @party.relationships.each do |rel|
|
---|
91 | target_ids << rel.target.id.value
|
---|
92 | end
|
---|
93 | target_ids.should == %w{03 04 05 06}.to_set
|
---|
94 | end
|
---|
95 |
|
---|
96 | it 'should not raise ArgumentError with nil relationships' do
|
---|
97 | lambda {
|
---|
98 | @party.relationships = nil
|
---|
99 | }.should_not raise_error ArgumentError
|
---|
100 | end
|
---|
101 |
|
---|
102 | it 'should raise ArgumentError with empty relationships' do
|
---|
103 | lambda {
|
---|
104 | @party.relationships = Set.new
|
---|
105 | }.should raise_error ArgumentError
|
---|
106 | end
|
---|
107 |
|
---|
108 | it 'invaild relationship raise ArgumentError' do
|
---|
109 | invalid_id = stub(ObjectID, :value => '10')
|
---|
110 | invalid_source = stub(PartyRef, :id => invalid_id)
|
---|
111 | invalid_rel = stub(PartyRelationship, :source => invalid_source)
|
---|
112 | lambda {
|
---|
113 | @party.relationships = [invalid_rel].to_set
|
---|
114 | }.should raise_error ArgumentError
|
---|
115 | end
|
---|
116 |
|
---|
117 | it 'reverse relationship should be assigned properly' do
|
---|
118 | @party.reverse_relationships.size.should be_equal 5
|
---|
119 | end
|
---|
120 |
|
---|
121 | it 'reverse_relationships should not be empty' do
|
---|
122 | lambda {
|
---|
123 | @party.reverse_relationships = Set.new
|
---|
124 | }.should raise_error ArgumentError
|
---|
125 | end
|
---|
126 |
|
---|
127 | it 'should validate reverse_relationships'
|
---|
128 |
|
---|
129 | it 'details should be assigned properly' do
|
---|
130 | @party.details.archetype_node_id.should == 'at0005'
|
---|
131 | end
|
---|
132 | end
|
---|
133 |
|
---|