Index: ruby/branches/0.5/lib/open_ehr/rm/demographic.rb
===================================================================
--- ruby/branches/0.5/lib/open_ehr/rm/demographic.rb	(revision 362)
+++ ruby/branches/0.5/lib/open_ehr/rm/demographic.rb	(revision 363)
@@ -7,29 +7,4 @@
   module RM
     module Demographic
-      class Address < Locatable
-        attr_reader :details
-
-        def initialize(args = { })
-          super(args)
-          self.details = args[:details]
-        end
-
-        def details=(details)
-          if details.nil?
-            raise ArgumentError, 'details are mandatory'
-          end
-          @details = details
-        end
-
-        def type
-          return @name
-        end
-      end
-
-      class Capability < Locatable
-        attr_reader :credentials, :time_validity
-
-      end
-
       class Party < Locatable
         attr_reader :uid, :identities, :contacts, :relationships,
@@ -115,68 +90,4 @@
       end
 
-      class PartyRelationship < Locatable
-
-      end
-
-      class VersionedParty < Locatable
-
-      end
-
-      class Role < Party
-
-      end
-
-      class Actor < Party
-        LEAGAL_IDENTITY = 'leagal identity'
-        attr_reader :languages, :rules
-
-        def initialize(uid, archetype_node_id, name, archetype_details,
-                       feeder_audit, links, identities, contacts,
-                       relationships, reverse_relationships, details,
-                       languages, rules)
-          super(uid, archetype_node_id, name, archetype_details,
-                feeder_audit, links, relationships, reverse_relationships,
-                details)
-          has_legal_identity?
-          set_languages(languages)
-          set_rules(rules)
-        end
-
-        def has_legal_identity?
-          @identities.each {|identity|
-            if (identity.purpose.value == LEAGAL_IDENTITY)
-              return true
-            end
-          }
-          false
-        end
-
-        def languages=(languages)
-          set_languages(languages)
-        end
-
-        def values=(values)
-          set_values(values)
-        end
-        private
-        def set_languages(languages)
-          if languages.nil?
-            raise ArgumentError, "languages should not be nil."
-          elsif languages.empty?
-            raise ArgumentError, "languages shouldnot be empty."
-          end
-          @languages = languages
-        end
-
-        def set_values(values)
-          if values.nil?
-            raise ArgumentError, "values should not be nil."
-          elsif values.empty?
-            raise ArgumentError, "values should not be nil."
-          end
-          @values = values
-        end
-      end
-
       class Contact < Locatable
         attr_accessor :time_validity
@@ -201,17 +112,88 @@
       end
 
+      class Address < Locatable
+        attr_reader :details
+
+        def initialize(args = { })
+          super(args)
+          self.details = args[:details]
+        end
+
+        def details=(details)
+          if details.nil?
+            raise ArgumentError, 'details are mandatory'
+          end
+          @details = details
+        end
+
+        def type
+          return @name
+        end
+      end
+
+      class Actor < Party
+        LEAGAL_IDENTITY = 'legal identity'
+        attr_reader :languages, :roles
+
+        def initialize(args = { })
+          super(args)
+          self.roles = args[:roles]
+          self.languages = args[:languages]
+        end
+
+        def roles=(roles)
+          if !roles.nil? && roles.empty?
+            raise ArgumentError, 'roles should not be empty'
+          end
+          @roles = roles
+        end
+
+        def has_legal_identity?
+          @identities.each do |identity|
+            if identity.purpose.value == LEAGAL_IDENTITY
+              return true
+            end
+          end
+          return false
+        end
+
+        def languages=(languages)
+          if !languages.nil? && languages.empty?
+            raise ArgumentError, 'languages should not be empty.'
+          end
+          @languages = languages
+        end
+      end
+
+      class Person < Actor
+
+      end
+
+      class Organisation < Actor
+
+      end
+
+      class Group < Actor
+
+      end
+
       class Agent < Actor
 
       end
 
