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

use touch_and_save_journals

Ivan Kuchin7b93b6072e4e
diff --git a/app/controllers/projects/settings/life_cycle_steps_controller.rb b/app/controllers/projects/settings/life_cycle_steps_controller.rb
index 60810b54dbd..89f04991572 100644
--- a/app/controllers/projects/settings/life_cycle_steps_controller.rb
+++ b/app/controllers/projects/settings/life_cycle_steps_controller.rb
@@ -78,6 +78,6 @@ class Projects::Settings::LifeCycleStepsController < Projects::SettingsControlle
unique_by: %i[project_id definition_id]
)
- @project.save_journals
+ @project.touch_and_save_journals
end
end
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 239a673c998..e4ba7ae01a6 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,6 +73,11 @@ module Acts::Journalized
end
end
+ def touch_and_save_journals
+ update_column(:updated_at, Time.current)
+ save_journals
+ end
+
def add_journal(user: User.current, notes: "", cause: CauseOfChange::NoCause.new)
self.journal_user ||= user
self.journal_notes ||= notes
diff --git a/modules/meeting/app/models/meeting/journalized.rb b/modules/meeting/app/models/meeting/journalized.rb
index 5e7f067102d..00c1105732f 100644
--- a/modules/meeting/app/models/meeting/journalized.rb
+++ b/modules/meeting/app/models/meeting/journalized.rb
@@ -54,10 +54,5 @@ module Meeting::Journalized
register_journal_formatted_fields /agenda_items_\d+_duration_in_minutes/, formatter_key: :agenda_item_duration
register_journal_formatted_fields "position", formatter_key: :agenda_item_position
register_journal_formatted_fields /agenda_items_\d+_work_package_id/, formatter_key: :meeting_work_package_id
-
- def touch_and_save_journals
- update_column(:updated_at, Time.current)
- save_journals
- end
end
end
diff --git a/spec/models/projects/project_acts_as_journalized_spec.rb b/spec/models/projects/project_acts_as_journalized_spec.rb
index de9dc3c1863..7cb1c26f6e0 100644
--- a/spec/models/projects/project_acts_as_journalized_spec.rb
+++ b/spec/models/projects/project_acts_as_journalized_spec.rb
@@ -364,6 +364,30 @@ RSpec.describe Project, "acts_as_journalized" do
)
end
end
+
+ describe "when creating without touching project" do
+ let!(:project) do
+ Timecop.freeze(1.year.ago) do
+ create(:project)
+ end
+ end
+
+ before do
+ create(:project_gate, project_id: project.id)
+ end
+
+ it "fails when using save_journals" do
+ expect do
+ project.save_journals
+ end.to raise_error(ActiveRecord::StatementInvalid)
+ end
+
+ it "succeeds when using touch_and_save_journals" do
+ expect do
+ project.touch_and_save_journals
+ end.to change { project.journals.count }.from(1).to(2)
+ end
+ end
end
describe "on project deletion" do