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

at_timestamp: handle asking for work packages with specific ids

Sebastian Fiedlschusterebad1063fe2c
diff --git a/app/models/journable/historic_active_record_relation.rb b/app/models/journable/historic_active_record_relation.rb
index c26afcb1563..1bcec40baa7 100644
--- a/app/models/journable/historic_active_record_relation.rb
+++ b/app/models/journable/historic_active_record_relation.rb
@@ -78,7 +78,12 @@ class Journable::HistoricActiveRecordRelation < ActiveRecord::Relation
if predicate.kind_of? String
predicate.gsub! "#{model.table_name}.", "#{model.journal_class.table_name}."
elsif predicate.left.relation == self.arel_table
+ if predicate.right.respond_to? :name and predicate.right.name == "id"
+ predicate.right.instance_variable_set(:@name, "journable_id")
+ predicate.left.relation = Journal.arel_table
+ else
predicate.left.relation = self.journal_class.arel_table
+ end
end
end
diff --git a/spec/models/journable/timestamps_spec.rb b/spec/models/journable/timestamps_spec.rb
index 9c68c63984a..5af8db315fd 100644
--- a/spec/models/journable/timestamps_spec.rb
+++ b/spec/models/journable/timestamps_spec.rb
@@ -405,6 +405,21 @@ describe Journable::Timestamps, type: :model do
end
end
+ describe "when chaining where(id:) in order to request specific work packages at a specific point in time" do
+ subject { WorkPackage.where(id: [work_package.id]).at_timestamp(@wednesday) }
+
+ it "returns the work packages in their state at the requested point in time" do
+ expect(subject.first.description).to eq "The work package as it has been on Wednesday"
+ end
+
+ describe "when the work package does not exist at the requested time" do
+ subject { WorkPackage.where(id: [work_package.id]).at_timestamp(@before_monday) }
+
+ it "returns an empty result" do
+ expect(subject.count).to eq 0
+ end
+ end
+ end
describe "when chaining a sql where clause (as used by Query#statement)" do
subject { WorkPackage.where("(work_packages.description ILIKE '%been on Wednesday%')").at_timestamp(@wednesday) }