From: Jean-Philippe Lang Date: Sun, 8 Mar 2015 09:46:21 +0000 (+0000) Subject: Merged r14054 (#19225). X-Git-Tag: 3.0.1~20 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7879d8e4dcb4f2d2bb4e03499a72939c1848c016;p=redmine.git Merged r14054 (#19225). git-svn-id: http://svn.redmine.org/redmine/branches/3.0-stable@14064 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 3870a066d..8e951596c 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -320,15 +320,19 @@ module IssuesHelper end strings << show_detail(detail, no_html, options) end - values_by_field.each do |field, changes| - detail = JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s) - detail.instance_variable_set "@custom_field", field - if changes[:added].any? - detail.value = changes[:added] - strings << show_detail(detail, no_html, options) - elsif changes[:deleted].any? - detail.old_value = changes[:deleted] - strings << show_detail(detail, no_html, options) + if values_by_field.present? + multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value) + values_by_field.each do |field, changes| + if changes[:added].any? + detail = multiple_values_detail.new('cf', field.id.to_s, field) + detail.value = changes[:added] + strings << show_detail(detail, no_html, options) + end + if changes[:deleted].any? + detail = multiple_values_detail.new('cf', field.id.to_s, field) + detail.old_value = changes[:deleted] + strings << show_detail(detail, no_html, options) + end end end strings diff --git a/test/unit/helpers/issues_helper_test.rb b/test/unit/helpers/issues_helper_test.rb index b275e75db..7e9ec0e09 100644 --- a/test/unit/helpers/issues_helper_test.rb +++ b/test/unit/helpers/issues_helper_test.rb @@ -296,6 +296,43 @@ class IssuesHelperTest < ActionView::TestCase assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, false) end + def test_details_to_strings_with_multiple_values_removed_from_custom_field + field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true) + details = [] + details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '1', :value => nil) + details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '3', :value => nil) + + assert_equal ["User deleted (Dave Lopper, Redmine Admin)"], details_to_strings(details, true) + assert_equal ["User deleted (Dave Lopper, Redmine Admin)"], details_to_strings(details, false) + end + + def test_details_to_strings_with_multiple_values_added_to_custom_field + field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true) + details = [] + details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '1') + details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '3') + + assert_equal ["User Dave Lopper, Redmine Admin added"], details_to_strings(details, true) + assert_equal ["User Dave Lopper, Redmine Admin added"], details_to_strings(details, false) + end + + def test_details_to_strings_with_multiple_values_added_and_removed_from_custom_field + field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true) + details = [] + details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '1') + details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '2', :value => nil) + details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '3', :value => nil) + + assert_equal [ + "User Redmine Admin added", + "User deleted (Dave Lopper, John Smith)" + ], details_to_strings(details, true) + assert_equal [ + "User Redmine Admin added", + "User deleted (Dave Lopper, John Smith)" + ], details_to_strings(details, false) + end + def test_find_name_by_reflection_should_return_nil_for_missing_record assert_nil find_name_by_reflection('status', 99) end