diff --git a/app/models/person.rb b/app/models/person.rb index 62dce7a..d1853e9 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -12,6 +12,23 @@ class Person < Profile has_many :friends, :class_name => 'Person', :through => :friendships has_many :person_friendships has_many :people, :through => :person_friendships, :foreign_key => 'friend_id' + has_one :person_info + def info + if person_info.nil? + nil + else + [ + [ _('Name'), self.name ], + [ _('Address'), self.person_info.address ], + [ _('Contact Information'), self.person_info.contact_information ], + ] + end + end validates_presence_of :user_id + + def initialize(*args) + super(*args) + self.person_info ||= PersonInfo.new + end end diff --git a/app/models/person_info.rb b/app/models/person_info.rb index ad09fc2..868b7a0 100644 --- a/app/models/person_info.rb +++ b/app/models/person_info.rb @@ -1,2 +1,5 @@ class PersonInfo < ActiveRecord::Base + + # FIXME: add file_column :photo + end diff --git a/test/unit/person_info_test.rb b/test/unit/person_info_test.rb index 7ce6789..535bedc 100644 --- a/test/unit/person_info_test.rb +++ b/test/unit/person_info_test.rb @@ -2,8 +2,12 @@ require File.dirname(__FILE__) + '/../test_helper' class PersonInfoTest < Test::Unit::TestCase - # Replace this with your real tests. - def test_truth - assert true + should 'provide desired fields' do + info = PersonInfo.new + + assert info.respond_to?(:photo) + assert info.respond_to?(:address) + assert info.respond_to?(:contact_information) end + end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index e7d645a..50e9880 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -60,4 +60,20 @@ class PersonTest < Test::Unit::TestCase assert !p2.valid? assert p2.errors.invalid?(:user_id) end + + should "have person info" do + p = Person.new + assert_kind_of PersonInfo, p.person_info + end + + should 'provide needed information in info' do + p = Person.new + p.person_info.address = 'my address' + p.person_info.contact_information = 'my contact information' + + info = p.info + assert(info.any? { |line| line[1] == 'my address' }) + assert(info.any? { |line| line[1] == 'my contact information' }) + end + end -- libgit2 0.21.2