From: Jean-Philippe Lang Date: Sat, 2 Jul 2011 17:29:54 +0000 (+0000) Subject: Merged r6147 and r6149 from trunk. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=8e87cd6f772a29bb854d9a0785741338dfc78382;hp=65bee7efa3dc1d69d6c14330d2462e9856c346b8;p=redminele%2Fredmine.git Merged r6147 and r6149 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.2-stable@6160 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/issue.rb b/app/models/issue.rb index ea18e03e..79c49154 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -227,6 +227,13 @@ class Issue < ActiveRecord::Base @custom_field_values = nil result end + + def description=(arg) + if arg.is_a?(String) + arg = arg.gsub(/(\r\n|\n|\r)/, "\r\n") + end + write_attribute(:description, arg) + end # Overrides attributes= so that tracker_id gets assigned first def attributes_with_tracker_first=(new_attributes, *args) @@ -870,10 +877,13 @@ class Issue < ActiveRecord::Base if @current_journal # attributes changes (Issue.column_names - %w(id root_id lft rgt lock_version created_on updated_on)).each {|c| + before = @issue_before_change.send(c) + after = send(c) + next if before == after || (before.blank? && after.blank?) @current_journal.details << JournalDetail.new(:property => 'attr', :prop_key => c, :old_value => @issue_before_change.send(c), - :value => send(c)) unless send(c)==@issue_before_change.send(c) + :value => send(c)) } # custom fields changes custom_values.each {|c| diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index eee84ce2..b19ddaa8 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -733,6 +733,27 @@ class IssueTest < ActiveSupport::TestCase assert_equal old_description, detail.old_value assert_equal new_description, detail.value end + + def test_blank_descriptions_should_not_be_journalized + IssueCustomField.delete_all + Issue.update_all("description = NULL", "id=1") + + i = Issue.find(1) + i.init_journal(User.find(2)) + i.subject = "blank description" + i.description = "\r\n" + + assert_difference 'Journal.count', 1 do + assert_difference 'JournalDetail.count', 1 do + i.save! + end + end + end + + def test_description_eol_should_be_normalized + i = Issue.new(:description => "CR \r LF \n CRLF \r\n") + assert_equal "CR \r\n LF \r\n CRLF \r\n", i.description + end def test_saving_twice_should_not_duplicate_journal_details i = Issue.find(:first)