0001-Add-avatar-for-anonymous-user.patch

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

Download (3.91 KB)

View differences:

app/helpers/application_helper.rb
1404 1404
      elsif user.to_s =~ %r{<(.+?)>}
1405 1405
        email = $1
1406 1406
      end
1407
      return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
1407
      if email.present?
1408
        gravatar(email.to_s.downcase, options) rescue nil
1409
      else
1410
        image_tag 'anonymous.png',
1411
                  GravatarHelper::DEFAULT_OPTIONS
1412
                    .except(:default, :rating, :ssl).merge(options)
1413
      end
1408 1414
    else
1409 1415
      ''
1410 1416
    end
test/helpers/application_helper_test.rb
1302 1302
  end
1303 1303

  
1304 1304
  def test_avatar_enabled
1305
    tag_for_anonymous_re = %r{src="/images/anonymous.png(\?\d+)?"}
1305 1306
    with_settings :gravatar_enabled => '1' do
1306 1307
      assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
1307 1308
      assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
......
1313 1314
      # The default class of the img tag should be gravatar
1314 1315
      assert avatar('jsmith <jsmith@somenet.foo>').include?('class="gravatar"')
1315 1316
      assert !avatar('jsmith <jsmith@somenet.foo>', :class => 'picture').include?('class="gravatar"')
1316
      assert_nil avatar('jsmith')
1317
      assert_nil avatar(nil)
1317
      assert_match tag_for_anonymous_re, avatar('jsmith')
1318
      assert_match tag_for_anonymous_re, avatar(nil)
1319
      # Avatar for anonymous user
1320
      assert_match tag_for_anonymous_re, avatar(User.anonymous)
1318 1321
    end
1319 1322
  end
1320 1323

  
1321
-