mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
Rename with_hash_prefix to format_display_id
This commit is contained in:
@@ -124,8 +124,8 @@ module WorkPackage::SemanticIdentifier
|
||||
# Returns formatted value for inline UI display.
|
||||
# * Semantic mode: "PROJ-42" (no prefix — self-describing)
|
||||
# * Classic mode: "#42" (hash-prefixed)
|
||||
def self.with_hash_prefix(value)
|
||||
value.is_a?(String) && value.match?(/[A-Za-z]/) ? value : "##{value}"
|
||||
def self.format_display_id(display_id)
|
||||
display_id.is_a?(String) && display_id.match?(/[A-Za-z]/) ? display_id : "##{display_id}"
|
||||
end
|
||||
|
||||
# Returns the user-facing identifier for this work package.
|
||||
@@ -141,7 +141,7 @@ module WorkPackage::SemanticIdentifier
|
||||
# Semantic mode: "PROJ-42" (no prefix — self-describing)
|
||||
# Classic mode: "#42" (hash-prefixed)
|
||||
def formatted_id
|
||||
WorkPackage::SemanticIdentifier.with_hash_prefix(display_id)
|
||||
WorkPackage::SemanticIdentifier.format_display_id(display_id)
|
||||
end
|
||||
|
||||
# Override ActiveRecord's default `to_param` so Rails URL helpers
|
||||
|
||||
@@ -101,7 +101,7 @@ module OpenProject::TextFormatting::Matchers
|
||||
def render_work_package_macro(work_package:, fallback_id:, detailed: false)
|
||||
id = work_package&.id || fallback_id
|
||||
display_id = work_package&.display_id || fallback_id
|
||||
label = WorkPackage::SemanticIdentifier.with_hash_prefix(display_id)
|
||||
label = WorkPackage::SemanticIdentifier.format_display_id(display_id)
|
||||
|
||||
return label if text_only?(work_package)
|
||||
return render_static_work_package_macro(work_package, label, detailed:) if context[:static_html]
|
||||
|
||||
@@ -606,17 +606,17 @@ RSpec.describe WorkPackage::SemanticIdentifier do
|
||||
end
|
||||
end
|
||||
|
||||
describe ".format" do
|
||||
describe ".format_display_id" do
|
||||
it "returns the semantic identifier unchanged when it carries letters" do
|
||||
expect(described_class.format("MYPROJ-1")).to eq("MYPROJ-1")
|
||||
expect(described_class.format_display_id("MYPROJ-1")).to eq("MYPROJ-1")
|
||||
end
|
||||
|
||||
it "hash-prefixes a numeric integer" do
|
||||
expect(described_class.format(42)).to eq("#42")
|
||||
expect(described_class.format_display_id(42)).to eq("#42")
|
||||
end
|
||||
|
||||
it "hash-prefixes a numeric string" do
|
||||
expect(described_class.format("42")).to eq("#42")
|
||||
expect(described_class.format_display_id("42")).to eq("#42")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user