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
correct journalizing noops
ulferts0f29e0d52202
diff --git a/app/services/journals/create_service.rb b/app/services/journals/create_service.rbindex bc03e43c96b..4afa3a8f183 100644--- a/app/services/journals/create_service.rb+++ b/app/services/journals/create_service.rb@@ -176,7 +176,7 @@ module Journals), fetch_time AS (#{fetch_time_sql}), insert_data AS (- #{insert_data_sql(notes, cause)}+ #{insert_data_sql(predecessor, notes, cause)}), update_predecessor AS (#{update_predecessor_sql(predecessor, notes, cause)}), inserted_journal AS (@@ -304,7 +304,7 @@ module Journalsdata_type: journable.class.journal_class.name)end- def insert_data_sql(notes, cause)+ def insert_data_sql(predecessor, notes, cause)data_sql = <<~SQLINSERT INTO#{data_table_name} (@@ -316,7 +316,7 @@ module Journals#{journable_data_sql_addition}WHERE#{journable_table_name}.id = :journable_id- #{only_on_changed_or_forced_condition_sql(notes, cause)}+ #{only_on_changed_or_forced_condition_sql(predecessor, notes, cause)}RETURNING *SQL@@ -397,7 +397,7 @@ module Journalsupdated_at = COALESCE(:update_timestamp, statement_timestamp())WHEREid = :id- #{only_on_changed_or_forced_condition_sql(notes, cause)}+ #{only_on_changed_or_forced_condition_sql(predecessor, notes, cause)}AND NOT updated_at > COALESCE(:predecessor_timestamp, (SELECT updated_at FROM max_journals))RETURNING updated_atSQL@@ -441,7 +441,7 @@ module Journalsvalidity_period = tstzrange(lower(validity_period), (SELECT updated_at FROM fetch_time), '[)')WHEREid = (SELECT id from max_journals)- #{only_on_changed_or_forced_condition_sql(notes, cause)}+ #{only_on_changed_or_forced_condition_sql(predecessor, notes, cause)}SQLend@@ -612,8 +612,13 @@ module Journalsdata_changes.join(' OR ')end- def only_on_changed_or_forced_condition_sql(notes, cause)- if notes.blank? && cause.blank?+ def only_on_changed_or_forced_condition_sql(predecessor, notes, cause)+ # The predecessor part of the condition is in in case the predecessor is being aggregated.+ # In one of the cases, the change that is being aggregated in nullifies the changes done by the predecessor so+ # that in effect, there would be no changes any more (compared to the predecessor's predecessor).+ # With changes being a precondition for journalizing, no journal data would be created and the predecessor+ # that is aggregated ends up having no data.+ if notes.blank? && cause.blank? && predecessor.nil?"AND EXISTS (SELECT * FROM changes)"else""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.rbindex 4274c6634d3..e20d12ece12 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@@ -801,6 +801,40 @@ RSpec.describe WorkPackage doendendend++ context 'when aggregation leads to an empty change (changing back and forth)',+ with_settings: { journal_aggregation_time_minutes: 1 } do+ let!(:work_package) do+ User.execute_as current_user do+ create(:work_package,+ :created_in_past,+ created_at: 5.minutes.ago,+ project_id: project.id,+ type:,+ description: 'Description',+ priority:,+ status:,+ duration: 1)+ end+ end++ let(:other_status) { create(:status) }++ before do+ work_package.status = other_status+ work_package.save!+ work_package.status = status+ work_package.save!+ end++ it 'creates a new journal' do+ expect(work_package.journals.count).to be 2+ end++ it 'has the old state in the last journal`s data' do+ expect(work_package.journals.last.data.status_id).to be status.id+ end+ endenddescribe '#destroy' do