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

salvage specs for fetching for a timestamp where the wp did not exist yet

ulfertsc028d139e8ea
diff --git a/app/models/journable/with_historic_attributes.rb b/app/models/journable/with_historic_attributes.rb
index 835e7257d9f..bdcb6c39554 100644
--- a/app/models/journable/with_historic_attributes.rb
+++ b/app/models/journable/with_historic_attributes.rb
@@ -115,9 +115,14 @@ class Journable::WithHistoricAttributes < SimpleDelegator
def wrap_each_journable(journables, timestamps:, query:, include_only_changed_attributes:)
loader = Loader.new(journables)
- journables = loader.at_timestamp(timestamps.last).values if timestamps.last.try(:historic?)
- journables.map { |j| new(j, timestamps:, query:, include_only_changed_attributes:, loader:) }
+ journables.map do |journable|
+ if timestamps.last.try(:historic?)
+ journable = loader.journable_at_timestamp(journable, timestamps.last) || WorkPackage.new(id: journable.id)
+ end
+
+ new(journable, timestamps:, query:, include_only_changed_attributes:, loader:)
+ end
end
end
@@ -182,7 +187,7 @@ class Journable::WithHistoricAttributes < SimpleDelegator
end
def attributes
- __getobj__.try(:attributes)
+ __getobj__.new_record? ? {} : __getobj__.attributes
end
def to_ary
diff --git a/app/models/journable/with_historic_attributes/loader.rb b/app/models/journable/with_historic_attributes/loader.rb
index 6f8096d10e0..cbc24887068 100644
--- a/app/models/journable/with_historic_attributes/loader.rb
+++ b/app/models/journable/with_historic_attributes/loader.rb
@@ -33,7 +33,7 @@ class Journable::WithHistoricAttributes
end
def journable_at_timestamp(journable, timestamp)
- at_timestamp(timestamp)[journable.id]
+ at_timestamp(timestamp)[journable&.id]
end
def at_timestamp(timestamp)
diff --git a/spec/models/journable/with_historic_attributes_spec.rb b/spec/models/journable/with_historic_attributes_spec.rb
index f9fcd9a90d0..705b2afac1d 100644
--- a/spec/models/journable/with_historic_attributes_spec.rb
+++ b/spec/models/journable/with_historic_attributes_spec.rb
@@ -126,7 +126,7 @@ describe Journable::WithHistoricAttributes do
end
end
- context "with an AR of work packages" do
+ context "with active record relation of work packages" do
let(:work_packages) { WorkPackage.all }
it "returns an array of Journable::WithHistoricAttributes instances" do
@@ -158,6 +158,14 @@ describe Journable::WithHistoricAttributes do
expect(subject.subject).to eq "The current work package 1"
end
end
+
+ describe "when the work package did not exist at the only requested date" do
+ let(:timestamps) { [Timestamp.parse("2021-01-01T00:00:00Z")] }
+
+ it "has no attributes" do
+ expect(subject.attributes).to be_empty
+ end
+ end
end
context "with an array of work packages" do
@@ -168,7 +176,7 @@ describe Journable::WithHistoricAttributes do
end
end
- context "with an AR of work packages" do
+ context "with active record relation of work packages" do
let(:work_packages) { WorkPackage.all }
it "provides access to the work-package attributes" do
@@ -222,6 +230,14 @@ describe Journable::WithHistoricAttributes do
expect(subject.attributes_by_timestamp["2021-01-01T00:00:00Z"]).to be_nil
end
end
+
+ describe "when the work package did not exist at the only requested date" do
+ let(:timestamps) { [Timestamp.parse("2021-01-01T00:00:00Z")] }
+
+ it "has no attributes at the baseline date, which is the only given date" do
+ expect(subject.attributes_by_timestamp["2021-01-01T00:00:00Z"]).to be_nil
+ end
+ end
end
context "with an array of work packages" do
@@ -257,7 +273,7 @@ describe Journable::WithHistoricAttributes do
end
end
- context "with an AR of work packages" do
+ context "with active record relation of work packages" do
let(:work_packages) { WorkPackage.all }
it "provides access to the work-package attributes at timestamps" do
@@ -340,6 +356,14 @@ describe Journable::WithHistoricAttributes do
expect(subject.exists_at_timestamps).to include Timestamp.parse("PT0S")
end
end
+
+ describe "when the work package did not exist at the only requested date" do
+ let(:timestamps) { [Timestamp.parse("2021-01-01T00:00:00Z")] }
+
+ it "does not include the timestamp in the exists_at_timestamps array" do
+ expect(subject.exists_at_timestamps).not_to include Timestamp.parse("2021-01-01T00:00:00Z")
+ end
+ end
end
end
@@ -372,7 +396,7 @@ describe Journable::WithHistoricAttributes do
end
end
- context "with an AR of work packages" do
+ context "with active record relation of work packages" do
let(:work_packages) { WorkPackage.all }
describe "when requesting only historic data" do
@@ -423,7 +447,7 @@ describe Journable::WithHistoricAttributes do
end
end
- context "with an AR of work packages" do
+ context "with active record relation of work packages" do
let(:work_packages) { WorkPackage.all }
describe "when providing a query" do
@@ -463,6 +487,14 @@ describe Journable::WithHistoricAttributes do
expect(subject).to be_nil
end
end
+
+ describe "when the work package did not exist at the only requested date" do
+ let(:timestamps) { [Timestamp.parse("2021-01-01T00:00:00Z")] }
+
+ it "has no baseline attributes" do
+ expect(subject).to be_nil
+ end
+ end
end
describe "#matches_query_filters_at_baseline_timestamp?" do