Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Filter out the nil to empty string attribute changes in the JournableDiffer.

Dombi Attila953bdf0f2ddf
diff --git a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb
index 53b2e325b45..fbfe65915b8 100644
--- a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb
@@ -52,7 +52,7 @@ module Acts::Journalized
def no_nil_to_empty_strings?(normalized_old_data, attribute, new_value)
old_value = normalized_old_data[attribute]
- new_value != old_value
+ new_value != old_value && ([new_value, old_value] - ['', nil]).present?
end
def journaled_attributes(object)
diff --git a/spec/lib/acts_as_journalized/journable_differ_spec.rb b/spec/lib/acts_as_journalized/journable_differ_spec.rb
index 1d513d407e0..8f84fd58738 100644
--- a/spec/lib/acts_as_journalized/journable_differ_spec.rb
+++ b/spec/lib/acts_as_journalized/journable_differ_spec.rb
@@ -57,9 +57,9 @@ RSpec.describe Acts::Journalized::JournableDiffer do
.to eql("subject" => [original.subject, changed.subject],
"author_id" => [original.author_id, changed.author_id],
"status_id" => [original.status_id, changed.status_id],
- "schedule_manually" => [original.schedule_manually, nil],
- "ignore_non_working_days" => [original.ignore_non_working_days, changed.ignore_non_working_days],
- "estimated_hours" => [original.estimated_hours, nil])
+ "schedule_manually" => [false, nil],
+ "ignore_non_working_days" => [true, false],
+ "estimated_hours" => [1.0, nil])
end
end
@@ -67,7 +67,7 @@ RSpec.describe Acts::Journalized::JournableDiffer do
let(:original) do
build_stubbed(:journal_work_package_journal,
subject: 'The original work package title',
- description: "The description\n",
+ description: nil,
priority_id: 5,
type_id: 89,
project_id: 12,
@@ -79,7 +79,7 @@ RSpec.describe Acts::Journalized::JournableDiffer do
let(:changed) do
build_stubbed(:journal_work_package_journal,
subject: 'The changed work package title',
- description: "The description\r\n",
+ description: '',
priority_id: original.priority_id,
type_id: original.type_id,
project_id: original.project_id,
@@ -90,12 +90,14 @@ RSpec.describe Acts::Journalized::JournableDiffer do
end
it 'returns the changes' do
+ # The description field changes from nil to '', but we want filter those transitions out,
+ # hence the expected hash does not contain the description related change.
expect(described_class.changes(original, changed))
.to eql("subject" => [original.subject, changed.subject],
"status_id" => [original.status_id, changed.status_id],
- "schedule_manually" => [nil, changed.schedule_manually],
- "ignore_non_working_days" => [original.ignore_non_working_days, changed.ignore_non_working_days],
- "estimated_hours" => [original.estimated_hours, nil])
+ "schedule_manually" => [nil, false],
+ "ignore_non_working_days" => [false, true],
+ "estimated_hours" => [1.0, nil])
end
end
end