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
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.rbindex 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 < SimpleDelegatordef 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:)+ endendend@@ -182,7 +187,7 @@ class Journable::WithHistoricAttributes < SimpleDelegatorenddef attributes- __getobj__.try(:attributes)+ __getobj__.new_record? ? {} : __getobj__.attributesenddef to_arydiff --git a/app/models/journable/with_historic_attributes/loader.rb b/app/models/journable/with_historic_attributes/loader.rbindex 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::WithHistoricAttributesenddef journable_at_timestamp(journable, timestamp)- at_timestamp(timestamp)[journable.id]+ at_timestamp(timestamp)[journable&.id]enddef at_timestamp(timestamp)diff --git a/spec/models/journable/with_historic_attributes_spec.rb b/spec/models/journable/with_historic_attributes_spec.rbindex 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 doendend- context "with an AR of work packages" do+ context "with active record relation of work packages" dolet(:work_packages) { WorkPackage.all }it "returns an array of Journable::WithHistoricAttributes instances" do@@ -158,6 +158,14 @@ describe Journable::WithHistoricAttributes doexpect(subject.subject).to eq "The current work package 1"endend++ 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+ endendcontext "with an array of work packages" do@@ -168,7 +176,7 @@ describe Journable::WithHistoricAttributes doendend- context "with an AR of work packages" do+ context "with active record relation of work packages" dolet(:work_packages) { WorkPackage.all }it "provides access to the work-package attributes" do@@ -222,6 +230,14 @@ describe Journable::WithHistoricAttributes doexpect(subject.attributes_by_timestamp["2021-01-01T00:00:00Z"]).to be_nilendend++ 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+ endendcontext "with an array of work packages" do@@ -257,7 +273,7 @@ describe Journable::WithHistoricAttributes doendend- context "with an AR of work packages" do+ context "with active record relation of work packages" dolet(:work_packages) { WorkPackage.all }it "provides access to the work-package attributes at timestamps" do@@ -340,6 +356,14 @@ describe Journable::WithHistoricAttributes doexpect(subject.exists_at_timestamps).to include Timestamp.parse("PT0S")endend++ 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+ endendend@@ -372,7 +396,7 @@ describe Journable::WithHistoricAttributes doendend- context "with an AR of work packages" do+ context "with active record relation of work packages" dolet(:work_packages) { WorkPackage.all }describe "when requesting only historic data" do@@ -423,7 +447,7 @@ describe Journable::WithHistoricAttributes doendend- context "with an AR of work packages" do+ context "with active record relation of work packages" dolet(:work_packages) { WorkPackage.all }describe "when providing a query" do@@ -463,6 +487,14 @@ describe Journable::WithHistoricAttributes doexpect(subject).to be_nilendend++ 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+ endenddescribe "#matches_query_filters_at_baseline_timestamp?" do