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::Selects::Default.key matches exactly

Ivan Kuchin1aeafb37d97d
diff --git a/app/models/queries/projects/selects/default.rb b/app/models/queries/projects/selects/default.rb
index 59cb279f11c..dcc20d02706 100644
--- a/app/models/queries/projects/selects/default.rb
+++ b/app/models/queries/projects/selects/default.rb
@@ -30,7 +30,7 @@ class Queries::Projects::Selects::Default < Queries::Selects::Base
KEYS = %i[status_explanation hierarchy name public description].freeze
def self.key
- Regexp.new(KEYS.join("|"))
+ /\A(#{Regexp.union(KEYS.map(&:to_s))})\z/
end
def self.all_available
diff --git a/spec/models/queries/projects/selects/default_spec.rb b/spec/models/queries/projects/selects/default_spec.rb
new file mode 100644
index 00000000000..17550b79ccf
--- /dev/null
+++ b/spec/models/queries/projects/selects/default_spec.rb
@@ -0,0 +1,49 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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.
+# ++
+
+require "spec_helper"
+
+RSpec.describe Queries::Projects::Selects::Default do
+ describe ".key" do
+ define_negated_matcher :not_match, :match
+
+ let(:keys) { described_class::KEYS }
+
+ it "matches every key" do
+ expect(keys).to all(match(described_class.key))
+ end
+
+ it "doesn't match any key with prefix" do
+ expect(keys.map { "x#{_1}" }).to all(not_match(described_class.key))
+ end
+
+ it "doesn't match any key with suffix" do
+ expect(keys.map { "#{_1}x" }).to all(not_match(described_class.key))
+ end
+ end
+end