From d05c1ff0877dcd5dd2a79a13b0622a8fc1fdc650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Thu, 28 Jun 2018 08:54:26 +0200 Subject: [PATCH] [27940] Don't sort members of attribute groups This will result in wrong orders https://community.openproject.com/wp/27940 --- app/models/type/attribute_group.rb | 2 +- spec/models/type/attribute_groups_spec.rb | 25 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/models/type/attribute_group.rb b/app/models/type/attribute_group.rb index 7208bdd11d..fcea4734c1 100644 --- a/app/models/type/attribute_group.rb +++ b/app/models/type/attribute_group.rb @@ -36,7 +36,7 @@ class Type::AttributeGroup < Type::FormGroup # unexpected/unexplicable validation error. valid_keys = type.work_package_attributes.keys - (attributes & valid_keys).sort + (attributes & valid_keys) end def ==(other) diff --git a/spec/models/type/attribute_groups_spec.rb b/spec/models/type/attribute_groups_spec.rb index 8c11b9e794..0089dd0a0f 100644 --- a/spec/models/type/attribute_groups_spec.rb +++ b/spec/models/type/attribute_groups_spec.rb @@ -221,6 +221,31 @@ describe ::Type, type: :model do expect(type.save).to be_truthy expect(type.read_attribute(:attribute_groups)).not_to be_empty end + + context 'with multiple CFs' do + let!(:custom_field2) do + FactoryBot.create( + :work_package_custom_field, + field_format: 'string' + ) + end + let(:cf_identifier2) do + :"custom_field_#{custom_field2.id}" + end + + it 'they are kept in their respective positions in the group (Regression test #27940)' do + # Enforce fresh lookup of groups + OpenProject::Cache.clear + + # Can be enabled + type.attribute_groups = [['foo', [cf_identifier2.to_s, cf_identifier.to_s]]] + expect(type.save).to be_truthy + expect(type.read_attribute(:attribute_groups)).not_to be_empty + + cf_group = type.attribute_groups[0] + expect(cf_group.members).to eq([cf_identifier2.to_s, cf_identifier.to_s]) + end + end end describe 'custom field added implicitly to type' do