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

Normalize AttributeHelpText#attribute_name

Alexander Brandon Coles33de48f8c77d
diff --git a/app/models/attribute_help_text.rb b/app/models/attribute_help_text.rb
index a138103f83e..fb0f2f30aa2 100644
--- a/app/models/attribute_help_text.rb
+++ b/app/models/attribute_help_text.rb
@@ -62,6 +62,8 @@ class AttributeHelpText < ApplicationRecord
scope
end
+ normalizes :attribute_name, with: -> { it.delete_suffix("_id") }
+
validates :help_text, presence: true
validates :attribute_name, uniqueness: { scope: :type }
diff --git a/spec/models/attribute_help_text/project_spec.rb b/spec/models/attribute_help_text/project_spec.rb
index 7132d9745ba..6e56f1ece26 100644
--- a/spec/models/attribute_help_text/project_spec.rb
+++ b/spec/models/attribute_help_text/project_spec.rb
@@ -111,6 +111,12 @@ RSpec.describe AttributeHelpText::Project do
end
end
+ describe "normalization" do
+ it "normalizes attribute_name" do
+ expect(subject).to normalize(:attribute_name).from("parent_id").to("parent")
+ end
+ end
+
describe "instance" do
subject { build(:project_help_text) }
diff --git a/spec/models/attribute_help_text/work_package_spec.rb b/spec/models/attribute_help_text/work_package_spec.rb
index a3fd96fccaf..c491c3ad8d7 100644
--- a/spec/models/attribute_help_text/work_package_spec.rb
+++ b/spec/models/attribute_help_text/work_package_spec.rb
@@ -197,6 +197,14 @@ RSpec.describe AttributeHelpText::WorkPackage do
end
end
+ describe "normalization" do
+ it "normalizes attribute_name" do
+ expect(subject).to normalize(:attribute_name).from("category_id").to("category")
+ expect(subject).to normalize(:attribute_name).from("status_id").to("status")
+ expect(subject).to normalize(:attribute_name).from("author_id").to("author")
+ end
+ end
+
describe "instance" do
subject { build(:work_package_help_text) }