Commit 458b63b3b583768892543ca3c5eeb2141b12a296
1 parent
712d7149
Exists in
master
and in
23 other branches
ActionItem7: implementing person_info
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@451 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
43 additions
and
3 deletions
Show diff stats
app/models/person.rb
| ... | ... | @@ -12,6 +12,23 @@ class Person < Profile |
| 12 | 12 | has_many :friends, :class_name => 'Person', :through => :friendships |
| 13 | 13 | has_many :person_friendships |
| 14 | 14 | has_many :people, :through => :person_friendships, :foreign_key => 'friend_id' |
| 15 | + has_one :person_info | |
| 16 | + def info | |
| 17 | + if person_info.nil? | |
| 18 | + nil | |
| 19 | + else | |
| 20 | + [ | |
| 21 | + [ _('Name'), self.name ], | |
| 22 | + [ _('Address'), self.person_info.address ], | |
| 23 | + [ _('Contact Information'), self.person_info.contact_information ], | |
| 24 | + ] | |
| 25 | + end | |
| 26 | + end | |
| 15 | 27 | |
| 16 | 28 | validates_presence_of :user_id |
| 29 | + | |
| 30 | + def initialize(*args) | |
| 31 | + super(*args) | |
| 32 | + self.person_info ||= PersonInfo.new | |
| 33 | + end | |
| 17 | 34 | end | ... | ... |
app/models/person_info.rb
test/unit/person_info_test.rb
| ... | ... | @@ -2,8 +2,12 @@ require File.dirname(__FILE__) + '/../test_helper' |
| 2 | 2 | |
| 3 | 3 | class PersonInfoTest < Test::Unit::TestCase |
| 4 | 4 | |
| 5 | - # Replace this with your real tests. | |
| 6 | - def test_truth | |
| 7 | - assert true | |
| 5 | + should 'provide desired fields' do | |
| 6 | + info = PersonInfo.new | |
| 7 | + | |
| 8 | + assert info.respond_to?(:photo) | |
| 9 | + assert info.respond_to?(:address) | |
| 10 | + assert info.respond_to?(:contact_information) | |
| 8 | 11 | end |
| 12 | + | |
| 9 | 13 | end | ... | ... |
test/unit/person_test.rb
| ... | ... | @@ -60,4 +60,20 @@ class PersonTest < Test::Unit::TestCase |
| 60 | 60 | assert !p2.valid? |
| 61 | 61 | assert p2.errors.invalid?(:user_id) |
| 62 | 62 | end |
| 63 | + | |
| 64 | + should "have person info" do | |
| 65 | + p = Person.new | |
| 66 | + assert_kind_of PersonInfo, p.person_info | |
| 67 | + end | |
| 68 | + | |
| 69 | + should 'provide needed information in info' do | |
| 70 | + p = Person.new | |
| 71 | + p.person_info.address = 'my address' | |
| 72 | + p.person_info.contact_information = 'my contact information' | |
| 73 | + | |
| 74 | + info = p.info | |
| 75 | + assert(info.any? { |line| line[1] == 'my address' }) | |
| 76 | + assert(info.any? { |line| line[1] == 'my contact information' }) | |
| 77 | + end | |
| 78 | + | |
| 63 | 79 | end | ... | ... |