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
fix reversing the relation if necessary before validation
ulferts322af4b73801
diff --git a/app/contracts/relations/base_contract.rb b/app/contracts/relations/base_contract.rbindex ad853587c91..5500763ddfe 100644--- a/app/contracts/relations/base_contract.rb+++ b/app/contracts/relations/base_contract.rb@@ -46,7 +46,7 @@ module RelationsRelationend- def validate!(*args)+ def valid?(*args)# same as before_validation callbackmodel.send(:reverse_if_needed)@@ -65,7 +65,7 @@ module Relationsdef validate_nodes_relatableif (model.from_id_changed? || model.to_id_changed?) &&- WorkPackage.relatable(model.from, model.relation_type).where(id: model.to).empty?+ WorkPackage.relatable(model.from, model.relation_type, ignore_relation: model).where(id: model.to).empty?errors.add :base, I18n.t(:'activerecord.errors.messages.circular_dependency')endenddiff --git a/app/models/work_packages/scopes/directly_related.rb b/app/models/work_packages/scopes/directly_related.rbindex e8c2228c277..6a5447a9e38 100644--- a/app/models/work_packages/scopes/directly_related.rb+++ b/app/models/work_packages/scopes/directly_related.rb@@ -31,9 +31,11 @@ module WorkPackages::Scopesextend ActiveSupport::Concernclass_methods do- def directly_related(work_package)- where(id: Relation.where(from_id: work_package).select(:to_id))- .or(where(id: Relation.where(to_id: work_package).select(:from_id)))+ def directly_related(work_package, ignore_relation: nil)+ relations_without_ignored = ignore_relation ? Relation.where.not(id: ignore_relation.id) : Relation.all++ where(id: relations_without_ignored.where(from_id: work_package).select(:to_id))+ .or(where(id: relations_without_ignored.where(to_id: work_package).select(:from_id)))endendenddiff --git a/app/models/work_packages/scopes/relatable.rb b/app/models/work_packages/scopes/relatable.rbindex 45a188f6cf6..58d21f76908 100644--- a/app/models/work_packages/scopes/relatable.rb+++ b/app/models/work_packages/scopes/relatable.rb@@ -168,7 +168,14 @@ module WorkPackages::Scopes# * includes_hierarchy - boolean indicating that the last relation taken was a hierarchy relation. For a queried for# PARENT relation, whenever that is the case, the work package is a valid relation target although# it appears in the CTE.- def relatable(work_package, relation_type)+ #+ # The caller can can also provide a relation that is ignored for the calculation of which+ # work packages are relatable. This can be helpful in case an existing relation is updated+ # especially if the the direction is switched. Only a single relation can be provided and+ # that one has to either be from or to the work package queried for.+ def relatable(work_package, relation_type, ignore_relation: nil)+ relatable_ensure_single_relation(ignore_relation, work_package)+return all if work_package.new_record?scope = case relation_type@@ -177,11 +184,11 @@ module WorkPackages::Scopeswhen Relation::TYPE_CHILDnot_having_potential_tree_relation_child(work_package)else- where.not(id: directly_related(work_package))+ where.not(id: directly_related(work_package, ignore_relation:))endscope = scope- .not_having_transitive_relation(work_package, relation_type)+ .not_having_transitive_relation(work_package, relation_type, ignore_relation:).where.not(id: work_package.id)if Setting.cross_project_work_package_relations@@ -191,7 +198,7 @@ module WorkPackages::Scopesendend- def not_having_transitive_relation(work_package, relation_type)+ def not_having_transitive_relation(work_package, relation_type, ignore_relation:)if relation_type == Relation::TYPE_RELATES# Bypassing the recursive query in this case as only children and parent needs to be excluded.# Using this more complicated statement since@@ -204,7 +211,7 @@ module WorkPackages::Scopessql = <<~SQL.squishWITHRECURSIVE- #{non_relatable_paths_sql(work_package, relation_type)}+ #{non_relatable_paths_sql(work_package, relation_type, ignore_relation:)}SELECT idFROM related@@ -243,7 +250,7 @@ module WorkPackages::Scopes.where.not(id: where(parent_id: work_package.id).select(:id))end- def non_relatable_paths_sql(work_package, relation_type)+ def non_relatable_paths_sql(work_package, relation_type, ignore_relation: nil)<<~SQL.squishrelated (id,from_hierarchy,@@ -268,7 +275,7 @@ module WorkPackages::ScopesFROMrelatedJOIN LATERAL (- #{joined_existing_connections(relation_type)}+ #{joined_existing_connections(relation_type, ignore_relation:)}) relations ON 1 = 1)SQL@@ -308,7 +315,7 @@ module WorkPackages::Scopesid: work_package.idend- def joined_existing_connections(relation_type)+ def joined_existing_connections(relation_type, ignore_relation:)unions = [existing_hierarchy_lateral(with_descendants: relation_type != Relation::TYPE_CHILD)]case relation_type@@ -316,14 +323,14 @@ module WorkPackages::Scopesunions << existing_relation_of_type_lateral(Relation::TYPE_FOLLOWS, limit_direction: true)unions << existing_relation_of_type_lateral(Relation::TYPE_PRECEDES, limit_direction: true)else- unions << existing_relation_of_type_lateral(relation_type)+ unions << existing_relation_of_type_lateral(relation_type, ignore_relation:)endunions.join(' UNION ')end# rubocop:disable Metrics/PerceivedComplexity- def existing_relation_of_type_lateral(relation_type, limit_direction: false)+ def existing_relation_of_type_lateral(relation_type, ignore_relation: nil, limit_direction: false)canonical_type = Relation.canonical_type(relation_type)is_canonical = canonical_type == relation_type@@ -356,6 +363,7 @@ module WorkPackages::ScopesWHERE (relations.#{direction2} = related.id AND relations.relation_type = :relation_type)AND NOT related.from_#{direction2}#{direction_limit ? "AND NOT #{direction_limit}" : ''}+ #{ignore_relation&.id ? " AND NOT relations.id = #{ignore_relation.id}" : ''}SQL::OpenProject::SqlSanitization@@ -407,6 +415,14 @@ module WorkPackages::Scopes.where(descendant_id: work_packages).select(:ancestor_id)end++ def relatable_ensure_single_relation(ignored_relation, work_package)+ if ignored_relation && (!ignored_relation.is_a?(Relation) ||+ (ignored_relation.from_id != work_package.id && ignored_relation.to_id != work_package.id))+ raise ArgumentError, 'only a single relation with from_id or to_id pointing ' \+ 'to the work package for which relatable is queried for is supported'+ end+ endendendenddiff --git a/spec/models/work_packages/scopes/directly_related_spec.rb b/spec/models/work_packages/scopes/directly_related_spec.rbindex 4a378d89d1e..433e205bcb5 100644--- a/spec/models/work_packages/scopes/directly_related_spec.rb+++ b/spec/models/work_packages/scopes/directly_related_spec.rb@@ -62,10 +62,11 @@ RSpec.describe WorkPackages::Scopes::DirectlyRelated, '.directly_related scope'to: related_work_package_to,from: transitively_related_work_package_to)end+ let(:ignored_relations) { nil }let!(:existing_relations) { [relation_to, transitive_relation_to, relation_from, transitive_relation_from] }- subject(:directly_related) { WorkPackage.directly_related(origin) }+ subject(:directly_related) { WorkPackage.directly_related(origin, ignore_relation: ignored_relations) }it 'is an AR scope' doexpect(directly_related)@@ -78,7 +79,16 @@ RSpec.describe WorkPackages::Scopes::DirectlyRelated, '.directly_related scope'context "with existing relations of type '#{current_type}'" doit 'contains the directly related work packages in both directions' doexpect(directly_related)- .to match_array([related_work_package_to, related_work_package_from])+ .to contain_exactly(related_work_package_to, related_work_package_from)+ end+ end++ context "with existing relations of type '#{current_type}' and ignoring one relation" do+ let(:ignored_relations) { relation_to }++ it 'contains the directly related work packages for which the relation isn`t ignored' do+ expect(directly_related)+ .to contain_exactly(related_work_package_from)endendenddiff --git a/spec/models/work_packages/scopes/relatable_spec.rb b/spec/models/work_packages/scopes/relatable_spec.rbindex 9b4aab99487..d22d65ac399 100644--- a/spec/models/work_packages/scopes/relatable_spec.rb+++ b/spec/models/work_packages/scopes/relatable_spec.rb@@ -73,8 +73,9 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' dolet(:existing_work_packages) { [] }let(:relation_type) { Relation::TYPE_FOLLOWS }+ let(:ignored_relation) { nil }- subject(:relatable) { WorkPackage.relatable(origin, relation_type) }+ subject(:relatable) { WorkPackage.relatable(origin, relation_type, ignore_relation: ignored_relation) }it 'is an AR scope' doexpect(relatable)@@ -87,7 +88,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains every other work package' doexpect(relatable)- .to match_array([unrelated_work_package])+ .to contain_exactly(unrelated_work_package)endend@@ -100,7 +101,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains the unrelated_work_package' doexpect(relatable)- .to match_array([unrelated_work_package])+ .to contain_exactly(unrelated_work_package)endend@@ -122,7 +123,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains the unrelated_work_package' doexpect(relatable)- .to match_array([unrelated_work_package])+ .to contain_exactly(unrelated_work_package)endendend@@ -150,6 +151,16 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' do.to be_emptyendend++ context "with the existing relation and the queried being '#{current_type}' typed but explicitly ignoring the existing" do+ let(:relation_type) { current_type }+ let(:ignored_relation) { directly_related_work_package.relations.first }++ it 'is empty' do+ expect(relatable)+ .to contain_exactly directly_related_work_package+ end+ endendend@@ -162,7 +173,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains the sibling' doexpect(relatable)- .to match_array([sibling])+ .to contain_exactly(sibling)endendend@@ -174,7 +185,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' docontext "for a 'follows' relation and the existing relations being in the same direction" doit 'contains the transitively related work package' doexpect(relatable)- .to match_array([transitively_related_work_package])+ .to contain_exactly(transitively_related_work_package)endend@@ -210,7 +221,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'includes the not directly related work package' doexpect(relatable)- .to match_array [origin]+ .to contain_exactly(origin)endend@@ -268,7 +279,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' do# semantic in the system, the relationship is not prohibited.it 'contains the transitively related work package' doexpect(relatable)- .to match_array([transitively_related_work_package])+ .to contain_exactly(transitively_related_work_package)endend@@ -279,7 +290,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains the transitively related work package' doexpect(relatable)- .to match_array([transitively_related_work_package])+ .to contain_exactly(transitively_related_work_package)endend@@ -293,7 +304,30 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' do# semantic in the system, the relationship is not prohibited.it 'contains the transitively related work package' doexpect(relatable)- .to match_array([transitively_related_work_package])+ .to contain_exactly(transitively_related_work_package)+ end+ end++ context "for a 'blocks' relation and the existing relations being 'blocks' when ignoring origin`s relation" do+ let(:relation_type) { Relation::TYPE_BLOCKS }+ let(:directly_related_work_package_type) { Relation::TYPE_BLOCKS }+ let(:transitively_related_work_package_type) { Relation::TYPE_BLOCKS }+ let(:ignored_relation) { origin.relations.first }++ it 'contains the the related work packages' do+ expect(relatable)+ .to contain_exactly(directly_related_work_package, transitively_related_work_package)+ end+ end++ context "for a 'follows' relation and the existing relations being of opposite direction but ignoring origin`s relation" do+ let(:directly_related_work_package_type) { Relation::TYPE_PRECEDES }+ let(:transitively_related_work_package_type) { Relation::TYPE_PRECEDES }+ let(:ignored_relation) { origin.relations.first }++ it 'contains the the related work packages' do+ expect(relatable)+ .to contain_exactly(directly_related_work_package, transitively_related_work_package)endendend@@ -341,7 +375,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains the work packages in the other hierarchy' doexpect(relatable)- .to match_array [other_parent, other_child]+ .to contain_exactly(other_parent, other_child)endend@@ -352,7 +386,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains the work packages in the other hierarchy' doexpect(relatable)- .to match_array [other_parent, other_child]+ .to contain_exactly(other_parent, other_child)endend@@ -375,7 +409,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains grandparent and aunt' doexpect(relatable)- .to match_array [grandparent, aunt]+ .to contain_exactly(grandparent, aunt)endend@@ -384,7 +418,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains aunt' doexpect(relatable)- .to match_array [aunt]+ .to contain_exactly(aunt)endend@@ -393,7 +427,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains aunt' doexpect(relatable)- .to match_array [aunt]+ .to contain_exactly(aunt)endend@@ -402,7 +436,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains aunt' doexpect(relatable)- .to match_array [aunt]+ .to contain_exactly(aunt)endend@@ -415,7 +449,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains grandparent' doexpect(relatable)- .to match_array [grandparent]+ .to contain_exactly(grandparent)endend@@ -428,7 +462,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains aunt' doexpect(relatable)- .to match_array [aunt]+ .to contain_exactly(aunt)endend@@ -441,7 +475,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains aunt and grandparent' doexpect(relatable)- .to match_array [aunt, grandparent]+ .to contain_exactly(aunt, grandparent)endend@@ -450,7 +484,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains aunt and grandparent' doexpect(relatable)- .to match_array [aunt, grandparent]+ .to contain_exactly(aunt, grandparent)endendend@@ -469,7 +503,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains grandparent and grand_grandparent' doexpect(relatable)- .to match_array [grandparent, grand_grandparent]+ .to contain_exactly(grandparent, grand_grandparent)endend@@ -525,7 +559,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit 'contains grandchild and grand_grandchild' doexpect(relatable)- .to match_array [grandchild, grand_grandchild]+ .to contain_exactly(grandchild, grand_grandchild)endend@@ -564,7 +598,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent" doexpect(relatable)- .to match_array [predecessor_parent]+ .to contain_exactly(predecessor_parent)endend@@ -631,7 +665,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent" doexpect(relatable)- .to match_array [predecessor_parent]+ .to contain_exactly(predecessor_parent)endend@@ -649,7 +683,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent and that parent's predecessor" doexpect(relatable)- .to match_array [predecessor_parent, predecessor_parent_predecessor]+ .to contain_exactly(predecessor_parent, predecessor_parent_predecessor)endend@@ -667,7 +701,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent and that parent's predecessor" doexpect(relatable)- .to match_array [predecessor_parent, predecessor_parent_predecessor]+ .to contain_exactly(predecessor_parent, predecessor_parent_predecessor)endend@@ -676,7 +710,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent and that parent's predecessor" doexpect(relatable)- .to match_array [predecessor_parent, predecessor_parent_predecessor]+ .to contain_exactly(predecessor_parent, predecessor_parent_predecessor)endend@@ -685,7 +719,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent and that parent's predecessor" doexpect(relatable)- .to match_array [predecessor_parent, predecessor_parent_predecessor]+ .to contain_exactly(predecessor_parent, predecessor_parent_predecessor)endendend@@ -711,7 +745,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent and its successor" doexpect(relatable)- .to match_array [predecessor_parent, predecessor_parent_successor]+ .to contain_exactly(predecessor_parent, predecessor_parent_successor)endend@@ -720,7 +754,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the successor of the predecessor's parent" doexpect(relatable)- .to match_array [predecessor_parent_successor]+ .to contain_exactly(predecessor_parent_successor)endend@@ -729,7 +763,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent and that parent's successor" doexpect(relatable)- .to match_array [predecessor_parent, predecessor_parent_successor]+ .to contain_exactly(predecessor_parent, predecessor_parent_successor)endend@@ -738,7 +772,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent's successor" doexpect(relatable)- .to match_array [predecessor_parent_successor]+ .to contain_exactly(predecessor_parent_successor)endend@@ -747,7 +781,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent and that parent's successor" doexpect(relatable)- .to match_array [predecessor_parent, predecessor_parent_successor]+ .to contain_exactly(predecessor_parent, predecessor_parent_successor)endend@@ -756,7 +790,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent and that parent's successor" doexpect(relatable)- .to match_array [predecessor_parent, predecessor_parent_successor]+ .to contain_exactly(predecessor_parent, predecessor_parent_successor)endend@@ -765,7 +799,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's parent and that parent's successor" doexpect(relatable)- .to match_array [predecessor_parent, predecessor_parent_successor]+ .to contain_exactly(predecessor_parent, predecessor_parent_successor)endendend@@ -791,7 +825,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the successor's parent" doexpect(relatable)- .to match_array [successor_parent]+ .to contain_exactly(successor_parent)endend@@ -818,7 +852,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "is contains the successor's parent and that parent's successor" doexpect(relatable)- .to match_array [successor_parent, successor_parent_successor]+ .to contain_exactly(successor_parent, successor_parent_successor)endend@@ -827,7 +861,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the successor's parent and that parent's successor" doexpect(relatable)- .to match_array [successor_parent, successor_parent_successor]+ .to contain_exactly(successor_parent, successor_parent_successor)endend@@ -836,7 +870,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the successor's parent and that parent's successor" doexpect(relatable)- .to match_array [successor_parent, successor_parent_successor]+ .to contain_exactly(successor_parent, successor_parent_successor)endend@@ -845,7 +879,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the successor's parent and that parent's successor" doexpect(relatable)- .to match_array [successor_parent, successor_parent_successor]+ .to contain_exactly(successor_parent, successor_parent_successor)endendend@@ -871,7 +905,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the successor's parent and its predecessor" doexpect(relatable)- .to match_array [successor_parent, successor_parent_predecessor]+ .to contain_exactly(successor_parent, successor_parent_predecessor)endend@@ -880,7 +914,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor of the successor's parent" doexpect(relatable)- .to match_array [successor_parent_predecessor]+ .to contain_exactly(successor_parent_predecessor)endend@@ -889,7 +923,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "is contains the successor's parent's predecessor" doexpect(relatable)- .to match_array [successor_parent_predecessor]+ .to contain_exactly(successor_parent_predecessor)endend@@ -898,7 +932,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "is contains the successor's parent and that parent's predecessor" doexpect(relatable)- .to match_array [successor_parent, successor_parent_predecessor]+ .to contain_exactly(successor_parent, successor_parent_predecessor)endend@@ -907,7 +941,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the successor's parent and that parent's predecessor" doexpect(relatable)- .to match_array [successor_parent, successor_parent_predecessor]+ .to contain_exactly(successor_parent, successor_parent_predecessor)endend@@ -916,7 +950,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the successor's parent and that parent's predecessor" doexpect(relatable)- .to match_array [successor_parent, successor_parent_predecessor]+ .to contain_exactly(successor_parent, successor_parent_predecessor)endend@@ -925,7 +959,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the successor's parent and that parent's predecessor" doexpect(relatable)- .to match_array [successor_parent, successor_parent_predecessor]+ .to contain_exactly(successor_parent, successor_parent_predecessor)endendend@@ -943,7 +977,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent's predecessor" doexpect(relatable)- .to match_array [parent_predecessor]+ .to contain_exactly(parent_predecessor)endend@@ -961,7 +995,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent's predecessor" doexpect(relatable)- .to match_array [parent_predecessor]+ .to contain_exactly(parent_predecessor)endend@@ -979,7 +1013,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent's predecessor" doexpect(relatable)- .to match_array [parent_predecessor]+ .to contain_exactly(parent_predecessor)endend@@ -988,7 +1022,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent's predecessor" doexpect(relatable)- .to match_array [parent_predecessor]+ .to contain_exactly(parent_predecessor)endendend@@ -1006,7 +1040,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent's successor" doexpect(relatable)- .to match_array [parent_successor]+ .to contain_exactly(parent_successor)endend@@ -1033,7 +1067,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent's successor" doexpect(relatable)- .to match_array [parent_successor]+ .to contain_exactly(parent_successor)endend@@ -1042,7 +1076,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent's successor" doexpect(relatable)- .to match_array [parent_successor]+ .to contain_exactly(parent_successor)endend@@ -1051,7 +1085,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent's successor" doexpect(relatable)- .to match_array [parent_successor]+ .to contain_exactly(parent_successor)endendend@@ -1075,7 +1109,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent of the child's successor and the grandparent" doexpect(relatable)- .to match_array [child_successor_parent, child_successor_grandparent]+ .to contain_exactly(child_successor_parent, child_successor_grandparent)endend@@ -1084,7 +1118,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child's successor and that's ancestors" doexpect(relatable)- .to match_array [child_successor, child_successor_parent, child_successor_grandparent]+ .to contain_exactly(child_successor, child_successor_parent, child_successor_grandparent)endend@@ -1093,7 +1127,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child's successor and the parent of that" doexpect(relatable)- .to match_array [child_successor, child_successor_parent, child_successor_grandparent]+ .to contain_exactly(child_successor, child_successor_parent, child_successor_grandparent)endend@@ -1111,7 +1145,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child's successor and the parent of that" doexpect(relatable)- .to match_array [child_successor, child_successor_parent, child_successor_grandparent]+ .to contain_exactly(child_successor, child_successor_parent, child_successor_grandparent)endendend@@ -1135,7 +1169,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent of the child's predecessor" doexpect(relatable)- .to match_array [child_predecessor_parent, child_predecessor_grandparent]+ .to contain_exactly(child_predecessor_parent, child_predecessor_grandparent)endend@@ -1144,7 +1178,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child's predecessor and that's ancestors" doexpect(relatable)- .to match_array [child_predecessor, child_predecessor_parent, child_predecessor_grandparent]+ .to contain_exactly(child_predecessor, child_predecessor_parent, child_predecessor_grandparent)endend@@ -1162,7 +1196,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child's predecessor and the parent of that" doexpect(relatable)- .to match_array [child_predecessor, child_predecessor_parent, child_predecessor_grandparent]+ .to contain_exactly(child_predecessor, child_predecessor_parent, child_predecessor_grandparent)endend@@ -1171,7 +1205,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child's predecessor and the parent of that" doexpect(relatable)- .to match_array [child_predecessor, child_predecessor_parent, child_predecessor_grandparent]+ .to contain_exactly(child_predecessor, child_predecessor_parent, child_predecessor_grandparent)endendend@@ -1195,7 +1229,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent of the child's blocked work package" doexpect(relatable)- .to match_array [child_blocked_parent, child_blocked_grandparent]+ .to contain_exactly(child_blocked_parent, child_blocked_grandparent)endend@@ -1204,7 +1238,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the work package blocked by the child and that's ancestors" doexpect(relatable)- .to match_array [child_blocked, child_blocked_parent, child_blocked_grandparent]+ .to contain_exactly(child_blocked, child_blocked_parent, child_blocked_grandparent)endend@@ -1213,7 +1247,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child's blocked work package and its ancestors" doexpect(relatable)- .to match_array [child_blocked, child_blocked_parent, child_blocked_grandparent]+ .to contain_exactly(child_blocked, child_blocked_parent, child_blocked_grandparent)endend@@ -1222,7 +1256,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child's blocked work package and its ancestors" doexpect(relatable)- .to match_array [child_blocked, child_blocked_parent, child_blocked_grandparent]+ .to contain_exactly(child_blocked, child_blocked_parent, child_blocked_grandparent)endend@@ -1231,7 +1265,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child's blocked work package and its ancestors" doexpect(relatable)- .to match_array [child_blocked, child_blocked_parent, child_blocked_grandparent]+ .to contain_exactly(child_blocked, child_blocked_parent, child_blocked_grandparent)endend@@ -1240,7 +1274,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child's blocked work package and its ancestors" doexpect(relatable)- .to match_array [child_blocked, child_blocked_parent, child_blocked_grandparent]+ .to contain_exactly(child_blocked, child_blocked_parent, child_blocked_grandparent)endend@@ -1279,7 +1313,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's child" doexpect(relatable)- .to match_array [predecessor_child]+ .to contain_exactly(predecessor_child)endend@@ -1297,7 +1331,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's child" doexpect(relatable)- .to match_array [predecessor_child]+ .to contain_exactly(predecessor_child)endend@@ -1306,7 +1340,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's child" doexpect(relatable)- .to match_array [predecessor_child]+ .to contain_exactly(predecessor_child)endend@@ -1315,7 +1349,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's child" doexpect(relatable)- .to match_array [predecessor_child]+ .to contain_exactly(predecessor_child)endend@@ -1324,7 +1358,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the predecessor's child" doexpect(relatable)- .to match_array [predecessor_child]+ .to contain_exactly(predecessor_child)endendend@@ -1348,7 +1382,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent and the child" doexpect(relatable)- .to match_array [blocks_parent, blocks_child]+ .to contain_exactly(blocks_parent, blocks_child)endend@@ -1366,7 +1400,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent" doexpect(relatable)- .to match_array [blocks_parent]+ .to contain_exactly(blocks_parent)endend@@ -1375,7 +1409,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child" doexpect(relatable)- .to match_array [blocks_child]+ .to contain_exactly(blocks_child)endendend@@ -1408,7 +1442,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent and the child" doexpect(relatable)- .to match_array [blocked_parent, blocked_child]+ .to contain_exactly(blocked_parent, blocked_child)endend@@ -1417,7 +1451,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent" doexpect(relatable)- .to match_array [blocked_parent]+ .to contain_exactly(blocked_parent)endend@@ -1426,7 +1460,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child" doexpect(relatable)- .to match_array [blocked_child]+ .to contain_exactly(blocked_child)endendend@@ -1466,7 +1500,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent at the beginning of the chain" doexpect(relatable)- .to match_array [transitive_predecessor_parent]+ .to contain_exactly(transitive_predecessor_parent)endend@@ -1475,7 +1509,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child at the beginning of the chain" doexpect(relatable)- .to match_array [transitive_predecessor_child]+ .to contain_exactly(transitive_predecessor_child)endendend@@ -1506,7 +1540,7 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the parent at the beginning of the chain" doexpect(relatable)- .to match_array [transitive_successor_parent]+ .to contain_exactly(transitive_successor_parent)endend@@ -1515,8 +1549,65 @@ RSpec.describe WorkPackages::Scopes::Relatable, '.relatable scope' doit "contains the child at the beginning of the chain" doexpect(relatable)- .to match_array [transitive_successor_child]+ .to contain_exactly(transitive_successor_child)+ end+ end+ end++ context 'with a transitively related work package that is also directly related' do+ let!(:existing_work_packages) { [directly_related_work_package, transitively_related_work_package] }+ let!(:additional_direct_relation) do+ create(:relation,+ relation_type: transitively_related_work_package_type,+ from: origin,+ to: transitively_related_work_package)+ end++ context "for a 'follows' relation and the existing relations being in the same direction" do+ it 'is empty' do+ expect(relatable)+ .to be_empty+ end+ end++ context "for a 'follows' relation and the existing relations being in the opposite direction" do+ let(:directly_related_work_package_type) { Relation::TYPE_PRECEDES }+ let(:transitively_related_work_package_type) { Relation::TYPE_PRECEDES }++ it 'is empty' do+ expect(relatable)+ .to be_empty+ end+ end++ context "for a 'follows' relation and the existing relations being of opposite direction and ignoring the direct relation" do+ let(:directly_related_work_package_type) { Relation::TYPE_PRECEDES }+ let(:transitively_related_work_package_type) { Relation::TYPE_PRECEDES }+ let(:ignored_relation) { additional_direct_relation }++ it 'is empty' do+ expect(relatable)+ .to be_emptyendendend++ context 'when ignoring anything else then a single relation' do+ let(:ignored_relation) { transitively_related_work_package.relations }++ it 'raises an error' do+ expect { relatable }+ .to raise_error ArgumentError+ end+ end++ context 'when ignoring with a relation neither starting nor ending in the work package queried for' do+ let!(:existing_work_packages) { [directly_related_work_package, transitively_related_work_package] }+ let(:ignored_relation) { transitively_related_work_package.relations.first }++ it 'raises an error' do+ expect { relatable }+ .to raise_error ArgumentError+ end+ endend