diff --git a/app/helpers/avatars_helper.rb b/app/helpers/avatars_helper.rb index 67567fd8d..6aa92b1cf 100644 --- a/app/helpers/avatars_helper.rb +++ b/app/helpers/avatars_helper.rb @@ -37,7 +37,14 @@ module AvatarsHelper # Returns the avatar image tag for the given +user+ if avatars are enabled # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe ') def avatar(user, options = {}) - if Setting.gravatar_enabled? + # "avatar" class should be added to all avatars + options[:class] = ['avatar', options[:class]].compact.join(' ') + + if user.is_a?(AnonymousUser) + anonymous_avatar(options) + elsif user.is_a?(Group) + group_avatar(options) + elsif Setting.gravatar_enabled? gravatar_avatar_tag(user, options) elsif user.respond_to?(:initials) initials_avatar_tag(user, options) @@ -77,17 +84,13 @@ module AvatarsHelper if email.present? gravatar(email.to_s.downcase, options) rescue nil - elsif user.is_a?(AnonymousUser) - anonymous_avatar(options) - elsif user.is_a?(Group) - group_avatar(options) end end def initials_avatar_tag(user, options) size = (options.delete(:size) || GravatarHelper::DEFAULT_OPTIONS[:size]).to_i - css_class = ["avatar-color-#{user.id % 8}", 'avatar', "s#{size}", options[:class]].compact.join(' ') + css_class = ["avatar-color-#{user.id % 8}", "s#{size}", options[:class]].compact.join(' ') content_tag('span', user.initials, role: 'img', class: css_class, title: options[:title]) end diff --git a/lib/plugins/gravatar/lib/gravatar.rb b/lib/plugins/gravatar/lib/gravatar.rb index 43820008f..316a01b19 100644 --- a/lib/plugins/gravatar/lib/gravatar.rb +++ b/lib/plugins/gravatar/lib/gravatar.rb @@ -32,7 +32,7 @@ module GravatarHelper :title => '', # The class to assign to the img tag for the gravatar. - :class => 'gravatar avatar', + :class => 'gravatar', } # The methods that will be made available to your views. diff --git a/test/helpers/avatars_helper_test.rb b/test/helpers/avatars_helper_test.rb index 6b426bc98..dee529b69 100644 --- a/test/helpers/avatars_helper_test.rb +++ b/test/helpers/avatars_helper_test.rb @@ -82,7 +82,7 @@ class AvatarsHelperTest < Redmine::HelperTest def test_avatar_disabled_should_display_user_initials with_settings :gravatar_enabled => '0' do - assert_equal "JS", avatar(User.find_by_mail('jsmith@somenet.foo')) + assert_equal "JS", avatar(User.find_by_mail('jsmith@somenet.foo')) end end