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

refactor no_nil_to_empty_strings?

Ivan Kuchin00218189bb6f
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 031d518c61d..464ab7afbb1 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
@@ -33,7 +33,7 @@ module Acts::Journalized
original_data = original ? normalize_newlines(journaled_attributes(original)) : {}
normalize_newlines(journaled_attributes(changed))
- .select { |attribute, new_value| no_nil_to_empty_strings?(original_data, attribute, new_value) }
+ .reject { |attribute, new_value| equal_ignoring_empty_string?(original_data[attribute], new_value) }
.to_h { |attribute, new_value| [attribute, [original_data[attribute], new_value]] }
.with_indifferent_access
end
@@ -66,9 +66,12 @@ module Acts::Journalized
end
end
- 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] - ["", nil]).present?
+ def equal_ignoring_empty_string?(old_value, new_value)
+ ignoring_empty_string(old_value) == ignoring_empty_string(new_value)
+ end
+
+ def ignoring_empty_string(value)
+ value unless value == ""
end
def journaled_attributes(object)