From cd67243de5f7a535c84ab3a22304db217e8364fa Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 10 Sep 2013 16:43:54 +0000 Subject: [PATCH] Merged r12079 from trunk (#14584). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.3-stable@12123 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..b75cbd5de 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, user) + 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.visible_custom_field_values(user).each do |value| + items << "#{value.custom_field.name}: #{show_value(value)}" + end + items + end + + def render_email_issue_attributes(issue, user, html=false) + items = email_issue_attributes(issue, user) + 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..e2e2bfc30 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, users.first, 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..dcca07e01 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, users.first) %> ---------------------------------------- <%= 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