Fix paul.elicker link, refactor people_helper

This commit is contained in:
Raphael Sofaer 2011-08-11 16:25:58 -07:00
parent f0924b8e36
commit 7f69714d08
2 changed files with 40 additions and 17 deletions

View file

@ -27,18 +27,14 @@ module PeopleHelper
I18n.l bday, :format => I18n.t('date.formats.birthday_with_year')
end
end
def person_link(person, opts={})
opts[:class] ||= ""
opts[:class] << " self" if defined?(user_signed_in?) && user_signed_in? && current_user.person == person
remote_or_hovercard_link = "/people/#{person.id}".html_safe
if person.local?
"<a data-hovercard='#{remote_or_hovercard_link}' href='/u/#{person.diaspora_handle.split('@')[0]}' class='#{opts[:class]}'>#{h(person.name)}</a>".html_safe
else
"<a href='#{remote_or_hovercard_link}' data-hovercard='#{remote_or_hovercard_link}' class='#{opts[:class]}' >#{h(person.name)}</a>".html_safe
end
"<a data-hovercard='#{remote_or_hovercard_link}' #{person_href(person)} class='#{opts[:class]}'>#{h(person.name)}</a>".html_safe
end
def person_image_tag(person, size=nil)
size ||= :thumb_small
"<img alt=\"#{h(person.name)}\" class=\"avatar\" data-person_id=\"#{person.id}\" src=\"#{person.profile.image_url(size)}\" title=\"#{h(person.name)} (#{h(person.diaspora_handle)})\">".html_safe
@ -49,16 +45,20 @@ module PeopleHelper
if opts[:to] == :photos
link_to person_image_tag(person, opts[:size]), person_photos_path(person)
else
if person.local?
"<a href='/u/#{person.diaspora_handle.split('@')[0]}' class='#{opts[:class]}'>
#{person_image_tag(person, opts[:size])}
</a>".html_safe
else
"<a href='/people/#{person.id}'>
#{person_image_tag(person, opts[:size])}
</a>".html_safe
end
"<a #{person_href(person)} class='#{opts[:class]}'>
#{person_image_tag(person, opts[:size])}
</a>".html_safe
end
end
def person_href(person)
if person.local?
username = person.diaspora_handle.split('@')[0]
unless username.include?('.')
return "href='/u/#{person.diaspora_handle.split('@')[0]}'"
end
end
return "href='/people/#{person.id}'"
end
end

View file

@ -58,6 +58,29 @@ describe PeopleHelper do
person_link(@person).should_not include("<h1>")
end
end
describe '#person_href' do
before do
@user = Factory(:user)
end
it "links by id if there is a period in the user's username" do
@user.username = "invalid.username"
@user.save(:validate => false).should == true
person = @user.person
person.diaspora_handle = "#{@user.username}@#{AppConfig[:pod_uri].authority}"
person.save!
person_href(@user.person).should include("href='/people/#{@user.person.id}'")
end
it 'links by username for a local user' do
person_href(@user.person).should include(@user.username)
end
it 'links by id for a remote person' do
person = Factory(:person)
person_href(person).should include("/people/#{person.id}")
end
end
end