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

baseline api: adding specs for caching

Sebastian Fiedlschustera18925e22913
diff --git a/spec/requests/api/v3/work_packages/index_resource_spec.rb b/spec/requests/api/v3/work_packages/index_resource_spec.rb
index e228cfedc02..b0e07c14482 100644
--- a/spec/requests/api/v3/work_packages/index_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/index_resource_spec.rb
@@ -712,6 +712,45 @@ describe 'API v3 Work package resource',
.not_to have_json_path('_embedded/elements/1/_embedded/attributesByTimestamp/0/subject')
end
end
+
+ context "with caching" do
+ context "with relative timestamps" do
+ let(:timestamps) { [Timestamp.parse("P-2D"), Timestamp.now] }
+ let(:created_at) { '2015-01-01' }
+
+ describe "when the filter becomes outdated" do
+ # The work package has been updated 1 day ago, which is after the baseline
+ # date (2 days ago). When time progresses, the date of the update will be
+ # before the baseline date, because the baseline date is relative to the
+ # current date. This means that the filter will become outdated and we cannot
+ # use a cached result in this case.
+
+ let(:path) { "#{api_v3_paths.path_for(:work_packages, filters:)}&timestamps=#{timestamps.join(',')}" }
+ let(:filters) do
+ [
+ {
+ subject: {
+ operator: '~',
+ values: [search_term]
+ }
+ }
+ ]
+ end
+ let(:search_term) { 'original' }
+
+ it "does not use an outdated cache" do
+ get path
+ expect do
+ Timecop.travel 5.days do
+ get path
+ end
+ end.to change {
+ JSON.parse(last_response.body).dig('_embedded', 'elements').count
+ }.from(1).to(0)
+ end
+ end
+ end
+ end
end
end
end
diff --git a/spec/requests/api/v3/work_packages/show_resource_spec.rb b/spec/requests/api/v3/work_packages/show_resource_spec.rb
index 86aa16e16ea..a19d4f96fd6 100644
--- a/spec/requests/api/v3/work_packages/show_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/show_resource_spec.rb
@@ -349,6 +349,60 @@ describe 'API v3 Work package resource',
end
end
end
+
+ context "with caching" do
+ before { login_as current_user }
+
+ context "with relative timestamps" do
+ let(:timestamps) { [Timestamp.parse("P-2D"), Timestamp.now] }
+ let(:created_at) { '2015-01-01' }
+
+ describe "attributesByTimestamp" do
+ it "does not cache the self link" do
+ get get_path
+ expect do
+ Timecop.travel 20.minutes do
+ get get_path
+ end
+ end.to change {
+ JSON.parse(last_response.body)
+ .dig("_embedded", "attributesByTimestamp", 0, "_links", "self", "href")
+ }
+ end
+
+ it "does not cache the attributes" do
+ get get_path
+ expect do
+ Timecop.travel 2.days do
+ get get_path
+ end
+ end.to change {
+ JSON.parse(last_response.body)
+ .dig("_embedded", "attributesByTimestamp", 0, "subject")
+ }
+ end
+ end
+
+ describe "_meta" do
+ describe "exists" do
+ let(:timestamps) { [Timestamp.parse("P-2D")] }
+ let(:created_at) { 25.hours.ago }
+
+ it "is not cached" do
+ get get_path
+ expect do
+ Timecop.travel 2.days do
+ get get_path
+ end
+ end.to change {
+ JSON.parse(last_response.body)
+ .dig("_meta", "exists")
+ }
+ end
+ end
+ end
+ end
+ end
end
end
end