-      class Organisation < Actor
-
-      end
-
-      class Person < Actor
-
-      end
-
-      class Group < Actor
+      class Role < Party
+
+      end
+
+      class Capability < Locatable
+        attr_reader :credentials, :time_validity
+
+      end
+
+      class PartyRelationship < Locatable
+
+      end
+
+      class VersionedParty < Locatable
 
       end
Index: ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/actor_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/actor_spec.rb	(revision 363)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/actor_spec.rb	(revision 363)
@@ -0,0 +1,79 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::Support::Identification
+
+describe Actor do
+  before(:each) do
+    name = DvText.new(:value => 'actor')
+    uid = HierObjectID.new(:value => '01')
+    identities = stub(Set, :empty? => false)
+    roles = stub(Set, :size => 2, :empty? => false)
+    languages = stub(Array, :size => 3, :empty? => false)
+    @actor = Actor.new(:archetype_node_id => 'at0000',
+                       :name => name,
+                       :uid => uid,
+                       :identities => identities,
+                       :roles => roles,
+                       :languages => languages)
+  end
+
+  it 'should be an instance of Actor' do
+    @actor.should be_an_instance_of Actor
+  end
+
+  it 'roles should be assigned properly' do
+    @actor.roles.size.should be_equal 2
+  end
+
+  it 'should raise ArgumentError with empty roles' do
+    lambda {
+      @actor.roles = Set.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentError with nil roles' do
+    lambda {
+      @actor.roles = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  it 'languages should be assigned properly' do
+    @actor.languages.size.should be_equal 3
+  end
+
+  it 'should raise ArgumentError with empty languages' do
+    lambda {
+      @actor.languages = Set.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentError with nil languages' do
+    lambda {
+      @actor.languages = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  describe 'has_legal_identity' do
+    before(:each) do
+      @dummy_purpose = DvText.new(:value => 'dummy')
+      @dummy_identity = stub(PartyIdentity, :purpose => @dummy_purpose)
+    end
+
+    it 'should not have legal identity' do
+      identity = stub(PartyIdentity, :purpose => @dummy_purpose)
+      identities = [identity, @dummy_identity].to_set
+      @actor.identities = identities
+      @actor.has_legal_identity?.should be_false
+    end
+
+    it 'should have legal identity' do
+      legal_purpose = DvText.new(:value => 'legal identity')
+      legal_identity = stub(PartyIdentity, :purpose => legal_purpose)
+      identities = [@dummy_identity, legal_identity].to_set
+      @actor.identities = identities
+      @actor.has_legal_identity?.should be_true
+    end
+  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 363)
@@ -21,4 +21,10 @@
   end
 
+  it 'should raise ArgumentError with nil details' do
+    lambda {
+      @party_identity.details = nil
+    }.should raise_error ArgumentError
+  end
+
   it 'purpose should return as same as name' do
     @party_identity.purpose.value.should == 'test'
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 363)
@@ -58,5 +58,5 @@
   it 'identities should be assigned properly' do
     @party.identities.size.should be_equal 2
-p  end
+  end
 
   it 'should raise ArgumentError when nil identities are assigned' do
@@ -80,4 +80,10 @@
   end
 
+  it 'should raise ArgumentError with empty contacts' do
+    lambda {
+      @party.contacts = Set.new
+    }.should raise_error ArgumentError
+  end
+
   it 'relationships should be assigned properly' do
     target_ids = Set.new
@@ -99,5 +105,13 @@
     }.should raise_error ArgumentError
   end
-  
+
+  it 'invaild relationship raise ArgumentError' do
+    invalid_id = stub(ObjectID, :value => '10')
+    invalid_source = stub(PartyRef, :id => invalid_id)
+    invalid_rel = stub(PartyRelationship, :source => invalid_source)
+    lambda {
+      @party.relationships = [invalid_rel].to_set
+    }.should raise_error ArgumentError
+  end
 
   it 'reverse relationship should be assigned properly' do
