]> source.dussan.org Git - redmine.git/commitdiff
Anonymous user should have their icon (#26699).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 7 Jan 2018 22:01:56 +0000 (22:01 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 7 Jan 2018 22:01:56 +0000 (22:01 +0000)
Patch by Go MAEDA.

git-svn-id: http://svn.redmine.org/redmine/trunk@17150 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index ef229f955388fc1786ea5266810165313e259c3f..a70add6f815c03bb68f5fc2940d3394d4ffebb27 100644 (file)
@@ -1405,7 +1405,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 6a461c31a1ffb1b5ef801443c0e1caf8749be5c2..936a0ba84f27f0c326781c2b26b1adbff96f10aa 100644 (file)
@@ -1302,6 +1302,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'))
@@ -1313,8 +1314,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