Move image_url defaulting logic into profile
This commit is contained in:
parent
7be232e33e
commit
518642d0d7
4 changed files with 33 additions and 21 deletions
|
|
@ -135,7 +135,7 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def person_image_tag(person, size=:thumb_small)
|
||||
"<img alt=\"#{h(person.name)}\" class=\"avatar\" data-person_id=\"#{person.id}\" src=\"#{image_or_default(person, size)}\" title=\"#{h(person.name)}\">".html_safe
|
||||
"<img alt=\"#{h(person.name)}\" class=\"avatar\" data-person_id=\"#{person.id}\" src=\"#{person.profile.image_url(size)}\" title=\"#{h(person.name)}\">".html_safe
|
||||
end
|
||||
|
||||
def person_link(person)
|
||||
|
|
@ -144,13 +144,6 @@ module ApplicationHelper
|
|||
</a>".html_safe
|
||||
end
|
||||
|
||||
def image_or_default(person, size=:thumb_large)
|
||||
image_location = person.profile.image_url(size) if person.profile
|
||||
image_location ||= person.profile.image_url(:thumb_large) if person.profile #backwards compatability for old profile pictures
|
||||
image_location ||= "/images/user/default.png"
|
||||
image_location
|
||||
end
|
||||
|
||||
def hard_link(string, path)
|
||||
link_to string, path, :rel => 'external'
|
||||
end
|
||||
|
|
@ -277,7 +270,7 @@ module ApplicationHelper
|
|||
image_tag 'icons/monotone_question.png', :class => 'what_is_this', :title => text
|
||||
end
|
||||
|
||||
|
||||
|
||||
def get_javascript_strings_for(language)
|
||||
I18n.t('javascripts')
|
||||
end
|
||||
|
|
|
|||
|
|
@ -45,13 +45,14 @@ class Profile < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def image_url(size = :thumb_large)
|
||||
if size == :thumb_medium
|
||||
self[:image_url_medium]
|
||||
elsif size == :thumb_small
|
||||
self[:image_url_small]
|
||||
else
|
||||
self[:image_url]
|
||||
end
|
||||
result = if size == :thumb_medium && self[:image_url_medium]
|
||||
self[:image_url_medium]
|
||||
elsif size == :thumb_small && self[:image_url_small]
|
||||
self[:image_url_small]
|
||||
else
|
||||
self[:image_url]
|
||||
end
|
||||
result || '/images/user/default.png'
|
||||
end
|
||||
|
||||
def image_url= url
|
||||
|
|
|
|||
|
|
@ -32,18 +32,18 @@
|
|||
%dl.entity_photo
|
||||
%dt Photo
|
||||
%dd
|
||||
%img.photo.avatar{:src=>image_or_default(@person), :width=>'300px', :height=>'300px'}
|
||||
%img.photo.avatar{:src=>@person.profile.image_url, :width=>'300px', :height=>'300px'}
|
||||
|
||||
%dl.entity_photo_medium
|
||||
%dt Photo
|
||||
%dd
|
||||
%img.photo.avatar{:src=>image_or_default(@person, :thumb_medium), :width=>'100px', :height=>'100px'}
|
||||
|
||||
%img.photo.avatar{:src=>@person.profile.image_url(:thumb_medium), :width=>'100px', :height=>'100px'}
|
||||
|
||||
%dl.entity_photo_small
|
||||
%dt Photo
|
||||
%dd
|
||||
%img.photo.avatar{:src=>image_or_default(@person, :thumb_small), :width=>'50px', :height=>'50px'}
|
||||
|
||||
%img.photo.avatar{:src=>@person.profile.image_url(:thumb_small), :width=>'50px', :height=>'50px'}
|
||||
|
||||
%dl.entity_searchable
|
||||
%dt Searchable
|
||||
%dd
|
||||
|
|
|
|||
|
|
@ -69,6 +69,24 @@ describe Profile do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#image_url' do
|
||||
before do
|
||||
@profile = Factory.build(:profile)
|
||||
end
|
||||
it 'returns a default rather than nil' do
|
||||
@profile.image_url = nil
|
||||
@profile.image_url.should_not be_nil
|
||||
end
|
||||
it 'falls back to the large thumbnail if the small thumbnail is nil' do
|
||||
#Backwards compatibility
|
||||
@profile[:image_url] = 'large'
|
||||
@profile[:image_url_small] = nil
|
||||
@profile[:image_url_medium] = nil
|
||||
@profile.image_url(:thumb_small).should == 'large'
|
||||
@profile.image_url(:thumb_medium).should == 'large'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#subscribers' do
|
||||
it 'returns all non-pending contacts for a user' do
|
||||
user = Factory(:user)
|
||||
|
|
|
|||
Loading…
Reference in a new issue