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

historic journables: raise warning when accessing non-journalized columns

Sebastian Fiedlschusterfe8ff8a1c12c
diff --git a/app/models/journable/timestamps.rb b/app/models/journable/timestamps.rb
index e5c0b264626..2f66c02cdcb 100644
--- a/app/models/journable/timestamps.rb
+++ b/app/models/journable/timestamps.rb
@@ -70,6 +70,18 @@ module Journable::Timestamps
end
end
+ prepended do
+ column_names_missing_in_journal.each do |missing_column_name|
+ define_method missing_column_name do
+ if historic?
+ Rails.logger.warn "Accessing missing column '#{missing_column_name}' on historic data. " \
+ "The column is not present in the '#{self.class.journal_class.table_name}' table."
+ end
+ super()
+ end
+ end
+ end
+
# Instantiates a journable with historic data from the given timestap.
#
# WorkPackage.find(1).at_timestamp(1.year.ago)
diff --git a/spec/models/journable/timestamps_spec.rb b/spec/models/journable/timestamps_spec.rb
index f410d976f29..2a83cc8bad5 100644
--- a/spec/models/journable/timestamps_spec.rb
+++ b/spec/models/journable/timestamps_spec.rb
@@ -640,5 +640,50 @@ describe Journable::Timestamps do
end
end
end
+
+ describe "#position (unjournalized column)" do
+ let(:timestamp) { monday }
+ let(:position) { 42 }
+
+ before do
+ work_package.update_attribute :position, position
+ end
+
+ describe "when retrieving the position of the current (nin-historic) record" do
+ subject { work_package.position }
+
+ it "returns the value of the work_packages table" do
+ expect(subject).to eq position
+ end
+
+ it "does not raise an error" do
+ expect { subject }.not_to raise_error
+ end
+
+ it "does not print a warning" do
+ allow(Rails.logger).to receive(:warn)
+ subject
+ expect(Rails.logger).not_to have_received(:warn).with(/position/)
+ end
+ end
+
+ describe "when retrieving the position of a historic record" do
+ subject { work_package.at_timestamp(timestamp).position }
+
+ it "returns nil" do
+ expect(subject).to be_nil
+ end
+
+ it "does not raise an error" do
+ expect { subject }.not_to raise_error
+ end
+
+ it "prints a warning" do
+ allow(Rails.logger).to receive(:warn)
+ subject
+ expect(Rails.logger).to have_received(:warn).with(/position/)
+ end
+ end
+ end
end
end