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

[#67706] Format integer custom fields with delimiters

Tobias Dillmann50968972ab50
diff --git a/app/models/custom_value/int_strategy.rb b/app/models/custom_value/int_strategy.rb
index fbeaa88b95c..84af0ed9203 100644
--- a/app/models/custom_value/int_strategy.rb
+++ b/app/models/custom_value/int_strategy.rb
@@ -29,10 +29,16 @@
#++
class CustomValue::IntStrategy < CustomValue::FormatStrategy
+ include ActionView::Helpers::NumberHelper
+
def typed_value
- if value.present?
- value.to_i
- end
+ value.to_i if value.present?
+ end
+
+ def formatted_value
+ return "" if value.blank?
+
+ number_with_delimiter(value.to_s)
end
def validate_type_of_value
diff --git a/spec/models/custom_value/int_strategy_spec.rb b/spec/models/custom_value/int_strategy_spec.rb
index f9c21d93f0a..fad37d92806 100644
--- a/spec/models/custom_value/int_strategy_spec.rb
+++ b/spec/models/custom_value/int_strategy_spec.rb
@@ -37,8 +37,14 @@ RSpec.describe CustomValue::IntStrategy do
describe "#typed_value" do
subject { instance.typed_value }
+ context "when value is an int string" do
+ let(:value) { "12" }
+
+ it { is_expected.to be(12) }
+ end
+
context "when value is a float string" do
- let(:value) { "10" }
+ let(:value) { "10.0" }
it { is_expected.to be(10) }
end
@@ -62,19 +68,31 @@ RSpec.describe CustomValue::IntStrategy do
context "when value is an int string" do
let(:value) { "10" }
- it { is_expected.to be(10) }
+ it { is_expected.to eql("10") }
+ end
+
+ context "when value is a big integer" do
+ let(:value) { "10432501" }
+
+ it { is_expected.to eql("10,432,501") }
+
+ it "is localized" do
+ I18n.with_locale(:de) do
+ expect(subject).to eql "10.432.501"
+ end
+ end
end
context "when value is blank" do
let(:value) { "" }
- it { is_expected.to be_nil }
+ it { is_expected.to be("") }
end
context "when value is nil" do
let(:value) { nil }
- it { is_expected.to be_nil }
+ it { is_expected.to be("") }
end
end