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
[#64348] mv has_circular_reference? formula_references_id?
Tobias Dillmanne6d2cb4d0b41
diff --git a/app/models/custom_field/calculated_value.rb b/app/models/custom_field/calculated_value.rbindex 2caab0291b4..dfd38b115fc 100644--- a/app/models/custom_field/calculated_value.rb+++ b/app/models/custom_field/calculated_value.rb@@ -78,7 +78,7 @@ module CustomField::CalculatedValue.visiblevisible_cfs.reject do |custom_field|- has_circular_reference?(custom_field, id)+ formula_references_id?(custom_field, id)endend@@ -140,7 +140,7 @@ module CustomField::CalculatedValueformula_string.gsub(/\{\{(cf_\d+)}}/, '\1')end- def has_circular_reference?(custom_field, original_id, visited = Set.new)+ def formula_references_id?(custom_field, original_id, visited = Set.new)return true unless visited.add?(custom_field.id)if custom_field.field_format_calculated_value?@@ -149,7 +149,7 @@ module CustomField::CalculatedValuereturn true if referenced_custom_fields.include?(original_id)ProjectCustomField.where(id: referenced_custom_fields).any? do |referenced_field|- has_circular_reference?(referenced_field, original_id, visited)+ formula_references_id?(referenced_field, original_id, visited)endelsefalsediff --git a/spec/models/custom_field/calculated_value_spec.rb b/spec/models/custom_field/calculated_value_spec.rbindex 8e777b122a2..286a4fffae2 100644--- a/spec/models/custom_field/calculated_value_spec.rb+++ b/spec/models/custom_field/calculated_value_spec.rb@@ -176,7 +176,7 @@ RSpec.describe CustomField::CalculatedValue, with_flag: { calculated_value_projeendend- describe "#has_circular_reference?" do+ describe "#formula_contains_reference_to_id?" dolet!(:int_field) { create(:project_custom_field, :integer, default_value: 10, is_for_all: true) }let!(:float_field) { create(:project_custom_field, :float, default_value: 5.5, is_for_all: true) }let!(:text_field) { create(:project_custom_field, :text, default_value: "text", is_for_all: true) }@@ -185,15 +185,15 @@ RSpec.describe CustomField::CalculatedValue, with_flag: { calculated_value_projecontext "when checking a non-calculated value custom field" doit "returns false for integer custom field" do- expect(subject.send(:has_circular_reference?, int_field, subject.id)).to be false+ expect(subject.send(:formula_references_id?, int_field, subject.id)).to be falseendit "returns false for float custom field" do- expect(subject.send(:has_circular_reference?, float_field, subject.id)).to be false+ expect(subject.send(:formula_references_id?, float_field, subject.id)).to be falseendit "returns false for text custom field" do- expect(subject.send(:has_circular_reference?, text_field, subject.id)).to be false+ expect(subject.send(:formula_references_id?, text_field, subject.id)).to be falseendend@@ -203,7 +203,7 @@ RSpec.describe CustomField::CalculatedValue, with_flag: { calculated_value_projeendit "returns false" do- expect(subject.send(:has_circular_reference?, simple_calculated_field, subject.id)).to be false+ expect(subject.send(:formula_references_id?, simple_calculated_field, subject.id)).to be falseendend@@ -221,7 +221,7 @@ RSpec.describe CustomField::CalculatedValue, with_flag: { calculated_value_projeendit "returns true when field references itself" do- circular = self_referencing_field.send(:has_circular_reference?, self_referencing_field, self_referencing_field.id)+ circular = self_referencing_field.send(:formula_references_id?, self_referencing_field, self_referencing_field.id)expect(circular).to be trueendend@@ -257,12 +257,12 @@ RSpec.describe CustomField::CalculatedValue, with_flag: { calculated_value_projeendit "returns true when there is an indirect circular reference" do- expect(field_a.send(:has_circular_reference?, field_a, field_a.id)).to be true+ expect(field_a.send(:formula_references_id?, field_a, field_a.id)).to be trueendit "returns true when checking from any field in the circular chain" do- expect(field_b.send(:has_circular_reference?, field_b, field_b.id)).to be true- expect(field_c.send(:has_circular_reference?, field_c, field_c.id)).to be true+ expect(field_b.send(:formula_references_id?, field_b, field_b.id)).to be true+ expect(field_c.send(:formula_references_id?, field_c, field_c.id)).to be trueendend@@ -287,9 +287,9 @@ RSpec.describe CustomField::CalculatedValue, with_flag: { calculated_value_projeendit "returns false when there is no circular reference" do- expect(field_x.send(:has_circular_reference?, field_x, field_x.id)).to be false- expect(field_y.send(:has_circular_reference?, field_y, field_y.id)).to be false- expect(field_z.send(:has_circular_reference?, field_z, field_z.id)).to be false+ expect(field_x.send(:formula_references_id?, field_x, field_x.id)).to be false+ expect(field_y.send(:formula_references_id?, field_y, field_y.id)).to be false+ expect(field_z.send(:formula_references_id?, field_z, field_z.id)).to be falseendend@@ -308,12 +308,12 @@ RSpec.describe CustomField::CalculatedValue, with_flag: { calculated_value_projeit "returns true when a node has already been visited" dovisited = Set.new([field1.id])- expect(field2.send(:has_circular_reference?, field1, field2.id, visited)).to be true+ expect(field2.send(:formula_references_id?, field1, field2.id, visited)).to be trueendit "returns false when checking a new node with empty visited set" dovisited = Set.new- expect(field2.send(:has_circular_reference?, field1, field2.id, visited)).to be false+ expect(field2.send(:formula_references_id?, field1, field2.id, visited)).to be falseendend@@ -330,7 +330,7 @@ RSpec.describe CustomField::CalculatedValue, with_flag: { calculated_value_projeendit "returns false when referenced custom field does not exist" do- circular = field_with_invalid_ref.send(:has_circular_reference?, field_with_invalid_ref, field_with_invalid_ref.id)+ circular = field_with_invalid_ref.send(:formula_references_id?, field_with_invalid_ref, field_with_invalid_ref.id)expect(circular).to be falseendend