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

Make spec fail if with_ee action is invalid

Christophe Bliard396a7dd4dfd5
diff --git a/spec/support/shared/with_ee.rb b/spec/support/shared/with_ee.rb
index 52f47446686..fbfaec2fb01 100644
--- a/spec/support/shared/with_ee.rb
+++ b/spec/support/shared/with_ee.rb
@@ -26,13 +26,29 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+def assert_valid_ee_action(action, example)
+ valid_ee_actions = Authorization::EnterpriseService::GUARDED_ACTIONS
+ return if valid_ee_actions.include?(action)
+
+ spell_checker = DidYouMean::SpellChecker.new(dictionary: valid_ee_actions)
+ suggestions = spell_checker.correct(action).map(&:inspect).join(' ')
+ did_you_mean = " Did you mean #{suggestions} instead?" if suggestions.present?
+
+ raise "Invalid Enterprise action #{action.inspect} at #{example.location}.#{did_you_mean}"
+end
+
+def ee_actions(example)
+ return [] unless example.respond_to?(:metadata) && example.metadata[:with_ee]
+
+ actions = example.metadata[:with_ee]
+ actions.each { |action| assert_valid_ee_action(action, example) }
+end
+
def aggregate_parent_array(example, acc)
# We have to manually check parent groups for with_ee:,
# since they are being ignored otherwise
example.example_group.module_parents.each do |parent|
- if parent.respond_to?(:metadata) && parent.metadata[:with_ee]
- acc.merge(parent.metadata[:with_ee])
- end
+ acc.merge(ee_actions(parent))
end
acc
@@ -40,7 +56,7 @@ end
RSpec.configure do |config|
config.before do |example|
- allowed = example.metadata[:with_ee]
+ allowed = ee_actions(example)
if allowed.present?
allowed = aggregate_parent_array(example, allowed.to_set)