From 1acccb444a92618fbf3f4264d76958ee9ed93379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 24 Apr 2018 11:04:25 +0200 Subject: [PATCH] Fix attribute groups model now that fixed children query is removed --- app/models/type/attribute_groups.rb | 8 +++++++- spec/models/type/attribute_groups_spec.rb | 12 +++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/models/type/attribute_groups.rb b/app/models/type/attribute_groups.rb index a5f686c755..274f292874 100644 --- a/app/models/type/attribute_groups.rb +++ b/app/models/type/attribute_groups.rb @@ -106,10 +106,14 @@ module Type::AttributeGroups def default_attribute_groups values = work_package_attributes_by_default_group_key - default_groups.keys.each_with_object([]) do |groupkey, array| + groups = default_groups.keys.each_with_object([]) do |groupkey, array| members = values[groupkey] array << [groupkey, members] if members.present? end + + groups << [:children, [default_children_query]] + + groups end def reload(*args) @@ -221,6 +225,8 @@ module Type::AttributeGroups def default_children_query query = Query.new_default + query.name = 'children' + query.is_public = false query.column_names = %w(id type subject) query.show_hierarchies = false query.filters = [] diff --git a/spec/models/type/attribute_groups_spec.rb b/spec/models/type/attribute_groups_spec.rb index b5bb5a69b2..7d5d01a48a 100644 --- a/spec/models/type/attribute_groups_spec.rb +++ b/spec/models/type/attribute_groups_spec.rb @@ -67,7 +67,8 @@ describe ::Type, type: :model do attribute_groups = type.attribute_groups.select{ |g| g.is_a?(Type::AttributeGroup) }.map do |group| [group.key, group.attributes] end - expect(attribute_groups).to eql type.default_attribute_groups + + expect(attribute_groups).to eql type.default_attribute_groups[0...-1] end it_behaves_like 'appends the children query' @@ -92,7 +93,9 @@ describe ::Type, type: :model do expect(group.members).to eql [] end - it_behaves_like 'appends the children query' + it 'does not have a children query' do + expect(type.attribute_groups.detect { |group| group.key == :children }).to be_nil + end end context 'with empty attributes provided' do @@ -120,8 +123,7 @@ describe ::Type, type: :model do end it 'retrieves the query' do - # 2 because of the default query - expect(type.attribute_groups.length).to eql 2 + expect(type.attribute_groups.length).to eql 1 expect(type.attribute_groups[0].class).to eql Type::QueryGroup expect(type.attribute_groups[0].key).to eql 'some group' @@ -134,7 +136,7 @@ describe ::Type, type: :model do type.save! type.reload - expect(type.attribute_groups.length).to eql 2 + expect(type.attribute_groups.length).to eql 1 expect(type.attribute_groups[0].class).to eql Type::QueryGroup expect(type.attribute_groups[0].key).to eql 'some group'