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

Refactor `add_jorunal` method to use keyword arguments

Klaus Zanders8380e0dcd4cf
diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index 70d4c6e8d80..c5876036e31 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -277,7 +277,7 @@ class Changeset < ApplicationRecord
def assign_openproject_user_from_comitter
self.user = repository.find_committer_user(committer)
- add_journal(user || User.anonymous, comments)
+ add_journal(user: user || User.anonymous, notes: comments)
end
# TODO: refactor to a standard helper method
diff --git a/app/services/add_work_package_note_service.rb b/app/services/add_work_package_note_service.rb
index 81b70d98a66..a30c3e839e2 100644
--- a/app/services/add_work_package_note_service.rb
+++ b/app/services/add_work_package_note_service.rb
@@ -42,7 +42,7 @@ class AddWorkPackageNoteService
def call(notes, send_notifications: nil)
Journal::NotificationConfiguration.with send_notifications do
- work_package.add_journal(user, notes)
+ work_package.add_journal(user:, notes:)
success, errors = validate_and_yield(work_package, user) do
work_package.save_journals
diff --git a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/save_hooks.rb b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/save_hooks.rb
index 20b35ab433b..99b289403b5 100644
--- a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/save_hooks.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/save_hooks.rb
@@ -73,7 +73,7 @@ module Acts::Journalized
end
end
- def add_journal(user = User.current, notes = '')
+ def add_journal(user: User.current, notes: '')
self.journal_user ||= user
self.journal_notes ||= notes
end
diff --git a/spec/features/notifications/reminder_mail_spec.rb b/spec/features/notifications/reminder_mail_spec.rb
index 9164fc00691..19be36eab17 100644
--- a/spec/features/notifications/reminder_mail_spec.rb
+++ b/spec/features/notifications/reminder_mail_spec.rb
@@ -78,7 +78,7 @@ RSpec.describe "Reminder email sending", js: true, with_cuprite: true do
</mention>
NOTE
- work_package.add_journal(other_user, note)
+ work_package.add_journal(user: other_user, notes: note)
work_package.save!
watched_work_package.subject = 'New watched work package subject'
diff --git a/spec/features/notifications/settings/immediate_reminder_spec.rb b/spec/features/notifications/settings/immediate_reminder_spec.rb
index 7ab37f05908..37f336f739b 100644
--- a/spec/features/notifications/settings/immediate_reminder_spec.rb
+++ b/spec/features/notifications/settings/immediate_reminder_spec.rb
@@ -88,7 +88,7 @@ RSpec.describe "Immediate reminder settings",
</mention>
NOTE
- work_package.add_journal(current_user, note)
+ work_package.add_journal(user: current_user, notes: note)
work_package.save!
end
diff --git a/spec/models/work_package/work_package_acts_as_journalized_spec.rb b/spec/models/work_package/work_package_acts_as_journalized_spec.rb
index 97e76640bfd..6669e332f5e 100644
--- a/spec/models/work_package/work_package_acts_as_journalized_spec.rb
+++ b/spec/models/work_package/work_package_acts_as_journalized_spec.rb
@@ -416,7 +416,7 @@ RSpec.describe WorkPackage do
context 'for only journal notes adding' do
before do
- work_package.add_journal(User.current, 'some notes')
+ work_package.add_journal(user: User.current, notes: 'some notes')
work_package.save
end
@@ -428,7 +428,7 @@ RSpec.describe WorkPackage do
context 'for mixed journal notes and attribute adding' do
before do
- work_package.add_journal(User.current, 'some notes')
+ work_package.add_journal(user: User.current, notes: 'some notes')
work_package.subject = 'blubs'
work_package.save
end
@@ -494,7 +494,7 @@ RSpec.describe WorkPackage do
let(:second_notes) { 'Another comment, unrelated to the first one.' }
before do
- work_package.add_journal(new_author, second_notes)
+ work_package.add_journal(user: new_author, notes: second_notes)
work_package.save!
end
diff --git a/spec/services/attachments/delete_service_integration_spec.rb b/spec/services/attachments/delete_service_integration_spec.rb
index 7cb2df58c33..92b79a481b7 100644
--- a/spec/services/attachments/delete_service_integration_spec.rb
+++ b/spec/services/attachments/delete_service_integration_spec.rb
@@ -71,7 +71,7 @@ RSpec.describe Attachments::DeleteService, 'integration', with_settings: { journ
before do
# Force to have a journal for the attachment
attachment
- container.add_journal(user)
+ container.add_journal(user:)
container.save!
call
@@ -86,7 +86,7 @@ RSpec.describe Attachments::DeleteService, 'integration', with_settings: { journ
before do
# Force to have a journal for the attachment
attachment
- container.add_journal(user, 'Some notes')
+ container.add_journal(user:, notes: 'Some notes')
container.save!
# have an invalid work package
diff --git a/spec/services/notifications/create_from_model_service_work_package_spec.rb b/spec/services/notifications/create_from_model_service_work_package_spec.rb
index 4a48a3573a0..0f7e9a15af5 100644
--- a/spec/services/notifications/create_from_model_service_work_package_spec.rb
+++ b/spec/services/notifications/create_from_model_service_work_package_spec.rb
@@ -67,7 +67,7 @@ RSpec.describe Notifications::CreateFromModelService,
let(:resource) { work_package }
let(:journal) { work_package.journals.first }
let(:journal_2_with_notes) do
- work_package.add_journal author, 'something I have to say'
+ work_package.add_journal user: author, notes: 'something I have to say'
work_package.save(validate: false)
work_package.journals.last
end
@@ -1108,7 +1108,7 @@ RSpec.describe Notifications::CreateFromModelService,
end
expect(call.all_results)
- .to match_array([notification_group_recipient, notification_other_recipient])
+ .to contain_exactly(notification_group_recipient, notification_other_recipient)
end
end
end
@@ -1117,7 +1117,7 @@ RSpec.describe Notifications::CreateFromModelService,
describe 'in the journal notes' do
let(:journal) { journal_2_with_notes }
let(:journal_2_with_notes) do
- work_package.add_journal author, note
+ work_package.add_journal user: author, notes: note
work_package.save(validate: false)
work_package.journals.last
end