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
make formula_str_without_patterns public
Ivan Kuchin2833108ac83b
diff --git a/app/models/custom_field/calculated_value.rb b/app/models/custom_field/calculated_value.rbindex c92b041a8a1..e6179003892 100644--- a/app/models/custom_field/calculated_value.rb+++ b/app/models/custom_field/calculated_value.rb@@ -114,6 +114,12 @@ module CustomField::CalculatedValueendend+ # Returns `formula_string` with all custom field references detokenized so that they are parseable by Dentaku.+ # For example, for `2 + {{cf_12}} + {{cf_4}}` it returns `2 + cf_12 + cf_4`.+ def formula_str_without_patterns+ formula_string.gsub(/\{\{(cf_\d+)}}/, '\1')+ end+privatedef calculator@@ -150,11 +156,5 @@ module CustomField::CalculatedValuedef cf_ids_used_in_formula(formula_str)formula_str.scan(/(?<=\{\{cf_)\d+(?=}})/).map(&:to_i).uniqend-- # Returns `formula_string` with all custom field references detokenized so that they are parseable by Dentaku.- # For example, for `2 + {{cf_12}} + {{cf_4}}` it returns `2 + cf_12 + cf_4`.- def formula_str_without_patterns- formula_string.gsub(/\{\{(cf_\d+)}}/, '\1')- endendenddiff --git a/spec/models/custom_field/calculated_value_spec.rb b/spec/models/custom_field/calculated_value_spec.rbindex 41dec192a40..c8affe87086 100644--- a/spec/models/custom_field/calculated_value_spec.rb+++ b/spec/models/custom_field/calculated_value_spec.rb@@ -175,6 +175,26 @@ RSpec.describe CustomField::CalculatedValue, with_flag: { calculated_value_projeendend+ describe "#formula_str_without_patterns" do+ it "returns an empty string if no formula is set" do+ subject.formula = nil++ expect(subject.formula_str_without_patterns).to eq("")+ end++ it "returns the formula as is if formula doesn't reference custom fields" do+ subject.formula = "2 + 2"++ expect(subject.formula_str_without_patterns).to eq("2 + 2")+ end++ it "returns ids if formula references custom fields" do+ subject.formula = "1 * {{cf_7}} + {{cf_42}}"++ expect(subject.formula_str_without_patterns).to eq("1 * cf_7 + cf_42")+ end+ end+describe "#formula_referenced_custom_field_ids" doit "returns an empty array if no formula is set" dosubject.formula = nil