Skip to content

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

ensure Queries::Projects::Orders::CustomFieldOrder.key matches exactly

Ivan Kuchind55f200cb07b
diff --git a/app/models/queries/projects/orders/custom_field_order.rb b/app/models/queries/projects/orders/custom_field_order.rb
index d8419bcb555..e11575ab3d7 100644
--- a/app/models/queries/projects/orders/custom_field_order.rb
+++ b/app/models/queries/projects/orders/custom_field_order.rb
@@ -36,10 +36,10 @@ class Queries::Projects::Orders::CustomFieldOrder < Queries::Orders::Base
def self.key
valid_ids = RequestStore.fetch(:custom_sortable_project_custom_fields) do
- ProjectCustomField.where.not(field_format: EXCLUDED_CUSTOM_FIELD_TYPES).visible.pluck(:id).join("|")
+ ProjectCustomField.where.not(field_format: EXCLUDED_CUSTOM_FIELD_TYPES).visible.pluck(:id)
end
- /cf_(#{valid_ids})/
+ /\Acf_(#{valid_ids.join('|')})\z/
end
def custom_field
diff --git a/spec/models/queries/projects/orders/custom_field_order_spec.rb b/spec/models/queries/projects/orders/custom_field_order_spec.rb
index c9085d2243c..47816576cd2 100644
--- a/spec/models/queries/projects/orders/custom_field_order_spec.rb
+++ b/spec/models/queries/projects/orders/custom_field_order_spec.rb
@@ -29,6 +29,39 @@
require "spec_helper"
RSpec.describe Queries::Projects::Orders::CustomFieldOrder do
+ describe ".key" do
+ before do
+ where = double
+ where_not = double
+ visible = double
+
+ allow(ProjectCustomField).to receive(:where).and_return(where)
+ allow(where).to receive(:not).with(field_format: %w[text]).and_return(where_not)
+ allow(where_not).to receive(:visible).and_return(visible)
+ allow(visible).to receive(:pluck).with(:id).and_return([42])
+ end
+
+ it "matches key in correct format for existing custom field" do
+ expect(described_class.key).to match("cf_42")
+ end
+
+ it "doesn't match key in correct format for not found custom field" do
+ expect(described_class.key).not_to match("cf_43")
+ end
+
+ it "doesn't match non numerical id" do
+ expect(described_class.key).not_to match("cf_cf")
+ end
+
+ it "doesn't match with prefix" do
+ expect(described_class.key).not_to match("xcf_42")
+ end
+
+ it "doesn't match with suffix" do
+ expect(described_class.key).not_to match("cf_42x")
+ end
+ end
+
describe "#available?" do
let(:instance) { described_class.new("cf_#{custom_field.id}") }