Fix attribute groups model now that fixed children query is removed

pull/6272/head
Oliver Günther 7 years ago
parent 0d33003b7e
commit 1acccb444a
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 8
      app/models/type/attribute_groups.rb
  2. 12
      spec/models/type/attribute_groups_spec.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 = []

@ -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'

Loading…
Cancel
Save