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

baseline api: use `Journable::WithHistoricAttributes include_only_changed_attributes: true` for api requests

Sebastian Fiedlschusterd426ee12a036
diff --git a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb b/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
index c008259c698..a350b1f0688 100644
--- a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
+++ b/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
@@ -51,7 +51,8 @@ module API::V3::WorkPackages::EagerLoading
def work_packages_with_historic_attributes
@work_packages_with_historic_attributes ||= begin
@timestamps ||= @query.try(:timestamps) || []
- Journable::WithHistoricAttributes.wrap_multiple(work_packages, timestamps: @timestamps, query: @query)
+ Journable::WithHistoricAttributes \
+ .wrap_multiple(work_packages, timestamps: @timestamps, query: @query, include_only_changed_attributes: true)
end
end
end
diff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
index 45ce3bf9008..85fc820472b 100644
--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
@@ -1379,13 +1379,17 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
expect(JSON.parse(subject)['_embedded']['attributesByTimestamp'].keys).to eq timestamps.map(&:to_s)
end
- it 'has the historic attributes for each timestamp' do
+ it 'has the historic attributes for each timestamp when they differ from the current attributes' do
expect(subject)
.to be_json_eql('The original work package'.to_json)
.at_path("_embedded/attributesByTimestamp/#{timestamps[0]}/subject")
+ end
+
+ it 'skips the historic attributes when they are the same as the current attributes' do
+ expect(subject)
+ .to have_json_path("_embedded/attributesByTimestamp/#{timestamps[1]}")
expect(subject)
- .to be_json_eql('The current work package'.to_json)
- .at_path("_embedded/attributesByTimestamp/#{timestamps[1]}/subject")
+ .not_to have_json_path("_embedded/attributesByTimestamp/#{timestamps[1]}/subject")
end
it 'has a link to the work package at the timestamp' do
diff --git a/spec/requests/api/v3/work_packages/show_resource_spec.rb b/spec/requests/api/v3/work_packages/show_resource_spec.rb
index 8abe6edd0db..41d1f0de6b8 100644
--- a/spec/requests/api/v3/work_packages/show_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/show_resource_spec.rb
@@ -266,13 +266,24 @@ describe 'API v3 Work package resource',
.at_path('_embedded/baselineAttributes/subject')
end
+ it 'does not embed the attributes in baselineAttributes if they are the same as the current attributes' do
+ expect(subject)
+ .not_to have_json_path('_embedded/baselineAttributes/description')
+ end
+
it 'embeds the attributesByTimestamp' do
expect(subject)
.to be_json_eql("The original work package".to_json)
.at_path("_embedded/attributesByTimestamp/#{timestamps.first}/subject")
expect(subject)
- .to be_json_eql("The current work package".to_json)
- .at_path("_embedded/attributesByTimestamp/#{timestamps.last}/subject")
+ .to have_json_path("_embedded/attributesByTimestamp/#{timestamps.last}")
+ end
+
+ it 'does not embed the attributes in attributesByTimestamp if they are the same as the current attributes' do
+ expect(subject)
+ .not_to have_json_path("_embedded/attributesByTimestamp/#{timestamps.first}/description")
+ expect(subject)
+ .not_to have_json_path("_embedded/attributesByTimestamp/#{timestamps.last}/description")
end
it 'has the current attributes as attributes' do