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 multiple option for project custom fields (#9125)
Oliver Güntherac049663a318
diff --git a/app/cells/projects/row_cell.rb b/app/cells/projects/row_cell.rbindex 2a19b7a7ab1..0e16982fcc5 100644--- a/app/cells/projects/row_cell.rb+++ b/app/cells/projects/row_cell.rb@@ -28,10 +28,12 @@ module Projectsdef custom_field_column(column)cf = custom_field(column)- custom_value = project.custom_value_for(cf).formatted_value+ custom_value = project.formatted_custom_value_for(cf)if cf.field_format == 'text'custom_value.html_safe+ elsif custom_value.is_a?(Array)+ safe_join(Array(custom_value).compact_blank, ', ')elsecustom_valueenddiff --git a/app/models/custom_field.rb b/app/models/custom_field.rbindex 067ec3b75c0..1ae182ef6cd 100644--- a/app/models/custom_field.rb+++ b/app/models/custom_field.rb@@ -254,6 +254,10 @@ class CustomField < ApplicationRecordfield_format == "text"end+ def boolean?+ field_format == "bool"+ end+def multi_value?multi_valueenddiff --git a/app/models/custom_value.rb b/app/models/custom_value.rbindex f75b15354a4..a74050ec752 100644--- a/app/models/custom_value.rb+++ b/app/models/custom_value.rb@@ -58,6 +58,13 @@ class CustomValue < ApplicationRecordsuper(parsed_value)end+ def strategy+ @strategy ||= begin+ format = custom_field&.field_format || 'empty'+ OpenProject::CustomFieldFormat.find_by_name(format).formatter.new(self)+ end+ end+protecteddef validate_presence_of_required_value@@ -98,11 +105,4 @@ class CustomValue < ApplicationRecorddef validate_max_length_of_valueerrors.add(:value, :too_long, count: max_length) if max_length > 0 && value.length > max_lengthend-- def strategy- @strategy ||= begin- format = custom_field&.field_format || 'empty'- OpenProject::CustomFieldFormat.find_by_name(format).formatter.new(self)- end- endenddiff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rbindex 6ff7bfda1bd..397d8123b26 100644--- a/app/models/permitted_params.rb+++ b/app/models/permitted_params.rb@@ -389,7 +389,9 @@ class PermittedParams# only permit values following the schema# 'id as string' => 'value as string'- values.reject! { |k, v| k.to_i < 1 || !v.is_a?(String) }+ values.select! { |k, v| k.to_i > 0 && (v.is_a?(String) || v.is_a?(Array)) }+ # Reject blank values from include_hidden select fields+ values.each { |_, v| v.compact_blank! if v.is_a?(Array) }values.empty? ? {} : { 'custom_field_values' => values.permit! }enddiff --git a/app/views/account/_register.html.erb b/app/views/account/_register.html.erbindex ff5a29a100a..f73df2a1d0b 100644--- a/app/views/account/_register.html.erb+++ b/app/views/account/_register.html.erb@@ -76,12 +76,8 @@ See docs/COPYRIGHT.rdoc for more details.<%= call_hook :view_account_register_after_basic_information, f: f %>- <%= render partial: 'customizable/field',- collection: @user.custom_field_values.select { |v|- v.editable? || v.required?- },- as: :value,- locals: { form: f, wide_labels: true } %>+ <%= render partial: "customizable/form",+ locals: { form: f, all_fields: false, only_required: true, wide_labels: true } %><br/><br/><% if @user.change_password_allowed? %>diff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erbindex 469f5619a93..37ab0420cb8 100644--- a/app/views/custom_fields/_form.html.erb+++ b/app/views/custom_fields/_form.html.erb@@ -60,8 +60,8 @@ See docs/COPYRIGHT.rdoc for more details.</span></div>- <% if @custom_field.class.name == 'WorkPackageCustomField' %>- <div class="form--field" id="custom_field_multi_select">+ <% if @custom_field.new_record? || @custom_field.field_format == 'list' %>+ <div class="form--field" id="custom_field_multi_select" style="display:none"><% if EnterpriseToken.allows_to?(:multiselect_custom_fields) %><%= f.check_box :multi_value %><% else %>@@ -74,9 +74,7 @@ See docs/COPYRIGHT.rdoc for more details.</span><% end %></div>- <% end %>- <% if @custom_field.new_record? || @custom_field.field_format == 'list' %><fieldset class="form--fieldset" id="custom_field_possible_values_attributes"><legend class="form--fieldset-legend"><%= I18n.t("activerecord.attributes.custom_field.possible_values") %></legend><div class="form--field">diff --git a/app/views/customizable/_field.html.erb b/app/views/customizable/_field.html.erbdeleted file mode 100644index 91080652483..00000000000--- a/app/views/customizable/_field.html.erb+++ /dev/null@@ -1,37 +0,0 @@-<%#-- copyright-OpenProject is an open source project management software.-Copyright (C) 2012-2021 the OpenProject GmbH--This program is free software; you can redistribute it and/or-modify it under the terms of the GNU General Public License version 3.--OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-Copyright (C) 2006-2013 Jean-Philippe Lang-Copyright (C) 2010-2013 the ChiliProject Team--This program is free software; you can redistribute it and/or-modify it under the terms of the GNU General Public License-as published by the Free Software Foundation; either version 2-of the License, or (at your option) any later version.--This program is distributed in the hope that it will be useful,-but WITHOUT ANY WARRANTY; without even the implied warranty of-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-GNU General Public License for more details.--You should have received a copy of the GNU General Public License-along with this program; if not, write to the Free Software-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.--See docs/COPYRIGHT.rdoc for more details.--++#%>--<%# locals: form %>--<%= form.fields_for_custom_fields :custom_field_values, value do |value_form| %>- <% required = value.custom_field.is_required? %>- <div class="form--field <%= required ? '-required' : '' %> <%= (defined? wide_labels) ? "-wide-label" : '' %>">- <%= value_form.custom_field container_class: (defined? input_size) ? "-#{input_size}" : '' %>- </div>-<% end %>diff --git a/app/views/customizable/_form.html.erb b/app/views/customizable/_form.html.erbindex aaa299015c1..62e193be220 100644--- a/app/views/customizable/_form.html.erb+++ b/app/views/customizable/_form.html.erb@@ -27,24 +27,36 @@ See docs/COPYRIGHT.rdoc for more details.++#%>-<%# locals: form, all_fields, only_required #%>--<% form.object.custom_field_values.each do |value| %>- <%= form.fields_for_custom_fields :custom_field_values, value do |value_form| %>- <%# display all fields OR only display required fields OR only display optional fields #%>- <% required = value.custom_field.is_required? %>- <% if all_fields || (only_required && required) || (!only_required && !required) %>- <% container_class = value.custom_field.field_format == 'text' ? '-xxwide' : '-wide' %>- <div class="form--field custom_field_<%= value.custom_field.id %> <%= required ? '-required' : '' %>">- <%- options = { container_class: container_class, required: required }-- if local_assigns[:help_text]- options[:help_text] = local_assigns[:help_text].merge(attribute: "customField#{value.custom_field.id}")- end- %>- <%= value_form.custom_field(options) %>- </div>- <% end %>+<% input_size = local_assigns[:input_size] || '-wide' %>+<% wide_labels = local_assigns[:wide_labels] ? '-wide-labels' : '' %>+<% help_text = local_assigns[:help_text] %>++<% form+ .object+ .available_custom_fields+ .select { |custom_field| all_fields || only_required == custom_field.is_required? }+ .each do |custom_field| %>+ <%+ form_options = {+ custom_value: form.object.custom_value_for(custom_field.id),+ custom_field: custom_field+ } %>+ <%= form.fields_for_custom_fields :custom_field_values, form.object, form_options do |cf_form| %>+ <% show_required = custom_field.is_required? && !custom_field.boolean? %>+ <%= content_tag :div,+ class: ['form--field',+ "custom_field_#{custom_field.id}",+ (show_required ? '-required' : ''),+ wide_labels] do+ options = {+ container_class: custom_field.field_format == 'text' ? '-xxwide' : input_size,+ }++ if help_text+ options[:help_text] = help_text.merge(attribute: "customField#{custom_field.id}")+ end++ cf_form.cf_form_field(options)+ end %><% end %><% end %>diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erbindex 633100fee17..5f860fc9452 100644--- a/app/views/my/account.html.erb+++ b/app/views/my/account.html.erb@@ -69,10 +69,8 @@ See docs/COPYRIGHT.rdoc for more details.<%= call_hook(:view_my_account, user: @user, form: f) %>- <%= render partial: 'customizable/field',- collection: @user.custom_field_values.select(&:editable?),- as: :value,- locals: { form: f, input_size: :middle } %>+ <%= render partial: "customizable/form",+ locals: { form: f, all_fields: true, only_required: false, input_size: '-middle' } %></section><%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %>diff --git a/app/views/users/form/_custom_fields.html.erb b/app/views/users/form/_custom_fields.html.erbindex 0a7746c2fb8..09824b363d9 100644--- a/app/views/users/form/_custom_fields.html.erb+++ b/app/views/users/form/_custom_fields.html.erb@@ -1,4 +1,2 @@-<%= render partial: 'customizable/field',- collection: @user.custom_field_values,- as: :value,- locals: { form: f, input_size: 'middle' } %>\ No newline at end of file+<%= render partial: "customizable/form",+ locals: { form: f, all_fields: true, only_required: false, input_size: '-middle' } %>diff --git a/lib/custom_field_form_builder.rb b/lib/custom_field_form_builder.rbindex 3fac604e8c6..f04a3d00084 100644--- a/lib/custom_field_form_builder.rb+++ b/lib/custom_field_form_builder.rb@@ -33,8 +33,18 @@ require 'action_view/helpers/form_helper'class CustomFieldFormBuilder < TabularFormBuilderinclude ActionView::Context+ attr_reader :custom_value,+ :custom_field++ def initialize(object_name, object, template, options)+ super++ @custom_value = options.fetch(:custom_value)+ @custom_field = options.fetch(:custom_field)+ end+# Return custom field html tag corresponding to its format- def custom_field(options = {})+ def cf_form_field(options = {})input = custom_field_input(options)if options[:no_label]@@ -49,20 +59,14 @@ class CustomFieldFormBuilder < TabularFormBuilderprivate- def possible_options_for_object- object- .custom_field- .possible_values_options(object.customized)- end-def custom_field_input(options = {})- field = :value+ field = custom_field.accessor_nameinput_options = options.merge(no_label: true,name: custom_field_field_name,id: custom_field_field_id)- field_format = OpenProject::CustomFieldFormat.find_by_name(object.custom_field.field_format)+ field_format = OpenProject::CustomFieldFormat.find_by_name(custom_field.field_format)case field_format.try(:edit_as)when 'date'@@ -71,8 +75,7 @@ class CustomFieldFormBuilder < TabularFormBuilderwhen 'text'text_area(field, input_options.merge(with_text_formatting: true, macros: false, editor_type: 'constrained'))when 'bool'- formatter = field_format.formatter.new(object)- check_box(field, input_options.merge(checked: formatter.checked?))+ check_box(field, input_options.merge(checked: custom_value.strategy.checked?))when 'list'custom_field_input_list(field, input_options)else@@ -81,22 +84,25 @@ class CustomFieldFormBuilder < TabularFormBuilderenddef custom_field_input_list(field, input_options)- possible_options = possible_options_for_object+ customized = Array(custom_value).first&.customized+ possible_options = custom_field.possible_values_options(customized)select_options = custom_field_select_options_for_object- selectable_options = template.options_for_select(possible_options, object.value)+ selected_options = Array(custom_value).map(&:value)+ selectable_options = template.options_for_select(possible_options, selected_options)+ input_options[:multiple] = custom_field.multi_value?select(field, selectable_options, select_options, input_options).html_safeenddef custom_field_select_options_for_object- is_required = object.custom_field.is_required?- default_value = object.custom_field.default_value+ is_required = custom_field.is_required?+ default_value = custom_field.default_valueselect_options = { no_label: true }if is_required && default_value.blank?select_options[:prompt] = "--- #{I18n.t(:actionview_instancetag_blank_option)} ---"- elsif !is_required+ elsif !is_required && !custom_field.multi_value?select_options[:include_blank] = trueend@@ -104,26 +110,28 @@ class CustomFieldFormBuilder < TabularFormBuilderenddef custom_field_field_name- "#{object_name}[#{object.custom_field.id}]"+ if custom_field.multi_value?+ "#{object_name}[#{custom_field.id}][]"+ else+ "#{object_name}[#{custom_field.id}]"+ endenddef custom_field_field_id- "#{object_name}#{object.custom_field.id}".gsub(/[\[\]]+/, '_')+ "#{object_name}#{custom_field.id}".gsub(/[\[\]]+/, '_')end# Return custom field label tagdef custom_field_label_tag(options)- custom_value = object-classes = 'form--label'- classes << ' error' unless custom_value.errors.empty?+ classes << ' error' unless Array(custom_value).flat_map(&:errors).empty?content_tag 'label',for: custom_field_field_id,class: classes,- title: custom_value.custom_field.name do+ title: custom_field.name dooutput = ''.html_safe- output += custom_value.custom_field.name+ output += custom_field.name# Render a help text iconif options[:help_text]diff --git a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rbindex 5f695b43bda..93f66b8fcdb 100644--- a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb+++ b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb@@ -122,10 +122,21 @@ module Redmineendend+ ##+ # Maps custom_values into a hash that can be passed to attributes+ # but keeps multivalue custom fields as array valuesdef custom_value_attributes- custom_field_values- .map { |cv| [cv.custom_field_id, cv.value] }- .to_h+ custom_field_values.each_with_object({}) do |cv, hash|+ key = cv.custom_field_id+ value = cv.value++ hash[key] =+ if existing = hash[key]+ Array(existing) << value+ else+ value+ end+ endenddef visible_custom_field_valuesdiff --git a/script/github_pr_errors b/script/github_pr_errorsindex dc5a1f6d724..5cdbc244f7a 100755--- a/script/github_pr_errors+++ b/script/github_pr_errors@@ -70,5 +70,5 @@ endif errors.empty?warn "No rspec errors found :-/"else- puts errors.flatten.join(" ")+ puts errors.flatten.uniq.join(" ")enddiff --git a/spec/factories/custom_field_factory.rb b/spec/factories/custom_field_factory.rbindex ccc80ed92a7..37ac1bcca5b 100644--- a/spec/factories/custom_field_factory.rb+++ b/spec/factories/custom_field_factory.rb@@ -49,6 +49,7 @@ FactoryBot.define dofactory :list_project_custom_field dosequence(:name) { |n| "List project custom field #{n}" }+ multi_value { false }field_format { 'list' }possible_values { ['A', 'B', 'C', 'D', 'E', 'F', 'G'] }enddiff --git a/spec/features/custom_fields/custom_fields_spec.rb b/spec/features/custom_fields/custom_fields_spec.rbindex c697edf65a7..bda353258ef 100644--- a/spec/features/custom_fields/custom_fields_spec.rb+++ b/spec/features/custom_fields/custom_fields_spec.rb@@ -9,14 +9,11 @@ describe 'custom fields', js: true dologin_as(user)end- describe "creating a new list custom field" do- before do- cf_page.visit!+ shared_examples "creating a new list custom field" do |type|+ it "creates a new list custom field with its options in the right order" do+ cf_page.visit_tab typeclick_on "Create a new custom field"- end-- it "creates a new list custom field with its options in the right order" docf_page.set_name "Operating System"select "List", from: "custom_field_field_format"@@ -62,6 +59,14 @@ describe 'custom fields', js: true doendend+ describe 'projects' do+ it_behaves_like "creating a new list custom field", 'Projects'+ end++ describe 'work packages' do+ it_behaves_like "creating a new list custom field", 'Work packages'+ end+context "with an existing list custom field" dolet!(:custom_field) doFactoryBot.create(diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rbindex d7eec938f09..2d45fdec73a 100644--- a/spec/features/projects/projects_index_spec.rb+++ b/spec/features/projects/projects_index_spec.rb@@ -969,4 +969,30 @@ describe 'Projects index page',expect(page).to_not have_select('add_filter_select', with_options: ["Subproject of"])endend++ context 'with a multi-value custom field' do+ let!(:list_custom_field) { FactoryBot.create(:list_project_custom_field, multi_value: true) }++ before do+ project.custom_values << CustomValue.new(custom_field: list_custom_field, value: list_custom_field.value_of('A'))+ project.custom_values << CustomValue.new(custom_field: list_custom_field, value: list_custom_field.value_of('B'))++ project.save!++ allow_enterprise_edition+ Setting.enabled_projects_columns << "cf_#{list_custom_field.id}"++ login_as(admin)+ visit projects_path+ end++ it 'shows the multi selection' do+ expected_sort = list_custom_field+ .custom_options+ .where(value: %w[A B])+ .reorder(:id)+ .pluck(:value)+ expect(page).to have_selector(".cf_#{list_custom_field.id}.format-list", text: expected_sort.join(", "))+ end+ endenddiff --git a/spec/features/projects/projects_spec.rb b/spec/features/projects/projects_spec.rbindex 421964c74fa..ca45222252f 100644--- a/spec/features/projects/projects_spec.rb+++ b/spec/features/projects/projects_spec.rb@@ -36,7 +36,7 @@ describe 'Projects', type: :feature doenddescribe 'creation', js: true do- let!(:project) { FactoryBot.create(:project, name: 'Foo project', identifier: 'foo-project') }+ shared_let(:project) { FactoryBot.create(:project, name: 'Foo project', identifier: 'foo-project') }before dovisit projects_path@@ -97,6 +97,35 @@ describe 'Projects', type: :feature doexpect(page).to have_content 'Identifier has already been taken'expect(current_path).to eq '/projects'end++ context 'with a multi-select custom field' do+ let!(:list_custom_field) { FactoryBot.create(:list_project_custom_field, name: 'List CF', multi_value: true) }++ it 'can create a project' do+ click_on 'New project'++ fill_in 'project[name]', with: 'Foo bar'+ click_on 'Advanced settings'+ fill_in 'project[identifier]', with: 'foo'++ select 'A', from: 'List CF'+ select 'B', from: 'List CF'++ sleep 1++ click_on 'Create'++ expect(page).to have_content 'Successful creation.'+ expect(page).to have_content 'Foo bar'+ expect(current_path).to eq '/projects/foo/work_packages'++ project = Project.last+ expect(project.name).to eq 'Foo bar'+ cvs = project.custom_value_for(list_custom_field)+ expect(cvs.count).to eq 2+ expect(cvs.map(&:typed_value)).to contain_exactly 'A', 'B'+ end+ endenddescribe 'project types' do@@ -239,4 +268,28 @@ describe 'Projects', type: :feature doendendend++ context 'with a multi-select custom field' do+ let(:project) { FactoryBot.create(:project, name: 'Foo project', identifier: 'foo-project') }+ let!(:list_custom_field) { FactoryBot.create(:list_project_custom_field, name: 'List CF', multi_value: true) }++ it 'can create a project' do+ visit settings_generic_project_path(project.id)++ select 'A', from: 'List CF'+ select 'B', from: 'List CF'++ sleep 1++ click_on 'Save'++ expect(page).to have_content 'Successful update.'++ expect(page).to have_select('List CF', selected: %w[A B])++ cvs = project.reload.custom_value_for(list_custom_field)+ expect(cvs.count).to eq 2+ expect(cvs.map(&:typed_value)).to contain_exactly 'A', 'B'+ end+ endenddiff --git a/spec/lib/custom_field_form_builder_spec.rb b/spec/lib/custom_field_form_builder_spec.rbindex ac2049a071e..c048a5af9f7 100644--- a/spec/lib/custom_field_form_builder_spec.rb+++ b/spec/lib/custom_field_form_builder_spec.rb@@ -34,7 +34,13 @@ describe CustomFieldFormBuilder doinclude Capybara::RSpecMatcherslet(:helper) { ActionView::Base.new(ActionView::LookupContext.new(''), {}, @controller) }- let(:builder) { described_class.new(:user, resource, helper, {}) }+ let(:builder) { described_class.new(:user, resource, helper, builder_options) }+ let(:builder_options) do+ {+ custom_value: custom_value,+ custom_field: custom_field+ }+ enddescribe '#custom_field' dolet(:options) { { class: 'custom-class' } }@@ -42,12 +48,25 @@ describe CustomFieldFormBuilder dolet(:custom_field) doFactoryBot.build_stubbed(:custom_field)end+ let(:custom_value) do+ FactoryBot.build_stubbed(:custom_value, customized: resource, custom_field: custom_field)+ end+ let(:typed_value) do+ custom_value.typed_value+ end+let(:resource) do- FactoryBot.build_stubbed(:custom_value, custom_field: custom_field)+ FactoryBot.build_stubbed(:user)+ end++ before do+ allow(resource)+ .to receive(custom_field.accessor_name)+ .and_return(typed_value)endsubject(:output) do- builder.custom_field options+ builder.cf_form_field optionsendit_behaves_like 'labelled by default'@@ -63,8 +82,8 @@ describe CustomFieldFormBuilder doit 'should output element' doexpect(output).to be_html_eql(%{<input class="custom-class form--check-box"- id="user#{resource.custom_field_id}"- name="user[#{resource.custom_field_id}]"+ id="user#{custom_field.id}"+ name="user[#{custom_field.id}]"type="checkbox"value="1" />}).at_path('input:nth-of-type(2)')@@ -73,7 +92,7 @@ describe CustomFieldFormBuilder docontext 'for a date custom field' dobefore do- resource.custom_field.field_format = 'date'+ custom_field.field_format = 'date'endit_behaves_like 'wrapped in container', 'text-field-container' do@@ -83,8 +102,8 @@ describe CustomFieldFormBuilder doit 'should output element' doexpect(output).to be_html_eql(%{<input class="custom-class -augmented-datepicker form--text-field"- id="user#{resource.custom_field_id}"- name="user[#{resource.custom_field_id}]"+ id="user#{custom_field.id}"+ name="user[#{custom_field.id}]"type="text" />}).at_path('input')end@@ -92,7 +111,7 @@ describe CustomFieldFormBuilder docontext 'for a text custom field' dobefore do- resource.custom_field.field_format = 'text'+ custom_field.field_format = 'text'endit_behaves_like 'wrapped in container', 'text-area-container' do@@ -102,8 +121,8 @@ describe CustomFieldFormBuilder doit 'should output element' doexpect(output).to be_html_eql(%{<textarea class="custom-class form--text-area"- id="user#{resource.custom_field_id}"- name="user[#{resource.custom_field_id}]"+ id="user#{custom_field.id}"+ name="user[#{custom_field.id}]"with_text_formatting="true"editor_type="constrained"macros="false">@@ -114,7 +133,7 @@ describe CustomFieldFormBuilder docontext 'for a string custom field' dobefore do- resource.custom_field.field_format = 'string'+ custom_field.field_format = 'string'endit_behaves_like 'wrapped in container', 'text-field-container' do@@ -124,8 +143,8 @@ describe CustomFieldFormBuilder doit 'should output element' doexpect(output).to be_html_eql(%{<input class="custom-class form--text-field"- id="user#{resource.custom_field_id}"- name="user[#{resource.custom_field_id}]"+ id="user#{custom_field.id}"+ name="user[#{custom_field.id}]"type="text" />}).at_path('input')end@@ -133,7 +152,7 @@ describe CustomFieldFormBuilder docontext 'for an int custom field' dobefore do- resource.custom_field.field_format = 'int'+ custom_field.field_format = 'int'endit_behaves_like 'wrapped in container', 'text-field-container' do@@ -143,8 +162,8 @@ describe CustomFieldFormBuilder doit 'should output element' doexpect(output).to be_html_eql(%{<input class="custom-class form--text-field"- id="user#{resource.custom_field_id}"- name="user[#{resource.custom_field_id}]"+ id="user#{custom_field.id}"+ name="user[#{custom_field.id}]"type="text" />}).at_path('input')end@@ -152,7 +171,7 @@ describe CustomFieldFormBuilder docontext 'for a float custom field' dobefore do- resource.custom_field.field_format = 'float'+ custom_field.field_format = 'float'endit_behaves_like 'wrapped in container', 'text-field-container' do@@ -162,8 +181,8 @@ describe CustomFieldFormBuilder doit 'should output element' doexpect(output).to be_html_eql(%{<input class="custom-class form--text-field"- id="user#{resource.custom_field_id}"- name="user[#{resource.custom_field_id}]"+ id="user#{custom_field.id}"+ name="user[#{custom_field.id}]"type="text" />}).at_path('input')end@@ -233,9 +252,15 @@ describe CustomFieldFormBuilder dolet(:user1) { FactoryBot.build_stubbed(:user) }let(:user2) { FactoryBot.build_stubbed(:user) }+ let(:resource) { project }+before do- resource.custom_field.field_format = 'user'- resource.customized = project+ custom_field.field_format = 'user'++ allow(project)+ .to receive(custom_field.accessor_name)+ .and_return typed_value+allow(project).to(receive(:principals)).and_return([user1, user2])@@ -248,8 +273,8 @@ describe CustomFieldFormBuilder doit 'should output element' doexpect(output).to be_html_eql(%{<select class="custom-class form--select"- id="user#{resource.custom_field_id}"- name="user[#{resource.custom_field_id}]"+ id="user#{custom_field.id}"+ name="user[#{custom_field.id}]"no_label="true"><option value=\"\" label=\" \"></option><option value="#{user1.id}">#{user1.name}</option>@@ -260,14 +285,14 @@ describe CustomFieldFormBuilder docontext 'which is required and has no default value' dobefore do- resource.custom_field.is_required = true+ custom_field.is_required = trueendit 'should output element' doexpect(output).to be_html_eql(%{<select class="custom-class form--select"- id="user#{resource.custom_field_id}"- name="user[#{resource.custom_field_id}]"+ id="user#{custom_field.id}"+ name="user[#{custom_field.id}]"no_label="true"><option value=\"\">--- Please select ---</option><option value="#{user1.id}">#{user1.name}</option>@@ -283,9 +308,14 @@ describe CustomFieldFormBuilder dolet(:version1) { FactoryBot.build_stubbed(:version) }let(:version2) { FactoryBot.build_stubbed(:version) }+ let(:resource) { project }+before do- resource.custom_field.field_format = 'version'- resource.customized = project+ custom_field.field_format = 'version'+ allow(project)+ .to receive(custom_field.accessor_name)+ .and_return typed_value+allow(project).to receive(:shared_versions).and_return([version1, version2])@@ -298,8 +328,8 @@ describe CustomFieldFormBuilder doit 'should output element' doexpect(output).to be_html_eql(%{<select class="custom-class form--select"- id="user#{resource.custom_field_id}"- name="user[#{resource.custom_field_id}]"+ id="user#{custom_field.id}"+ name="user[#{custom_field.id}]"no_label="true"><option value=\"\" label=\" \"></option><option value="#{version1.id}">#{version1.name}</option>@@ -310,14 +340,14 @@ describe CustomFieldFormBuilder docontext 'which is required and has no default value' dobefore do- resource.custom_field.is_required = true+ custom_field.is_required = trueendit 'should output element' doexpect(output).to be_html_eql(%{<select class="custom-class form--select"- id="user#{resource.custom_field_id}"- name="user[#{resource.custom_field_id}]"+ id="user#{custom_field.id}"+ name="user[#{custom_field.id}]"no_label="true"><option value=\"\">--- Please select ---</option><option value="#{version1.id}">#{version1.name}</option>diff --git a/spec/services/projects/copy_service_integration_spec.rb b/spec/services/projects/copy_service_integration_spec.rbindex cff0afd26b9..3992d30165f 100644--- a/spec/services/projects/copy_service_integration_spec.rb+++ b/spec/services/projects/copy_service_integration_spec.rb@@ -644,6 +644,28 @@ describe Projects::CopyService, 'integration', type: :model doexpect(cv.typed_value).to eq user_valueendend++ context 'with multi selection project list CF' do+ let(:list_custom_field) { FactoryBot.create(:list_project_custom_field, multi_value: true) }++ before do+ source.custom_values << CustomValue.new(custom_field: list_custom_field, value: list_custom_field.value_of('A'))+ source.custom_values << CustomValue.new(custom_field: list_custom_field, value: list_custom_field.value_of('B'))++ source.save!+ end++ let(:only_args) { %w[wiki] }++ it 'copies the custom_field' do+ expect(subject).to be_success++ cv = project_copy.custom_values.reload.where(custom_field: list_custom_field).to_a+ expect(cv).to be_kind_of Array+ expect(cv.count).to eq 2+ expect(cv.map(&:formatted_value)).to contain_exactly('A', 'B')+ end+ endendendenddiff --git a/spec/support/pages/custom_fields.rb b/spec/support/pages/custom_fields.rbindex 1205f5c21a2..c2e02def6e2 100644--- a/spec/support/pages/custom_fields.rb+++ b/spec/support/pages/custom_fields.rb@@ -34,6 +34,13 @@ module Pages'/custom_fields'end+ def visit_tab(name)+ visit!+ within('content-tabs') do+ click_link name.to_s+ end+ end+def select_format(label)select label, from: "custom_field_field_format"end