diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 3ca7167af..9b1a47680 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -135,7 +135,7 @@ module ApplicationHelper
end
def person_image_tag(person, size=:thumb_small)
- "
".html_safe
+ "
".html_safe
end
def person_link(person)
@@ -144,13 +144,6 @@ module ApplicationHelper
".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
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 47d709e84..ea5e7c42a 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -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
diff --git a/app/views/publics/hcard.haml b/app/views/publics/hcard.haml
index f6e4c4408..ca0194e3d 100644
--- a/app/views/publics/hcard.haml
+++ b/app/views/publics/hcard.haml
@@ -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
diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb
index 9614f39ad..e32b63534 100644
--- a/spec/models/profile_spec.rb
+++ b/spec/models/profile_spec.rb
@@ -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)