Index: ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/address_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/address_spec.rb	(revision 362)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/address_spec.rb	(revision 362)
@@ -0,0 +1,33 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe Address do
+  before(:each) do
+    name = DvText.new(:value => 'address')
+    details = stub(ItemStructure, :archetype_node_id => 'at0001')
+    @address = Address.new(:archetype_node_id => 'at0000',
+                           :name => name,
+                           :details => details)
+  end
+
+  it 'should be an instance of Address' do
+    @address.should be_an_instance_of Address
+  end
+
+  it 'type is inherit from name' do
+    @address.type.value.should == 'address'
+  end
+
+  it 'details should be assigned properly' do
+    @address.details.archetype_node_id.should == 'at0001'
+  end
+
+  it 'should raise ArgumentError with nil details' do
+    lambda {
+      @address.details = nil
+    }.should raise_error ArgumentError
+  end
+end
+
Index: ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/contact_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/contact_spec.rb	(revision 362)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/contact_spec.rb	(revision 362)
@@ -0,0 +1,45 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::DataTypes::Text
+
+describe Contact do
+  before(:each) do
+    name = DvText.new(:value => 'contact')
+    addresses = stub(Array, :size => 2, :empty? => false)
+    upper = DvDate.new(:value => '2009-11-20')
+    time_validity = stub(DvInterval, :upper => upper)
+    @contact = Contact.new(:archetype_node_id => 'at0000',
+                           :name => name,
+                           :addresses => addresses,
+                           :time_validity => time_validity)
+  end
+
+  it 'should be an instance of Contact' do
+    @contact.should be_an_instance_of Contact
+  end
+
+  it 'addresses should be assigned properly' do
+    @contact.addresses.size.should == 2
+  end
+
+  it 'should raise ArgumentError with nil address' do
+    lambda {
+      @contact.addresses = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty addresses' do
+    lambda {
+      @contact.addresses = [ ]
+    }.should raise_error ArgumentError
+  end
+
+  it 'time_validity should be assigned properly' do
+    @contact.time_validity.upper.value.should == '2009-11-20'
+  end
+
+  it 'purpose should be inherit as name' do
+    @contact.purpose.value.should == 'contact'
+  end
+end
Index: ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/party_identity_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/party_identity_spec.rb	(revision 362)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/party_identity_spec.rb	(revision 362)
@@ -0,0 +1,26 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe PartyIdentity do
+  before(:each) do
+    name = DvText.new(:value => 'test')
+    details = stub(ItemStructure, :archetype_node_id => 'at0002')
+    @party_identity = PartyIdentity.new(:archetype_node_id => 'at0001',
+                                        :name => name,
+                                        :details => details)
+  end
+
+  it 'should be an instance of PartyIdentity' do
+    @party_identity.should be_an_instance_of PartyIdentity
+  end
+
+  it 'details should be assigned properly' do
+    @party_identity.details.archetype_node_id.should == 'at0002'
+  end
+
+  it 'purpose should return as same as name' do
+    @party_identity.purpose.value.should == 'test'
+  end
+end
Index: ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/party_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/party_spec.rb	(revision 362)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/party_spec.rb	(revision 362)
@@ -0,0 +1,119 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe Party do
+  before(:each) do
+    name = DvText.new(:value => 'PARTY')
+    uid = HierObjectID.new(:value => '01')
+    identities = stub(Set, :empty? => false, :size => 2)
+    contacts = stub(Set, :size => 3, :empty? => false)
+    cur_id = stub(ObjectID, :value => '01')
+    cur_source = stub(PartyRef, :id => cur_id)
+    id1 = stub(ObjectID, :value => '03')
+    targ1 = stub(PartyRef, :id => id1)
+    rel1 = stub(PartyRelationship, :source => cur_source,
+                :target => targ1)
+    id2 = stub(ObjectID, :value => '04')
+    targ2 = stub(PartyRef, :id => id2)
+    rel2 = stub(PartyRelationship, :source => cur_source,
+                :target => targ2)
+    id3 = stub(ObjectID, :value => '05')
+    targ3 = stub(PartyRef, :id => id3) 
+    rel3 = stub(PartyRelationship, :source => cur_source,
+                :target => targ3)
+    id4 = stub(ObjectID, :value => '06')
+    targ4 = stub(PartyRef, :id => id4)
+    rel4 = stub(PartyRelationship, :source => cur_source,
+                :target => targ4)
+    relationships = [rel1, rel2, rel3, rel4].to_set
+    reverse_relationships = stub(Set, :empty? => false, :size => 5)
+    details = stub(ItemStructure, :archetype_node_id => 'at0005')
+    @party = Party.new(:archetype_node_id => 'at0001',
+                       :name => name,
+                       :uid => uid,
+                       :identities => identities,
+                       :contacts => contacts,
+                       :relationships => relationships,
+                       :reverse_relationships => reverse_relationships,
+                       :details => details)
+  end
+
+  it 'should be an instance of Party' do
+    @party.should be_an_instance_of Party
+  end
+
+  it 'uid should be assigned properly' do
+    @party.uid.value.should == '01'
+  end
+
+  it 'should raise ArgumentError with nil uid' do
+    lambda {
+      @party.uid = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'identities should be assigned properly' do
+    @party.identities.size.should be_equal 2
+p  end
+
+  it 'should raise ArgumentError when nil identities are assigned' do
+    lambda {
+      @party.identities = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when identities are empty' do
+    lambda {
+      @party.identities = Set.new
+    }
+  end
+
+  it 'type should be alias of name' do
+    @party.type.value.should == 'PARTY'
+  end
+
+  it 'contacts should be assigned properly' do
+    @party.contacts.size.should be_equal 3
+  end
+
+  it 'relationships should be assigned properly' do
+    target_ids = Set.new
+    @party.relationships.each do |rel|
+      target_ids << rel.target.id.value
+    end
+    target_ids.should == %w{03 04 05 06}.to_set
+  end
+
+  it 'should not raise ArgumentError with nil relationships' do
+    lambda {
+      @party.relationships = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty relationships' do
+    lambda {
+      @party.relationships = Set.new
+    }.should raise_error ArgumentError
+  end
+  
+
+  it 'reverse relationship should be assigned properly' do
+    @party.reverse_relationships.size.should be_equal 5
+  end
+
+  it 'reverse_relationships should not be empty' do
+    lambda {
+      @party.reverse_relationships = Set.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'should validate reverse_relationships'
+
+  it 'details should be assigned properly' do
+    @party.details.archetype_node_id.should == 'at0005'
+  end
+end
+
