diff --git a/app/models/work_package_types/patterns/token_property_mapper.rb b/app/models/work_package_types/patterns/token_property_mapper.rb index b594bd3fadb0..00b369dc37fd 100644 --- a/app/models/work_package_types/patterns/token_property_mapper.rb +++ b/app/models/work_package_types/patterns/token_property_mapper.rb @@ -64,7 +64,7 @@ def attribute(key, label_fn, value_fn, formatter = STRING_OR_NIL) attribute(:parent_subject, -> { WorkPackage.human_attribute_name(:subject) }, ->(parent) { parent.subject }), attribute(:parent_status, -> { WorkPackage.human_attribute_name(:status) }, ->(parent) { parent.status }), attribute(:parent_type, -> { WorkPackage.human_attribute_name(:type) }, ->(parent) { parent.type }), - attribute(:parent_version, -> { WorkPackage.human_attribute_name(:version) }, ->(parent) { parent.version }), + attribute(:parent_version, -> { Setting::WorkPackageMultipleVersions.active? ? WorkPackage.human_attribute_name(:target_versions) : WorkPackage.human_attribute_name(:version) }, ->(parent) { parent.target_versions }, ARRAY), attribute(:priority, -> { WorkPackage.human_attribute_name(:priority) }, ->(wp) { wp.priority }), attribute(:project_id, -> { Project.human_attribute_name(:id) }, ->(project) { project.id }), attribute(:project_active, -> { Project.human_attribute_name(:active) }, ->(project) { project.active? }), @@ -75,7 +75,7 @@ def attribute(key, label_fn, value_fn, formatter = STRING_OR_NIL) attribute(:start_date, -> { WorkPackage.human_attribute_name(:start_date) }, ->(wp) { wp.start_date }, DATE), attribute(:status, -> { WorkPackage.human_attribute_name(:status) }, ->(wp) { wp.status }), attribute(:type, -> { WorkPackage.human_attribute_name(:type) }, ->(wp) { wp.type }), - attribute(:version, -> { WorkPackage.human_attribute_name(:version) }, ->(wp) { wp.version }) + attribute(:version, -> { Setting::WorkPackageMultipleVersions.active? ? WorkPackage.human_attribute_name(:target_versions) : WorkPackage.human_attribute_name(:version) }, ->(wp) { wp.target_versions }, ARRAY) ].freeze # rubocop:enable Layout/LineLength diff --git a/spec/models/work_package_types/patterns/token_property_mapper_spec.rb b/spec/models/work_package_types/patterns/token_property_mapper_spec.rb index 0bc6e46b51b4..a59cf94834f5 100644 --- a/spec/models/work_package_types/patterns/token_property_mapper_spec.rb +++ b/spec/models/work_package_types/patterns/token_property_mapper_spec.rb @@ -201,6 +201,38 @@ expect(token.call(sub_work_package)).to eq("Task") end end + + context "for versions" do + shared_let(:second_version) { create(:version, project:) } + + before do + create(:work_package_version, work_package:, version: second_version, kind: :target) + end + + context "when work package multiple versions is active", + with_flag: { work_package_multiple_versions: true }, + with_settings: { work_package_multiple_versions: true } do + it "renders an array of values" do + enabled, = subject + token = detect(enabled, :version) + + expect(token.call(work_package)).to eq("#{version.name}, #{second_version.name}") + end + + it "label is target versions" do + enabled, = subject + expect(detect(enabled, :version)&.label).to eq("Target versions") + end + end + + context "when work package multiple versions is not active", + with_settings: { work_package_multiple_versions: false } do + it "label is version" do + enabled, = subject + expect(detect(enabled, :version)&.label).to eq("Version") + end + end + end end private