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

Fix specs for CostEntry- and TimeEntryRepresenters. Also still include deprecated WP attribute

Klaus Zanders1e89a785c46e
diff --git a/modules/costs/lib/api/v3/cost_entries/cost_entry_representer.rb b/modules/costs/lib/api/v3/cost_entries/cost_entry_representer.rb
index af20c8ffb76..43ed8c2b2f5 100644
--- a/modules/costs/lib/api/v3/cost_entries/cost_entry_representer.rb
+++ b/modules/costs/lib/api/v3/cost_entries/cost_entry_representer.rb
@@ -43,6 +43,10 @@ module API
getter: ::API::V3::CostEntries::EntityRepresenterFactory.create_getter_lambda(:entity),
link: ::API::V3::CostEntries::EntityRepresenterFactory.create_link_lambda(:entity)
+ # TODO: DEPRECATED!
+ associated_resource :work_package,
+ skip_render: ->(*) { represented.entity_type != "WorkPackage" }
+
property :id, render_nil: true
property :units, as: :spentUnits
diff --git a/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb b/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb
index d95adbd1664..eb02ba53f82 100644
--- a/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb
+++ b/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb
@@ -97,6 +97,10 @@ module API
getter: ::API::V3::TimeEntries::EntityRepresenterFactory.create_getter_lambda(:entity),
link: ::API::V3::TimeEntries::EntityRepresenterFactory.create_link_lambda(:entity)
+ # TODO: DEPRECATED!
+ associated_resource :work_package,
+ skip_render: ->(*) { represented.entity_type != "WorkPackage" }
+
associated_resource :user
date_time_property :start_time,
diff --git a/modules/costs/spec/lib/api/v3/cost_entries/cost_entry_representer_spec.rb b/modules/costs/spec/lib/api/v3/cost_entries/cost_entry_representer_spec.rb
index 1b3d2483708..0993de0907a 100644
--- a/modules/costs/spec/lib/api/v3/cost_entries/cost_entry_representer_spec.rb
+++ b/modules/costs/spec/lib/api/v3/cost_entries/cost_entry_representer_spec.rb
@@ -64,8 +64,8 @@ RSpec.describe API::V3::CostEntries::CostEntryRepresenter do
end
it_behaves_like "has a titled link" do
- let(:link) { "workPackage" }
- let(:href) { api_v3_paths.work_package cost_entry.work_package.id }
+ let(:link) { "entity" }
+ let(:href) { api_v3_paths.work_package cost_entry.entity.id }
let(:title) { cost_entry.work_package.subject }
end
diff --git a/modules/costs/spec/lib/api/v3/time_entries/time_entry_representer_rendering_spec.rb b/modules/costs/spec/lib/api/v3/time_entries/time_entry_representer_rendering_spec.rb
index 4a27d6f3dfe..a8fd7ab7360 100644
--- a/modules/costs/spec/lib/api/v3/time_entries/time_entry_representer_rendering_spec.rb
+++ b/modules/costs/spec/lib/api/v3/time_entries/time_entry_representer_rendering_spec.rb
@@ -40,11 +40,12 @@ RSpec.describe API::V3::TimeEntries::TimeEntryRepresenter, "rendering" do
hours:,
activity:,
project:,
- work_package:,
+ entity: work_package,
user:)
end
let(:project) { build_stubbed(:project) }
let(:work_package) { build_stubbed(:work_package, project:) }
+ let(:meeting) { build_stubbed(:meeting, project:) }
let(:activity) { build_stubbed(:time_entry_activity) }
let(:user) { build_stubbed(:user) }
let(:current_user) { user }
@@ -82,10 +83,34 @@ RSpec.describe API::V3::TimeEntries::TimeEntryRepresenter, "rendering" do
let(:title) { project.name }
end
- it_behaves_like "has a titled link" do
- let(:link) { "workPackage" }
- let(:href) { api_v3_paths.work_package work_package.id }
- let(:title) { work_package.subject }
+ context "with a time entry logged on a work package" do
+ it_behaves_like "has a titled link" do
+ let(:link) { "entity" }
+ let(:href) { api_v3_paths.work_package work_package.id }
+ let(:title) { work_package.subject }
+ end
+
+ it_behaves_like "has a titled link" do
+ let(:link) { "workPackage" }
+ let(:href) { api_v3_paths.work_package work_package.id }
+ let(:title) { work_package.subject }
+ end
+ end
+
+ context "with a time entry logged on a meeting" do
+ before do
+ time_entry.entity = meeting
+ end
+
+ it_behaves_like "has a titled link" do
+ let(:link) { "entity" }
+ let(:href) { api_v3_paths.meeting meeting.id }
+ let(:title) { meeting.title }
+ end
+
+ it_behaves_like "has no link" do
+ let(:link) { "workPackage" }
+ end
end
it_behaves_like "has a titled link" do