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

Reuse PlaintextFormatter for ProjectJournal identifier field

Christophe Bliardc4cb87b5200b
diff --git a/app/models/journal.rb b/app/models/journal.rb
index dd6a0fd07b8..6028b508b34 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -41,9 +41,6 @@ class Journal < ApplicationRecord
register_journal_formatter :ignore_non_working_days, OpenProject::JournalFormatter::IgnoreNonWorkingDays
register_journal_formatter :active_status, OpenProject::JournalFormatter::ActiveStatus
register_journal_formatter :template, OpenProject::JournalFormatter::Template
- register_journal_formatter :identifier, OpenProject::JournalFormatter::Identifier
-
-
# Make sure each journaled model instance only has unique version ids
validates :version, uniqueness: { scope: %i[journable_id journable_type] }
diff --git a/app/models/project.rb b/app/models/project.rb
index ac37aba8a49..c3932c7ea15 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -106,7 +106,7 @@ class Project < ApplicationRecord
register_on_journal_formatter(:active_status, 'active')
register_on_journal_formatter(:template, 'templated')
- register_on_journal_formatter(:identifier, 'identifier')
+ register_on_journal_formatter(:plaintext, 'identifier')
has_paper_trail
diff --git a/lib/open_project/journal_formatter/identifier.rb b/spec/factories/journal/project_journal_factory.rb
similarity index 74%
rename from lib/open_project/journal_formatter/identifier.rb
rename to spec/factories/journal/project_journal_factory.rb
index bd4f1774c87..54e5cf2f27f 100644
--- a/lib/open_project/journal_formatter/identifier.rb
+++ b/spec/factories/journal/project_journal_factory.rb
@@ -26,12 +26,6 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class OpenProject::JournalFormatter::Identifier < JournalFormatter::Base
- def render(_key, values, options = { html: true })
- binding.pry
- label_text = options[:html] ? content_tag('strong', "Template:") : "Template:"
- activated_text = values.last ? "Project un-marked as template" : "Project marked as template"
-
- I18n.t(:text_journal_label_value, label: label_text, value: activated_text)
- end
+FactoryBot.define do
+ factory :journal_project_journal, class: 'Journal::ProjectJournal'
end
diff --git a/spec/factories/journal_factory.rb b/spec/factories/journal_factory.rb
index affa2f2b798..ce3d6889b98 100644
--- a/spec/factories/journal_factory.rb
+++ b/spec/factories/journal_factory.rb
@@ -55,5 +55,10 @@ FactoryBot.define do
journable_type { 'News' }
data { build(:journal_message_journal) }
end
+
+ factory :project_journal, class: 'Journal' do
+ journable_type { 'Project' }
+ data { build(:journal_project_journal) }
+ end
end
end
diff --git a/spec/lib/journal_formatter/identifier_spec.rb b/spec/models/journal/project_journal_spec.rb
similarity index 52%
rename from spec/lib/journal_formatter/identifier_spec.rb
rename to spec/models/journal/project_journal_spec.rb
index 9720d401974..a0500ec38bc 100644
--- a/spec/lib/journal_formatter/identifier_spec.rb
+++ b/spec/models/journal/project_journal_spec.rb
@@ -26,16 +26,27 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'spec_helper'
-describe OpenProject::JournalFormatter::Identifier do
- let(:instance) { described_class.new(build(:journal)) }
+RSpec.describe Journal::ProjectJournal do
+ describe '#render_detail' do
+ it 'renders identifier field correctly' do
+ project = build(:project)
+ journal = build(:project_journal, journable: project)
- it "renders correctly when identifier is changed" do
- html = instance.render("templated", [false, true], html: true)
- expect(html).to eq("<strong>Identifier</strong> changed to []")
+ html = journal.render_detail(['identifier', [nil, 'my-project']], html: true)
+ expect(html).to eq('<strong>Identifier</strong> set to ' \
+ '<i title="my-project">my-project</i>')
- html = instance.render("templated", [false, true], html: false)
- expect(html).to eq("Identifier changed to []")
+ html = journal.render_detail(['identifier', [nil, 'my-project']], html: false)
+ expect(html).to eq('Identifier set to my-project')
+
+ html = journal.render_detail(['identifier', ['my-project', 'my-beautiful-project']], html: true)
+ expect(html).to eq('<strong>Identifier</strong> changed from <i title="my-project">my-project</i> ' \
+ '<strong>to</strong> <i title="my-beautiful-project">my-beautiful-project</i>')
+
+ html = journal.render_detail(['identifier', ['my-project', 'my-beautiful-project']], html: false)
+ expect(html).to eq('Identifier changed from my-project to my-beautiful-project')
+ end
end
end