feature-30822.patch

Mizuki ISHIKAWA, 2019-03-20 06:11

Download (6.73 KB)

View differences:

app/helpers/application_helper.rb
1482 1482
  def avatar(user, options = { })
1483 1483
    if Setting.gravatar_enabled?
1484 1484
      options.merge!(:default => Setting.gravatar_default)
1485
      # style for HTML mail
1486
      if options.delete(:html_mail)
1487
        options[:style] = "#{options[:style]}width:14px;height:14px;border-radius:20%;vertical-align:middle;"
1488
      end
1485 1489
      email = nil
1486 1490
      if user.respond_to?(:mail)
1487 1491
        email = user.mail
app/helpers/issues_helper.rb
320 320
    %w(author status priority assigned_to category fixed_version start_date due_date).each do |attribute|
321 321
      if issue.disabled_core_fields.grep(/^#{attribute}(_id)?$/).empty?
322 322
        if html
323
          items << content_tag('strong', "#{l("field_#{attribute}")}: ") + (issue.send attribute)
323
          value = issue.send(attribute)
324
          if %w(author assigned_to).include?(attribute) && value.is_a?(User)
325
            value = "#{avatar(value, :title => l("field_#{attribute}"), :html_mail => true)}#{value}".html_safe
326
          end
327
          items << content_tag('strong', "#{l("field_#{attribute}")}: ") + value
324 328
        else
325 329
          items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
326 330
        end
app/views/mailer/issue_add.html.erb
1
<%= l(:text_issue_added, :id => link_to("##{@issue.id}", @issue_url), :author => h(@issue.author)).html_safe %>
1
<%= l(:text_issue_added,
2
      :id => link_to("##{@issue.id}", @issue_url),
3
      :author => "#{avatar(@issue.author, :html_mail => true)}#{h(@issue.author)}").html_safe %>
2 4
<hr />
3 5
<%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %>
app/views/mailer/issue_edit.html.erb
1 1
<% if @journal.private_notes? %>
2 2
  (<%= l(:field_private_notes) %>)
3 3
<% end %>
4
<%= l(:text_issue_updated, :id => link_to("##{@issue.id}", @issue_url), :author => h(@journal.user)).html_safe %>
4
<%= l(:text_issue_updated,
5
      :id => link_to("##{@issue.id}", @issue_url),
6
      :author => "#{avatar(@journal.user, :html_mail => true)}#{h(@journal.user)}").html_safe %>
5 7
<hr />
6 8

  
7 9
<ul class="journal details">
test/helpers/application_helper_test.rb
1505 1505
    end
1506 1506
  end
1507 1507

  
1508
  def test_avatar_with_html_mail_option
1509
    with_settings :gravatar_enabled => '1' do
1510
      avatar = avatar('jsmith <jsmith@somenet.foo>', :html_mail => true)
1511
      assert_include 'style="width:14px;height:14px;border-radius:20%;vertical-align:middle;"', avatar
1512
      assert_not_include 'html_mail', avatar
1513
    end
1514
  end
1515

  
1508 1516
  def test_avatar_disabled
1509 1517
    with_settings :gravatar_enabled => '0' do
1510 1518
      assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo'))
test/unit/mailer_test.rb
447 447
    end
448 448
  end
449 449

  
450
  def test_issue_add_should_include_gravatar_if_gravatar_enabled
451
    with_settings :gravatar_enabled => '1' do
452
      issue = Issue.find(2)
453
      Mailer.deliver_issue_add(issue)
454
      gravatar_url = 'https://www.gravatar.com/avatar/'
455
      option = '?rating=PG&size=50&default='
456
      author_gravatar_url = gravatar_url + Digest::MD5.hexdigest(issue.author.mail) + option
457
      assignee_gravatar_url = gravatar_url + Digest::MD5.hexdigest(issue.assigned_to.mail) + option
458

  
459
      assert_select_email do
460
        assert_select 'img[class=?]', 'gravatar', :count => 3
461
        assert_select 'img[class="gravatar"][title=?][src=?]', '', author_gravatar_url, :count => 1
462
        assert_select 'li img[class="gravatar"][title=?][src=?]', 'Author', author_gravatar_url, :count => 1
463
        assert_select 'li img[class="gravatar"][title=?][src=?]', 'Assignee', assignee_gravatar_url, :count => 1
464
      end
465
    end
466
  end
467

  
468
  def test_issue_add_should_include_gravatar_if_gravatar_disabled
469
    with_settings :gravatar_enabled => '0' do
470
      issue = Issue.find(2)
471
      Mailer.deliver_issue_add(issue)
472

  
473
      assert_select_email do
474
        assert_select 'img[class=?]', 'gravatar', :count => 0
475
      end
476
    end
477
  end
478

  
450 479
  def test_issue_edit_subject_should_include_status_changes_if_setting_is_enabled
451 480
    with_settings :show_status_changes_in_mail_subject => 1 do
452 481
      issue = Issue.find(2)
......
534 563
    end
535 564
  end
536 565

  
566
  def test_issue_edit_should_include_gravatar_if_gravatar_enabled
567
    with_settings :gravatar_enabled => '1' do
568
      journal = Journal.find(3)
569
      Mailer.deliver_issue_edit(journal)
570
      gravatar_url = 'https://www.gravatar.com/avatar/'
571
      option = '?rating=PG&size=50&default='
572
      reported_user_gravatar_url = gravatar_url + Digest::MD5.hexdigest(journal.user.mail) + option
573
      author_gravatar_url = gravatar_url + Digest::MD5.hexdigest(journal.issue.author.mail) + option
574
      assignee_gravatar_url = gravatar_url + Digest::MD5.hexdigest(journal.issue.assigned_to.mail) + option
575

  
576
      assert_select_email do
577
        assert_select 'img[class="gravatar"]', :count => 3
578
        assert_select 'img[class="gravatar"][title=?][src=?]', '', reported_user_gravatar_url, :count => 1
579
        assert_select 'li img[class="gravatar"][title=?][src=?]', 'Author', author_gravatar_url, :count => 1
580
        assert_select 'li img[class="gravatar"][title=?][src=?]', 'Assignee', assignee_gravatar_url, :count => 1
581
      end
582
    end
583
  end
584

  
585
  def test_issue_edit_should_include_gravatar_if_gravatar_disabled
586
    with_settings :gravatar_enabled => '0' do
587
      journal = Journal.find(3)
588
      Mailer.deliver_issue_edit(journal)
589

  
590
      assert_select_email do
591
        assert_select 'img[class="gravatar"]', :count => 0
592
      end
593
    end
594
  end
595

  
537 596
  def test_version_file_added
538 597
    attachements = [ Attachment.find_by_container_type('Version') ]
539 598
    assert Mailer.deliver_attachments_added(attachements)