From: Jean-Philippe Lang Date: Sun, 7 Jan 2018 22:06:11 +0000 (+0000) Subject: Merged r17150 to 3.3-stable (#26699). X-Git-Tag: 3.3.6~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8f93f08e1c4a22d5ea8fe47271cd9d46b4112a8f;p=redmine.git Merged r17150 to 3.3-stable (#26699). git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@17152 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0c85598e0..6889ba231 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1278,7 +1278,13 @@ module ApplicationHelper elsif user.to_s =~ %r{<(.+?)>} email = $1 end - return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil + if email.present? + gravatar(email.to_s.downcase, options) rescue nil + else + image_tag 'anonymous.png', + GravatarHelper::DEFAULT_OPTIONS + .except(:default, :rating, :ssl).merge(options) + end else '' end diff --git a/public/images/anonymous.png b/public/images/anonymous.png new file mode 100644 index 000000000..5f00a8362 Binary files /dev/null and b/public/images/anonymous.png differ diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index c82922cd0..2285944af 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -1291,6 +1291,7 @@ RAW end def test_avatar_enabled + tag_for_anonymous_re = %r{src="/images/anonymous.png(\?\d+)?"} with_settings :gravatar_enabled => '1' do assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) assert avatar('jsmith ').include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) @@ -1302,8 +1303,10 @@ RAW # The default class of the img tag should be gravatar assert avatar('jsmith ').include?('class="gravatar"') assert !avatar('jsmith ', :class => 'picture').include?('class="gravatar"') - assert_nil avatar('jsmith') - assert_nil avatar(nil) + assert_match tag_for_anonymous_re, avatar('jsmith') + assert_match tag_for_anonymous_re, avatar(nil) + # Avatar for anonymous user + assert_match tag_for_anonymous_re, avatar(User.anonymous) end end