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

Render custom fields in Project activity details

Christophe Bliardf24eb12fdbb5
diff --git a/app/models/project.rb b/app/models/project.rb
index 76757ab893f..2f1619fe851 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -111,6 +111,7 @@ class Project < ApplicationRecord
register_journal_formatted_fields(:diff, 'description')
register_journal_formatted_fields(:visibility, 'public')
register_journal_formatted_fields(:parent, 'parent_id')
+ register_journal_formatted_fields(:custom_field, /custom_fields_\d+/)
has_paper_trail
diff --git a/spec/features/activities/project_attributes_activity_spec.rb b/spec/features/activities/project_attributes_activity_spec.rb
index 7b871b2b4ce..48c2d53dc86 100644
--- a/spec/features/activities/project_attributes_activity_spec.rb
+++ b/spec/features/activities/project_attributes_activity_spec.rb
@@ -36,7 +36,7 @@ describe 'Project attributes activities' do
edit_wiki_pages
view_wiki_edits])
end
- let(:project) { create(:project, active: false, enabled_module_names: %w[activity]) }
+ let(:project) { create(:project, parent: create(:project), active: false, enabled_module_names: %w[activity]) }
# more factories available in spec/factories/custom_field_factory.rb
let!(:list_project_custom_field) { create(:list_project_custom_field) }
let!(:version_project_custom_field) { create(:version_project_custom_field) }
@@ -48,16 +48,32 @@ describe 'Project attributes activities' do
let!(:string_project_custom_field) { create(:string_project_custom_field) }
let!(:date_project_custom_field) { create(:date_project_custom_field) }
+ let(:next_version) { create(:version, project:, name: 'Turfu 2.0') }
+
current_user { user }
it 'tracks the project\'s activities', js: true do
+ previous_project_attributes = project.attributes.dup
new_project_attributes = {
- active: true,
name: 'a new project name',
description: 'a new project description',
- string_project_custom_field.attribute_name => 'a new text custom field value'
+ public: true,
+ parent: nil,
+ identifier: 'a-new-project-name',
+ active: true,
+ templated: true,
+
+ list_project_custom_field.attribute_name => list_project_custom_field.possible_values.first.id,
+ version_project_custom_field.attribute_name => next_version.id,
+ bool_project_custom_field.attribute_name => true,
+ user_project_custom_field.attribute_name => current_user.id,
+ int_project_custom_field.attribute_name => 42,
+ float_project_custom_field.attribute_name => 3.14159,
+ text_project_custom_field.attribute_name => 'a new text CF value',
+ string_project_custom_field.attribute_name => 'a new string CF value',
+ date_project_custom_field.attribute_name => Date.new(2023, 1, 31)
}
- project.update(new_project_attributes)
+ project.update!(new_project_attributes)
visit project_activity_index_path(project)
@@ -69,46 +85,25 @@ describe 'Project attributes activities' do
expect(page)
.to have_link("Project: #{project.name}")
- # expect each attribute to appear
- ### own fields
- # name
- # description
- # public
- # parent
- # identifier
- # active (project archived or active)
- # template
- ### custom fields
- # Text CF
- # Long text CF
- # Integer CF
- # Float CF
- # Boolean CF
- # Version CF
- # User CF
- # Date CF
- # List CF
-
- # or
- expect(page).to have_text('Project unarchived')
- # expect(page).to have_text('Project name changed from (old name) to (new name)')
- # expect(page).to have_text('Description changed (Details)')
- # expect(page).to have_text('Project visibility changed to (new visibility)')
- # expect(page).to have_text('Project parent changed to (new parent)')
- # expect(page).to have_text('Identifier changed to (new identifier)') # probably not needed
- # expect(page).to have_text('Template: Project marked as template')
- # # or
- # expect(page).to have_text('Template: Project un-marked as template')
+ expect(page).to have_selector('li', text: "Name changed from #{previous_project_attributes['name']} to #{project.name}")
+ expect(page).to have_selector('li', text: 'Description set (Details)')
+ expect(page).to have_selector('li', text: 'Visibility set to public')
+ # expect(page).to have_selector('li', text: 'Project parent changed to (new parent)')
+ expect(page).to have_selector('li', text: 'Project unarchived')
+ expect(page).to have_selector('li', text: "Identifier changed from #{previous_project_attributes['identifier']} " \
+ "to #{project.identifier}")
+ expect(page).to have_selector('li', text: 'Template: Project marked as template')
- # expect(page).to have_text('') # list
- # expect(page).to have_text('') # version
- # expect(page).to have_text('') # bool
- # expect(page).to have_text('') # user
- # expect(page).to have_text('') # int
- # expect(page).to have_text('') # float
- # expect(page).to have_text('a new text custom field value')
- # expect(page).to have_text('') # string
- # expect(page).to have_text('') # date
+ expect(page).to have_selector('li', text: "#{list_project_custom_field.name} " \
+ "set to #{project.send(list_project_custom_field.attribute_getter)}")
+ expect(page).to have_selector('li', text: "#{version_project_custom_field.name} set to #{next_version.name}")
+ expect(page).to have_selector('li', text: "#{bool_project_custom_field.name} set to Yes")
+ expect(page).to have_selector('li', text: "#{user_project_custom_field.name} set to #{current_user.name}")
+ expect(page).to have_selector('li', text: "#{int_project_custom_field.name} set to 42")
+ expect(page).to have_selector('li', text: "#{float_project_custom_field.name} set to 3.14159")
+ expect(page).to have_selector('li', text: "#{text_project_custom_field.name} set to\na new text CF value")
+ expect(page).to have_selector('li', text: "#{string_project_custom_field.name} set to a new string CF value")
+ expect(page).to have_selector('li', text: "#{date_project_custom_field.name} set to 01/31/2023")
end
end
end
diff --git a/spec/lib/journal_formatter/visibility_spec.rb b/spec/lib/journal_formatter/visibility_spec.rb
index 07a197bc6e2..a30fe0e370a 100644
--- a/spec/lib/journal_formatter/visibility_spec.rb
+++ b/spec/lib/journal_formatter/visibility_spec.rb
@@ -31,7 +31,7 @@ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper.rb")
describe OpenProject::JournalFormatter::Visibility do
let(:instance) { described_class.new(build(:journal)) }
- it "renders correctly when changing visibility" do
+ it "renders correctly when setting visibility" do
html = instance.render("public", [nil, true], html: true)
expect(html).to eq("<strong>Visibility</strong> set to public")
@@ -44,4 +44,18 @@ describe OpenProject::JournalFormatter::Visibility do
html = instance.render("public", [nil, false], html: false)
expect(html).to eq("Visibility set to private")
end
+
+ it "renders correctly when changing visibility" do
+ html = instance.render("public", [false, true], html: true)
+ expect(html).to eq("<strong>Visibility</strong> set to public")
+
+ html = instance.render("public", [false, true], html: false)
+ expect(html).to eq("Visibility set to public")
+
+ html = instance.render("public", [true, false], html: true)
+ expect(html).to eq("<strong>Visibility</strong> set to private")
+
+ html = instance.render("public", [true, false], html: false)
+ expect(html).to eq("Visibility set to private")
+ end
end