use touch_and_save_journals

This commit is contained in:
Ivan Kuchin
2025-02-21 19:29:21 +01:00
parent 97c0487384
commit 7b93b6072e
4 changed files with 30 additions and 6 deletions
@@ -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
@@ -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
@@ -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
@@ -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