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
Changing the where into a find to avoid random weird ordering (#17435)
Marcello Rochabb7daa8fa59a
diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 4a7cc7f32a6..af22402a037 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2369,6 +2369,7 @@ en:label_delete: "Delete"label_deleted: "deleted"label_deleted_custom_field: "(deleted custom field)"+ label_deleted_custom_item: "(deleted item)"label_deleted_custom_option: "(deleted option)"label_empty_element: "(empty)"label_missing_or_hidden_custom_option: "(missing value or lacking permissions to access)"diff --git a/lib/open_project/journal_formatter/custom_field/plain.rb b/lib/open_project/journal_formatter/custom_field/plain.rbindex a0ed17f05b2..a7a94fd3dbb 100644--- a/lib/open_project/journal_formatter/custom_field/plain.rb+++ b/lib/open_project/journal_formatter/custom_field/plain.rb@@ -93,10 +93,12 @@ class OpenProject::JournalFormatter::CustomField::Plain < JournalFormatter::Basedef find_item_value(value, _custom_field)ids = value.split(",").map(&:to_i)- CustomField::Hierarchy::Item.where(id: ids).map do |item|- next I18n.t(:label_deleted_custom_option) unless ids.include?(item.id)+ items = CustomField::Hierarchy::Item.where(id: ids).index_by(&:id)- item.ancestry_path+ ids.map do |id|+ next I18n.t(:label_deleted_custom_item) unless items[id]++ items[id].ancestry_pathend.join(", ")enddiff --git a/spec/lib/journal_formatter/custom_field_spec.rb b/spec/lib/journal_formatter/custom_field_spec.rbindex e86d3fb9099..9287ee05557 100644--- a/spec/lib/journal_formatter/custom_field_spec.rb+++ b/spec/lib/journal_formatter/custom_field_spec.rb@@ -469,6 +469,22 @@ RSpec.describe OpenProject::JournalFormatter::CustomField doit { expect(rendered).to be_html_eql(expected) }end++ describe "with a deleted item" do+ let(:values) { [[luke.id, -100].join(","), luke.id.to_s] }+ let(:original_value) { [luke.ancestry_path, I18n.t(:label_deleted_custom_item)].join(", ") }+ let(:formatted_value) { luke.ancestry_path }++ let(:expected) do+ I18n.t(:text_journal_changed_plain,+ label: "<strong>#{custom_field.name}</strong>",+ linebreak: "",+ old: "<i>#{original_value}</i>",+ new: "<i>#{formatted_value}</i>")+ end++ it { expect(rendered).to be_html_eql(expected) }+ endendendend