diff --git a/app/controllers/profile_editor_controller.rb b/app/controllers/profile_editor_controller.rb index 48675ec..3c4bfce 100644 --- a/app/controllers/profile_editor_controller.rb +++ b/app/controllers/profile_editor_controller.rb @@ -1,3 +1,12 @@ class ProfileEditorController < ApplicationController helper :profile + + # edits the profile info (posts back) + def edit + if request.post? + else + render :action => profile.info.class.tableize + end + end end + diff --git a/app/helpers/profile_helper.rb b/app/helpers/profile_helper.rb index 366f1f9..65aba03 100644 --- a/app/helpers/profile_helper.rb +++ b/app/helpers/profile_helper.rb @@ -6,7 +6,7 @@ module ProfileHelper content_tag('div', _('This profile does not have any public information')) else table_rows = '' - info.each do |item| + info.summary.each do |item| name = item[0] value = item[1] if value.is_a?(Proc) diff --git a/app/models/person.rb b/app/models/person.rb index d1853e9..99325ec 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -13,16 +13,9 @@ class Person < Profile 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 + person_info end validates_presence_of :user_id diff --git a/app/models/person_info.rb b/app/models/person_info.rb index 868b7a0..71702a1 100644 --- a/app/models/person_info.rb +++ b/app/models/person_info.rb @@ -2,4 +2,14 @@ class PersonInfo < ActiveRecord::Base # FIXME: add file_column :photo + belongs_to :person + + def summary + [ + [ _('Name'), self.person.name ], + [ _('Address'), self.address ], + [ _('Contact Information'), self.contact_information ], + ] + end + end diff --git a/app/models/profile.rb b/app/models/profile.rb index 9d97e1d..891e301 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -73,14 +73,18 @@ class Profile < ActiveRecord::Base end # Returns information about the profile's owner that was made public by - # him/her. The returned value must be an array in the followinf format: + # him/her. + # + # The returned value must be an object that responds to a method "summary", + # which must return an array in the following format: # # [ # [ 'First Field', first_field_value ], # [ 'Second Field', second_field_value ], # ] # - # This information shall be used by user interface to present the information + # This information shall be used by user interface to present the + # information. # # In this class, this method returns nil, what is interpreted as "no # information at all". Subclasses must override this method to provide their diff --git a/test/unit/person_info_test.rb b/test/unit/person_info_test.rb index 535bedc..4d9b4cd 100644 --- a/test/unit/person_info_test.rb +++ b/test/unit/person_info_test.rb @@ -10,4 +10,18 @@ class PersonInfoTest < Test::Unit::TestCase assert info.respond_to?(:contact_information) end + should 'provide needed information in summary' do + person_info = PersonInfo.new + person_info.person = Person.new + person_info.person.name = 'person name' + + person_info.address = 'my address' + person_info.contact_information = 'my contact information' + + summary = person_info.summary + assert(summary.any? { |line| line[1] == 'person name' }) + assert(summary.any? { |line| line[1] == 'my address' }) + assert(summary.any? { |line| line[1] == 'my contact information' }) + end + end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 50e9880..45769ec 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -66,14 +66,9 @@ class PersonTest < Test::Unit::TestCase assert_kind_of PersonInfo, p.person_info end - should 'provide needed information in info' do + should 'return person_info as 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' }) + assert_equal p.person_info, p.info end end diff --git a/test/unit/profile_helper_test.rb b/test/unit/profile_helper_test.rb index 62f455b..81a49a6 100644 --- a/test/unit/profile_helper_test.rb +++ b/test/unit/profile_helper_test.rb @@ -27,7 +27,9 @@ class ProfileHelperTest < Test::Unit::TestCase [ f1, v1 ], [ f2, v2 ] ] - profile.stubs(:info).returns(array) + info = mock + info.expects(:summary).returns(array) + profile.stubs(:info).returns(info) helper.expects(:content_tag).with('th', f1).returns(f1) helper.expects(:content_tag).with('td', v1).returns(v1) @@ -42,7 +44,9 @@ class ProfileHelperTest < Test::Unit::TestCase def test_should_call_blocks myproc = lambda { content_tag('div', 'lalala') } - profile.stubs(:info).returns([['f1', myproc ]]) + info = mock + info.expects(:summary).returns([['f1', myproc ]]) + profile.stubs(:info).returns(info) helper.stubs(:content_tag).returns('') helper.expects(:instance_eval).with(myproc) -- libgit2 0.21.2