]> source.dussan.org Git - redmine.git/commitdiff
Merged r17150 to 3.4-stable (#26699).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 7 Jan 2018 22:05:47 +0000 (22:05 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 7 Jan 2018 22:05:47 +0000 (22:05 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.4-stable@17151 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
public/images/anonymous.png [new file with mode: 0644]
test/unit/helpers/application_helper_test.rb

index efe8882b929d4ac2553f69b5094b64a9a9e67a67..c5d4c76a7def938220ed3336f141d06b682a5010 100644 (file)
@@ -1421,7 +1421,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 (file)
index 0000000..5f00a83
Binary files /dev/null and b/public/images/anonymous.png differ
index 3bb018be1707aa1b1b635ce91f00cce1c0279123..941ba7ef05190ba01414f6d89734fae394ba686d 100644 (file)
@@ -1328,6 +1328,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 <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
@@ -1339,8 +1340,10 @@ RAW
       # The default class of the img tag should be gravatar
       assert avatar('jsmith <jsmith@somenet.foo>').include?('class="gravatar"')
       assert !avatar('jsmith <jsmith@somenet.foo>', :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