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 timestamp custom field specs to index_resource_spec
Dombi Attila4719162a62f7
diff --git a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb b/lib/api/v3/work_packages/eager_loading/historic_attributes.rbindex fa69281a1b4..9319505786b 100644--- a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb+++ b/lib/api/v3/work_packages/eager_loading/historic_attributes.rb@@ -164,7 +164,9 @@ module API::V3::WorkPackages::EagerLoading# Journal::CustomizableJournal objects and they are being dubbed as custom values.# The custom_values contain only the historic Journal::CustomizableJournal objects# that were available on the WorkPackage at the timestamp we are looking at.- custom_values.map(&:custom_field)+ # The intersection is made with the super to filter out any historic custom fields that+ # are not activated for the work package.+ @available_custom_fields ||= super.intersection(custom_values.map(&:custom_field))endendenddiff --git a/spec/requests/api/v3/work_packages/index_resource_spec.rb b/spec/requests/api/v3/work_packages/index_resource_spec.rbindex ba1ae3717ad..9714050ed6f 100644--- a/spec/requests/api/v3/work_packages/index_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/index_resource_spec.rb@@ -258,6 +258,21 @@ RSpec.describe 'API v3 Work package resource',new_work_package.update_columns(created_at:)new_work_packageend++ 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_package,+ value: 'This the current value')+ end+let(:original_journal) docreate_journal(journable: work_package, timestamp: created_at,version: 1,@@ -283,6 +298,13 @@ RSpec.describe 'API v3 Work package resource',data: build(:journal_work_package_journal, journal_attributes))end+ def create_customizable_journal(journal:, custom_field:, value:)+ create(:journal_customizable_journal,+ journal:,+ custom_field:,+ value:)+ end+before dowork_package.journals.destroy_alloriginal_journal@@ -301,6 +323,40 @@ RSpec.describe 'API v3 Work package resource',.to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1")end+ context 'when the custom fields are changed' do+ before do+ custom_field+ custom_value+ create_customizable_journal(journal: original_journal, custom_field:, value: 'Original value')+ end++ it 'embeds the custom fields in the attributesByTimestamp' do+ expect(subject.body)+ .to be_json_eql('Original value'.to_json)+ .at_path("_embedded/elements/0/_embedded/attributesByTimestamp/0/customField#{custom_field.id}")+ expect(subject.body)+ .to be_json_eql('This the current value'.to_json)+ .at_path("_embedded/elements/0/customField#{custom_field.id}")+ expect(subject.body)+ .to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1")+ end++ context 'and the custom field is deactivated in the meantime' do+ before do+ custom_field.destroy+ end++ it 'does not embeds the custom fields in the attributesByTimestamp' do+ expect(subject.body)+ .not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/0/customField#{custom_field.id}")+ expect(subject.body)+ .to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/0")+ expect(subject.body)+ .to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1")+ end+ end+ end+it 'does not embed the attributes in attributesByTimestamp if they are the same as the current attributes' doexpect(subject.body).not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1/description")@@ -641,6 +697,27 @@ RSpec.describe 'API v3 Work package resource',.not_to have_json_path('_embedded/elements/0/_embedded/attributesByTimestamp/1/subject')end+ context 'when the custom fields are not changed' do+ before do+ custom_field+ custom_value+ end++ it 'has no attributes in the embedded objects because they are the same as in the main object' do+ expect(subject.body)+ .to have_json_path('_embedded/elements/0/_embedded/attributesByTimestamp/0')+ expect(subject.body)+ .not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/0/customField#{custom_field.id}")+ expect(subject.body)+ .to have_json_path('_embedded/elements/0/_embedded/attributesByTimestamp/1')+ expect(subject.body)+ .not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1/customField#{custom_field.id}")+ expect(subject.body)+ .to be_json_eql('This the current value'.to_json)+ .at_path("_embedded/elements/0/customField#{custom_field.id}")+ end+ end+describe "_meta" dodescribe "matchesFilters" doit 'marks the work package as matching the filters today' do