Project

General

Profile

Defect #26699 » 0001-Add-avatar-for-anonymous-user.patch

patch - Go MAEDA, 2017-08-15 17:52

View differences:

app/helpers/application_helper.rb
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
test/helpers/application_helper_test.rb
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'))
......
# 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
(6-6/6)