From e7c82e393442c775270754bb39c68857d8761613 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 10 Sep 2013 17:08:53 +0000 Subject: [PATCH] Backported r12079 from trunk (#14584). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.3-stable@12125 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/issues_helper.rb | 22 ++++++++++++++++++++++ app/views/mailer/_issue.html.erb | 12 +----------- app/views/mailer/_issue.text.erb | 9 +-------- test/unit/mailer_test.rb | 23 +++++++++++++++++++++++ 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index b4b15a66e..6bfd9adea 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -214,6 +214,28 @@ module IssuesHelper out end + def email_issue_attributes(issue) + items = [] + %w(author status priority assigned_to category fixed_version).each do |attribute| + unless issue.disabled_core_fields.include?(attribute+"_id") + items << "#{l("field_#{attribute}")}: #{issue.send attribute}" + end + end + issue.custom_field_values.each do |value| + items << "#{value.custom_field.name}: #{show_value(value)}" + end + items + end + + def render_email_issue_attributes(issue, html=false) + items = email_issue_attributes(issue) + if html + content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe) + else + items.map{|s| "* #{s}"}.join("\n") + end + end + # Returns the textual representation of a journal details # as an array of strings def details_to_strings(details, no_html=false, options={}) diff --git a/app/views/mailer/_issue.html.erb b/app/views/mailer/_issue.html.erb index 3d851d442..18cd72d56 100644 --- a/app/views/mailer/_issue.html.erb +++ b/app/views/mailer/_issue.html.erb @@ -1,15 +1,5 @@

<%= link_to(h("#{issue.tracker.name} ##{issue.id}: #{issue.subject}"), issue_url) %>

- +<%= render_email_issue_attributes(issue, true) %> <%= textilizable(issue, :description, :only_path => false) %> diff --git a/app/views/mailer/_issue.text.erb b/app/views/mailer/_issue.text.erb index 427b6a890..392d7c497 100644 --- a/app/views/mailer/_issue.text.erb +++ b/app/views/mailer/_issue.text.erb @@ -1,13 +1,6 @@ <%= "#{issue.tracker.name} ##{issue.id}: #{issue.subject}" %> <%= issue_url %> -* <%=l(:field_author)%>: <%= issue.author %> -* <%=l(:field_status)%>: <%= issue.status %> -* <%=l(:field_priority)%>: <%= issue.priority %> -* <%=l(:field_assigned_to)%>: <%= issue.assigned_to %> -* <%=l(:field_category)%>: <%= issue.category %> -* <%=l(:field_fixed_version)%>: <%= issue.fixed_version %> -<% issue.custom_field_values.each do |c| %>* <%= c.custom_field.name %>: <%= show_value(c) %> -<% end -%> +<%= render_email_issue_attributes(issue) %> ---------------------------------------- <%= issue.description %> diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 3fb9b701f..e65ee20fb 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -315,6 +315,29 @@ class MailerTest < ActiveSupport::TestCase assert !last_email.bcc.include?(user.mail) end + def test_issue_add_should_include_enabled_fields + Setting.default_language = 'en' + issue = Issue.find(2) + assert Mailer.deliver_issue_add(issue) + assert_mail_body_match '* Target version: 1.0', last_email + assert_select_email do + assert_select 'li', :text => 'Target version: 1.0' + end + end + + def test_issue_add_should_not_include_disabled_fields + Setting.default_language = 'en' + issue = Issue.find(2) + tracker = issue.tracker + tracker.core_fields -= ['fixed_version_id'] + tracker.save! + assert Mailer.deliver_issue_add(issue) + assert_mail_body_no_match 'Target version', last_email + assert_select_email do + assert_select 'li', :text => /Target version/, :count => 0 + end + end + # test mailer methods for each language def test_issue_add issue = Issue.find(1) -- 2.39.5