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
support the child operator properly
ulferts336fd850a499
diff --git a/app/models/queries/operators.rb b/app/models/queries/operators.rbindex 3cb44d9c86f..66e2e34aec6 100644--- a/app/models/queries/operators.rb+++ b/app/models/queries/operators.rb@@ -59,7 +59,8 @@ module Queries::OperatorsQueries::Operators::Requires,Queries::Operators::Required,Queries::Operators::Parent,- Queries::Operators::Children+ Queries::Operators::Children,+ Queries::Operators::Child]OPERATORS = Hash[*(operators.map { |o| [o.symbol.to_s, o] }).flatten].freezediff --git a/app/models/queries/operators/child.rb b/app/models/queries/operators/child.rbnew file mode 100644index 00000000000..68c869ca278--- /dev/null+++ b/app/models/queries/operators/child.rb@@ -0,0 +1,34 @@+# --copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-2022 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 COPYRIGHT and LICENSE files for more details.+# ++++module Queries::Operators+ class Child < Base+ label 'child'+ set_symbol 'child'+ end+enddiff --git a/spec/requests/api/v3/work_packages/available_relation_candidates_resource_spec.rb b/spec/requests/api/v3/work_packages/available_relation_candidates_resource_spec.rbindex 9dd6981ebdc..7986fffa6d1 100644--- a/spec/requests/api/v3/work_packages/available_relation_candidates_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/available_relation_candidates_resource_spec.rb@@ -147,24 +147,48 @@ describe ::API::V3::WorkPackages::AvailableRelationCandidatesAPI dodescribe 'with an already existing relationship from the work package' do# rubocop:disable Naming/VariableNumbershared_let(:relation_wp2_to_wp2_2) do- create(:relation, from: wp2, to: wp2_2, relation_type: "relates")+ create(:relation, from: wp2, to: wp2_2, relation_type: "follows")endshared_let(:relation_wp1_1_to_wp2) do- create(:relation, from: wp1_1, to: wp2, relation_type: "relates")+ create(:relation, from: wp1_1, to: wp2, relation_type: "follows")end# rubocop:enable Naming/VariableNumbercontext 'for a follows relationship' do- it 'does not contain the work packages with which a relationship already exists but the parent' do+ it 'does not contain the work packages already related in the opposite direction nor the parent' do+ expect(subjects).to match_array ["WP 1.2", "WP 1.2.1", "WP 2.1"]+ end+ end++ context 'for a precedes relationship' do+ let(:href) { "/api/v3/work_packages/#{wp2.id}/available_relation_candidates?query=WP&type=precedes" }++ it 'does not contain the work packages already related but the parent' doexpect(subjects).to match_array ["WP 1", "WP 1.2", "WP 1.2.1", "WP 2.1"]endend+ context 'for a parent relationship' do+ let(:href) { "/api/v3/work_packages/#{wp2.id}/available_relation_candidates?query=WP&type=parent" }++ it 'does not contain the work packages already related but the parent' do+ expect(subjects).to match_array ["WP 1", "WP 1.2", "WP 1.2.1", "WP 2.1"]+ end+ end++ context 'for a child relationship' do+ let(:href) { "/api/v3/work_packages/#{wp2.id}/available_relation_candidates?query=WP&type=child" }++ it 'does not contain the work packages already related nor the parent' do+ expect(subjects).to match_array ["WP 1.2", "WP 1.2.1", "WP 2.1"]+ end+ end+context 'for a relates relationship' dolet(:href) { "/api/v3/work_packages/#{wp2.id}/available_relation_candidates?query=WP&type=relates" }- it 'does not contain the work packages with which a relationship already exists but the parent' do+ it 'does not contain the work packages already related but the parent' doexpect(subjects).to match_array ["WP 1", "WP 1.2", "WP 1.2.1", "WP 2.1"]endend