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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#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.rbindex 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)enddef validate_type_of_valuediff --git a/spec/models/custom_value/int_strategy_spec.rb b/spec/models/custom_value/int_strategy_spec.rbindex 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 dodescribe "#typed_value" dosubject { 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 docontext "when value is an int string" dolet(: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+ endendcontext "when value is blank" dolet(:value) { "" }- it { is_expected.to be_nil }+ it { is_expected.to be("") }endcontext "when value is nil" dolet(:value) { nil }- it { is_expected.to be_nil }+ it { is_expected.to be("") }endend