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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add more specs and explanations
Dombi Attila17574acf9c80
diff --git a/app/models/journable/with_historic_attributes.rb b/app/models/journable/with_historic_attributes.rbindex 372de13f2e9..691cca44cf0 100644--- a/app/models/journable/with_historic_attributes.rb+++ b/app/models/journable/with_historic_attributes.rb@@ -233,12 +233,21 @@ class Journable::WithHistoricAttributes < SimpleDelegatorreturn unless historic_journablechanges = ::Acts::Journalized::JournableDiffer.changes(__getobj__, historic_journable)+ # In the other occurrences of JournableDiffer.association_changes calls, we are using the plural+ # of the association name (`custom_fields` in this instance), to map the association fields. That+ # will result in a changes hash containing { "custom_fields_1" => ... }. This makes sense in the case+ # of journal changes, because the formatted fields have the convention for plural lookup for journals+ # defined in the `register_journal_formatted_fields(:custom_field, /custom_fields_\d+/)`.+ # In this case the diff is part of the WorkPackageAtTimestampRepresenter where the `representable_map`+ # contains the singular names (`custom_field_1`), hence we need to map the diffs to match that format.+ # As a food for thought, I think it would be more handy to use the singular naming everywhere.+changes.merge!(::Acts::Journalized::JournableDiffer.association_changes(historic_journable,__getobj__,'custom_values',- 'custom_fields',+ 'custom_field',:custom_field_id,:value)diff --git a/spec/models/journable/with_historic_attributes_spec.rb b/spec/models/journable/with_historic_attributes_spec.rbindex d21f6532752..5f56db6d494 100644--- a/spec/models/journable/with_historic_attributes_spec.rb+++ b/spec/models/journable/with_historic_attributes_spec.rb@@ -635,6 +635,27 @@ RSpec.describe Journable::WithHistoricAttributes,expect(subject.changed_at_timestamp(Timestamp.parse("2022-01-01T00:00:00Z"))).to match_array ['subject']end++ context 'when the work package includes custom field changes' do+ let!(:custom_field) do+ create(:string_wp_custom_field,+ name: 'String CF',+ types: project.types,+ projects: [project])+ end++ let!(:custom_value) do+ create(:custom_value,+ custom_field:,+ customized: work_package1,+ value: 'This is a string value')+ end++ it 'returns the changed attributes including custom fields at the timestamp compared to the current attribute values' do+ expect(subject.changed_at_timestamp(Timestamp.parse("2022-01-01T00:00:00Z")))+ .to contain_exactly 'subject', "custom_field_#{custom_field.id}"+ end+ endendcontext 'for a timestamp where the work package did not exist' do