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 JournableDiffer#get_association_changes

Dombi Attilabfb26bbcf0f8
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 e8ad2291e97..0d4571229df 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
@@ -81,18 +81,10 @@ module Acts::Journalized
end
def get_association_changes(original, changed, association, association_name, key, value)
- if original.nil?
- changed.send(association).each_with_object({}) do |associated_journal, h|
- changed_attribute = "#{association_name}_#{associated_journal.send(key)}"
- new_value = associated_journal.send(value)
- h[changed_attribute] = [nil, new_value]
- end
- else
- new_journals = changed.send(association).map(&:attributes)
- old_journals = original.send(association).map(&:attributes)
+ new_journals = changed.send(association).map(&:attributes)
+ old_journals = original ? original.send(association).map(&:attributes) : [];
- changes_on_association(new_journals, old_journals, association_name, key, value)
- end
+ changes_on_association(new_journals, old_journals, association_name, key, value)
end
def changes_on_association(current, original, association_name, key, value)