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

Refactor replacement-finding recursion

Aaron Contreras03387ca41850
diff --git a/app/services/users/replace_mentions_service.rb b/app/services/users/replace_mentions_service.rb
index 9c29671bd51..e84b2e1f142 100644
--- a/app/services/users/replace_mentions_service.rb
+++ b/app/services/users/replace_mentions_service.rb
@@ -68,15 +68,15 @@ module Users
{ class: News, column: :description },
{ class: Journal::NewsJournal, column: :description },
{ class: Project, column: :description },
- { class: Projects::Status, column: :explanation },
+ { class: Project, column: :status_explanation },
{ class: WikiPage, column: :text },
{ class: Journal::WikiPageJournal, column: :text }
]
end
- def initialize(*classes)
- self.replacements = if classes.any?
- self.class.replacements.select { |r| classes.include?(r[:class]) }
+ def initialize(replacement = nil)
+ self.replacements = if replacement
+ self.class.replacements.select { |r| r == replacement }
else
self.class.replacements
end
@@ -107,7 +107,7 @@ module Users
rewrite_column(from, to)
else
replacements.map do |replacement|
- self.class.new(replacement[:class]).call(from:, to:)
+ self.class.new(replacement).call(from:, to:)
end
end
end
diff --git a/spec/services/users/replace_mentions_service_integration_spec.rb b/spec/services/users/replace_mentions_service_integration_spec.rb
index 0aced0e37a0..4693fe3d317 100644
--- a/spec/services/users/replace_mentions_service_integration_spec.rb
+++ b/spec/services/users/replace_mentions_service_integration_spec.rb
@@ -407,7 +407,7 @@ describe Users::ReplaceMentionsService, 'integration' do
end
context 'for project_status explanation' do
- it_behaves_like 'rewritten mention', :project_status, :explanation
+ it_behaves_like 'rewritten mention', :project, :status_explanation
end
context 'for wiki_page text' do