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
Implement models instead of hashes as journal changes
Klaus Zanderse82c4f37156a
diff --git a/app/models/journal/caused_by_work_package_child_change.rb b/app/models/journal/caused_by_work_package_child_change.rbnew file mode 100644index 00000000000..2f5e083fb1b--- /dev/null+++ b/app/models/journal/caused_by_work_package_child_change.rb@@ -0,0 +1,36 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#+++#+class Journal::CausedByWorkPackageChildChange < CauseOfChange::Base+ def initialize(work_package)+ additional = {+ "work_package_id" => work_package.id+ }+ super('work_package_children_changed_times', additional)+ end+enddiff --git a/app/models/journal/caused_by_work_package_parent_change.rb b/app/models/journal/caused_by_work_package_parent_change.rbnew file mode 100644index 00000000000..a4f67727f46--- /dev/null+++ b/app/models/journal/caused_by_work_package_parent_change.rb@@ -0,0 +1,36 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++class Journal::CausedByWorkPackageParentChange < CauseOfChange::Base+ def initialize(work_package)+ additional = {+ "work_package_id" => work_package.id+ }+ super('work_package_parent_changed_times', additional)+ end+enddiff --git a/app/models/journal/caused_by_work_package_predecessor_change.rb b/app/models/journal/caused_by_work_package_predecessor_change.rbnew file mode 100644index 00000000000..0227fd5c360--- /dev/null+++ b/app/models/journal/caused_by_work_package_predecessor_change.rb@@ -0,0 +1,36 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++class Journal::CausedByWorkPackagePredecessorChange < CauseOfChange::Base+ def initialize(work_package)+ additional = {+ "work_package_id" => work_package.id+ }+ super('work_package_predecessor_changed_times', additional)+ end+enddiff --git a/app/models/journal/caused_by_work_package_related_change.rb b/app/models/journal/caused_by_work_package_related_change.rbnew file mode 100644index 00000000000..68a38e5a15c--- /dev/null+++ b/app/models/journal/caused_by_work_package_related_change.rb@@ -0,0 +1,36 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++class Journal::CausedByWorkPackageRelatedChange < CauseOfChange::Base+ def initialize(work_package:)+ additional = {+ "work_package_id" => work_package.id+ }+ super('work_package_related_changed_times', additional)+ end+enddiff --git a/app/models/journal/caused_by_working_day_changes.rb b/app/models/journal/caused_by_working_day_changes.rbnew file mode 100644index 00000000000..ef27187ad77--- /dev/null+++ b/app/models/journal/caused_by_working_day_changes.rb@@ -0,0 +1,39 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++class Journal::CausedByWorkingDayChanges < CauseOfChange::Base+ def initialize(working_days:, non_working_days:)+ additional = {+ "changed_days" => {+ "working_days" => working_days,+ "non_working_days" => non_working_days.transform_keys(&:iso8601)+ }+ }+ super('working_days_changed', additional)+ end+enddiff --git a/app/services/journals/create_service.rb b/app/services/journals/create_service.rbindex 86e36fa9d17..b002ad97548 100644--- a/app/services/journals/create_service.rb+++ b/app/services/journals/create_service.rb@@ -48,13 +48,9 @@ module Journalsself.journable = journableend- def call(notes: "", cause: {})- # JSON columns read from the database always have string keys. As we do not know what is passed in here,- # and we want to compare it to values read from the DB, we need to stringify the keys here as well- normalized_cause = cause.deep_stringify_keys-+ def call(notes: "", cause: CauseOfChange::NoCause.new)Journal.transaction do- journal = create_journal(notes, normalized_cause)+ journal = create_journal(notes, cause)if journalreload_journals@@ -270,28 +266,28 @@ module Journalsdef cleanup_predecessor_attachable(predecessor)cleanup_predecessor(predecessor,- 'attachable_journals',+ "attachable_journals",:journal_id,:id)enddef cleanup_predecessor_customizable(predecessor)cleanup_predecessor(predecessor,- 'customizable_journals',+ "customizable_journals",:journal_id,:id)enddef cleanup_predecessor_storable(predecessor)cleanup_predecessor(predecessor,- 'storages_file_links_journals',+ "storages_file_links_journals",:journal_id,:id)enddef cleanup_predecessor_agenda_itemable(predecessor)cleanup_predecessor(predecessor,- 'meeting_agenda_item_journals',+ "meeting_agenda_item_journals",:journal_id,:id)end@@ -817,7 +813,7 @@ module JournalsSQLend- data_changes.join(' OR ')+ data_changes.join(" OR ")enddef only_on_changed_or_forced_condition_sql(predecessor, notes, cause)@@ -835,17 +831,17 @@ module Journalsdef data_sink_columnstext_columns = text_column_names- (journable.journaled_columns_names - text_columns + text_columns).join(', ')+ (journable.journaled_columns_names - text_columns + text_columns).join(", ")enddef data_source_columnstext_columns = text_column_namesnormalized_text_columns = text_columns.map { |column| normalize_newlines_sql(column) }- (journable.journaled_columns_names - text_columns + normalized_text_columns).join(', ')+ (journable.journaled_columns_names - text_columns + normalized_text_columns).join(", ")enddef journable_data_sql_addition- journable.class.aaj_options[:data_sql]&.call(journable) || ''+ journable.class.aaj_options[:data_sql]&.call(journable) || ""enddef text_column_names@@ -874,7 +870,7 @@ module Journalsdef cause_sql(cause)# Using the same encoder mechanism that ActiveRecord uses for json/jsonb columns- ActiveSupport::JSON.encode(cause || {})+ ActiveSupport::JSON.encode(cause&.to_h || {})end# Because we added the journal via bare metal sql, rails does not yet@@ -910,7 +906,7 @@ module Journalsenddef same_cause?(predecessor, cause)- (predecessor.cause.blank? && cause.blank?) || predecessor.cause == cause+ (predecessor.cause.blank? && cause.blank?) || predecessor.cause == cause.to_henddef log_journal_creation(predecessor)diff --git a/app/services/work_packages/set_schedule_service.rb b/app/services/work_packages/set_schedule_service.rbindex 57a966818f5..a27d13e680c 100644--- a/app/services/work_packages/set_schedule_service.rb+++ b/app/services/work_packages/set_schedule_service.rb@@ -185,32 +185,19 @@ class WorkPackages::SetScheduleServiceif initiated_by.is_a?(WorkPackage)assign_cause_initiated_by_work_package(work_package, relation)- elsif initiated_by.is_a?(Journal::WorkingDayUpdate)- assign_cause_initiated_by_changed_working_days(work_package)+ elsif initiated_by.is_a?(CauseOfChange::Base)+ work_package.journal_cause = initiated_byendenddef assign_cause_initiated_by_work_package(work_package, _relation)# For now we only track a generic cause, and not a specialized reason depending on the relation- #- # type_mapping = {- # parent: 'work_package_parent_changed_times',- # children: 'work_package_children_changed_times',- # predecessor: 'work_package_predecessor_changed_times',- # related: 'work_package_related_changed_times'- # }- # work_package.journal_cause = { "type" => type_mapping[relation], "work_package_id" => initiated_by.id }-- work_package.journal_cause = {- "type" => "work_package_related_changed_times",- "work_package_id" => initiated_by.id- }- end+ # work_package.journal_cause = case relation+ # when :parent then Journal::CausedByWorkPackageParentChange.new(initiated_by)+ # when :children then Journal::CausedByWorkPackageChildChange.new(initiated_by)+ # when :predecessor then Journal::CausedByWorkPackagePredecessorChange.new(initiated_by)+ # end- def assign_cause_initiated_by_changed_working_days(work_package)- work_package.journal_cause = {- "type" => 'working_days_changed',- "changed_days" => initiated_by.to_h- }+ work_package.journal_cause = Journal::CausedByWorkPackageRelatedChange.new(work_package: initiated_by)endenddiff --git a/app/services/work_packages/update_service.rb b/app/services/work_packages/update_service.rbindex d9216515520..7865485a118 100644--- a/app/services/work_packages/update_service.rb+++ b/app/services/work_packages/update_service.rb@@ -30,11 +30,11 @@ class WorkPackages::UpdateService < BaseServices::Updateinclude ::WorkPackages::Shared::UpdateAncestorsinclude Attachments::ReplaceAttachments- attr_accessor :cause_of_update+ attr_accessor :cause_of_rescheduling- def initialize(user:, model:, contract_class: nil, contract_options: {}, cause_of_update: nil)+ def initialize(user:, model:, contract_class: nil, contract_options: {}, cause_of_rescheduling: nil)super(user:, model:, contract_class:, contract_options:)- self.cause_of_update = cause_of_update || model+ self.cause_of_rescheduling = cause_of_rescheduling || modelendprivate@@ -135,7 +135,7 @@ class WorkPackages::UpdateService < BaseServices::Updatedef reschedule(work_package, work_packages)WorkPackages::SetScheduleService- .new(user:, work_package: work_packages, initiated_by: cause_of_update)+ .new(user:, work_package: work_packages, initiated_by: cause_of_rescheduling).call(work_package.saved_changes.keys.map(&:to_sym))enddiff --git a/app/workers/work_packages/apply_working_days_change_job.rb b/app/workers/work_packages/apply_working_days_change_job.rbindex bc362b92e69..8b4f1799237 100644--- a/app/workers/work_packages/apply_working_days_change_job.rb+++ b/app/workers/work_packages/apply_working_days_change_job.rb@@ -38,9 +38,9 @@ class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJobuser = User.find(user_id)User.execute_as user do- wd_update = Journal::WorkingDayUpdate.new(+ wd_update = Journal::CausedByWorkingDayChanges.new(working_days: changed_days(previous_working_days),- non_working_days: changed_non_working_dates(previous_non_working_days).transform_keys(&:iso8601)+ non_working_days: changed_non_working_dates(previous_non_working_days))updated_work_package_ids = collect_id_for_each(applicable_work_package(previous_working_days,@@ -56,14 +56,9 @@ class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJobprivate- def apply_change_to_work_package(user, work_package, changed_working_days)- cause = {- "type" => "working_days_changed",- "changed_days" => changed_working_days.to_h- }-+ def apply_change_to_work_package(user, work_package, cause)WorkPackages::UpdateService- .new(user:, model: work_package, contract_class: EmptyContract, cause_of_update: changed_working_days)+ .new(user:, model: work_package, contract_class: EmptyContract, cause_of_rescheduling: cause).call(duration: work_package.duration, journal_cause: cause) # trigger a recomputation of start and due date.all_resultsenddiff --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.rbindex 863115e2c16..61a76ca3603 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::Journalizedendend- def add_journal(user: User.current, notes: '', cause: {})+ def add_journal(user: User.current, notes: '', cause: CauseOfChange::NoCause.new)self.journal_user ||= userself.journal_notes ||= notesself.journal_cause ||= cause@@ -84,7 +84,7 @@ module Acts::Journalizeddef with_ensured_journal_attributesself.journal_user ||= User.currentself.journal_notes ||= ''- self.journal_cause ||= {}+ self.journal_cause ||= CauseOfChange::NoCause.newyieldensurediff --git a/lib_static/plugins/acts_as_journalized/lib/acts_as_journalized.rb b/lib_static/plugins/acts_as_journalized/lib/acts_as_journalized.rbindex 045275ea70a..0c5862d6362 100644--- a/lib_static/plugins/acts_as_journalized/lib/acts_as_journalized.rb+++ b/lib_static/plugins/acts_as_journalized/lib/acts_as_journalized.rb@@ -47,6 +47,7 @@require 'journal_changes'require 'journal_formatter'+require 'cause_of_change'module Actsenddiff --git a/lib_static/plugins/acts_as_journalized/lib/cause_of_change.rb b/lib_static/plugins/acts_as_journalized/lib/cause_of_change.rbnew file mode 100644index 00000000000..c7294d844ce--- /dev/null+++ b/lib_static/plugins/acts_as_journalized/lib/cause_of_change.rb@@ -0,0 +1,52 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++# This file is part of the acts_as_journalized plugin for the redMine+# project management software+#+# Copyright (C) 2010 Finn GmbH, http://finn.de+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either journal 2+# of the License, or (at your option) any later journal.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.++require_relative 'cause_of_change/base'+require_relative 'cause_of_change/no_cause'++module CauseOfChange+enddiff --git a/lib_static/plugins/acts_as_journalized/lib/cause_of_change/base.rb b/lib_static/plugins/acts_as_journalized/lib/cause_of_change/base.rbnew file mode 100644index 00000000000..40e1b610611--- /dev/null+++ b/lib_static/plugins/acts_as_journalized/lib/cause_of_change/base.rb@@ -0,0 +1,56 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module CauseOfChange+ class Base+ attr_reader :type, :additional_attributes++ def initialize(type, additional_attributes = {})+ @type = type+ @additional_attributes = additional_attributes+ end++ def to_h+ { "type" => type }.merge(additional_attributes).deep_stringify_keys+ end++ def blank?+ false+ end++ def ==(other)+ if other.is_a?(Hash)+ to_h == other+ else+ other.class == self.class &&+ type == other.type &&+ additional_attributes == other.additional_attributes+ end+ end+ end+enddiff --git a/lib_static/plugins/acts_as_journalized/lib/cause_of_change/no_cause.rb b/lib_static/plugins/acts_as_journalized/lib/cause_of_change/no_cause.rbnew file mode 100644index 00000000000..e79ded31956--- /dev/null+++ b/lib_static/plugins/acts_as_journalized/lib/cause_of_change/no_cause.rb@@ -0,0 +1,43 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module CauseOfChange+ class NoCause < Base+ def initialize+ super(nil)+ end++ def blank?+ true+ end++ def to_h+ {}+ end+ end+enddiff --git a/spec/models/work_package/work_package_acts_as_journalized_spec.rb b/spec/models/work_package/work_package_acts_as_journalized_spec.rbindex 2eaf8f8d858..58d2229e218 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@@ -48,6 +48,7 @@ RSpec.describe WorkPackage doduration: 1)endend+ let(:other_work_package) { build_stubbed(:work_package) }current_user { create(:user) }@@ -510,17 +511,17 @@ RSpec.describe WorkPackage dosubject dowork_package.add_journal(user: User.current,- cause: {- type: 'some cause',- work_package_id: 42- }+ cause: Journal::CausedByWorkPackagePredecessorChange.new(other_work_package))work_package.savework_packageendit 'has the cause logged in the last journal' do- expect(subject.last_journal.cause).to eql({ 'type' => 'some cause', 'work_package_id' => 42 })+ expect(subject.last_journal.cause).to eql({+ 'type' => 'work_package_predecessor_changed_times',+ 'work_package_id' => other_work_package.id+ })endit 'has the timestamp of the work package update time for created_at' do@@ -541,10 +542,7 @@ RSpec.describe WorkPackage dowork_package.add_journal(user: User.current,notes: 'some notes',- cause: {- type: 'work_package_predecessor_changed_times',- work_package_id: 42- }+ cause: Journal::CausedByWorkPackagePredecessorChange.new(other_work_package))work_package.subject = 'blubs'work_package.save@@ -570,7 +568,7 @@ RSpec.describe WorkPackage doexpect(work_package.last_journal.notes).to eq('some notes')expect(work_package.last_journal.cause_type).to eq('work_package_predecessor_changed_times')- expect(work_package.last_journal.cause_work_package_id).to eq(42)+ expect(work_package.last_journal.cause_work_package_id).to eq(other_work_package.id)endend@@ -578,10 +576,7 @@ RSpec.describe WorkPackage dobefore dowork_package.add_journal(user: User.current,- cause: {- type: 'work_package_predecessor_changed_times',- work_package_id: 42- }+ cause: Journal::CausedByWorkPackagePredecessorChange.new(other_work_package))work_package.subject = "new subject 1"work_package.save@@ -590,10 +585,7 @@ RSpec.describe WorkPackage dosubject dowork_package.add_journal(user: User.current,- cause: {- type: 'work_package_predecessor_changed_times',- work_package_id: 42- }+ cause: Journal::CausedByWorkPackagePredecessorChange.new(other_work_package))work_package.subject = "new subject 2"work_package.save@@ -608,7 +600,7 @@ RSpec.describe WorkPackage doexpect(work_package.last_journal.new_value_for(:subject)).to eq('new subject 2')expect(work_package.last_journal.cause_type).to eq('work_package_predecessor_changed_times')- expect(work_package.last_journal.cause_work_package_id).to eq(42)+ expect(work_package.last_journal.cause_work_package_id).to eq(other_work_package.id)endenddiff --git a/spec/services/work_packages/set_schedule_service_spec.rb b/spec/services/work_packages/set_schedule_service_spec.rbindex 8062b24e560..cbae618927a 100644--- a/spec/services/work_packages/set_schedule_service_spec.rb+++ b/spec/services/work_packages/set_schedule_service_spec.rb@@ -141,11 +141,12 @@ RSpec.describe WorkPackages::SetScheduleService do.to be_present,"Expected work package ##{wp.id} '#{wp.subject}' to be rescheduled"- expect(result.journal_cause['work_package_id'])+ expect(result.journal_cause.additional_attributes["work_package_id"]).to eql(initiating_work_package.id),- "Expected work package change to ##{wp.id} to have been caused by ##{initiating_work_package.id}."+ "Expected work package change to ##{wp.id} to have been caused by ##{initiating_work_package.id}, but " \+ "it was caused by ##{result.journal_cause.additional_attributes[:work_package_id]}."- expect(result.journal_cause['type'])+ expect(result.journal_cause.type).to eql("work_package_related_changed_times"),"Expected work package change to ##{wp.id} to have been caused because ##{expected_cause_type}."