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: rubocop refactoring

Sebastian Fiedlschuster2b86510a87fe
diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rb
index dcc7654e9fe..7ddfb05684f 100644
--- a/lib/api/v3/work_packages/work_package_representer.rb
+++ b/lib/api/v3/work_packages/work_package_representer.rb
@@ -26,6 +26,10 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# rubocop:disable Lint/SymbolConversion
+# because some of the json attributes are written in 'singleQuotes' instead of symbols
+# for better reading.
+
module API
module V3
module WorkPackages
@@ -52,7 +56,7 @@ module API
super(model, current_user:, embed_links:)
end
- def self_v3_path(path, id_attribute)
+ def self_v3_path(*)
api_v3_paths.work_package(represented.id, timestamps:)
end
@@ -466,17 +470,19 @@ module API
as: :baselineAttributes,
if: ->(*) { respond_to?(:baseline_attributes) and baseline_attributes.present? },
getter: ->(*) do
- baseline_attributes.to_h.merge({
- '_links': {
- 'self': {
- 'href': API::V3::Utilities::PathHelper::ApiV3Path.work_package(id, timestamps: baseline_timestamp)
- }
- },
- '_meta': {
- 'timestamp': baseline_timestamp.to_s,
- 'matchesFilters': matches_query_filters_at_baseline_timestamp?
- }.compact
- })
+ baseline_attributes.to_h.merge(
+ {
+ '_links': {
+ 'self': {
+ 'href': API::V3::Utilities::PathHelper::ApiV3Path.work_package(id, timestamps: baseline_timestamp)
+ }
+ },
+ '_meta': {
+ 'timestamp': baseline_timestamp.to_s,
+ 'matchesFilters': matches_query_filters_at_baseline_timestamp?
+ }.compact
+ }
+ )
end,
embedded: true,
uncachable: true
@@ -485,18 +491,20 @@ module API
as: :attributesByTimestamp,
if: ->(*) { respond_to?(:attributes_by_timestamp) and attributes_by_timestamp.present? },
getter: ->(*) do
- attributes_by_timestamp.to_a.collect do |timestamp, attributes|
- [timestamp, attributes.to_h.merge({
- '_links': {
- 'self': {
- 'href': API::V3::Utilities::PathHelper::ApiV3Path.work_package(id, timestamps: timestamp)
- }
- },
- '_meta': {
- 'matchesFilters': matches_query_filters_at_timestamp?(timestamp)
- }.compact
- })]
- end.to_h
+ attributes_by_timestamp.to_a.to_h do |timestamp, attributes|
+ [timestamp, attributes.to_h.merge(
+ {
+ '_links': {
+ 'self': {
+ 'href': API::V3::Utilities::PathHelper::ApiV3Path.work_package(id, timestamps: timestamp)
+ }
+ },
+ '_meta': {
+ 'matchesFilters': matches_query_filters_at_timestamp?(timestamp)
+ }.compact
+ }
+ )]
+ end
end,
embedded: true,
uncachable: true
@@ -716,3 +724,5 @@ module API
end
end
end
+
+# rubocop:enable Lint/SymbolConversion
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 41d1f0de6b8..dce82b77c85 100644
--- a/spec/requests/api/v3/work_packages/show_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/show_resource_spec.rb
@@ -209,7 +209,7 @@ describe 'API v3 Work package resource',
end
describe 'GET /api/v3/work_packages/:id?timestamps=' do
- let(:get_path) { api_v3_paths.work_package(work_package.id) + "?timestamps=" + timestamps.map(&:to_s).join(',') }
+ let(:get_path) { "#{api_v3_paths.work_package(work_package.id)}?timestamps=#{timestamps.map(&:to_s).join(',')}" }
describe 'response body' do
subject do
diff --git a/spec/services/api/v3/work_package_collection_from_query_service_spec.rb b/spec/services/api/v3/work_package_collection_from_query_service_spec.rb
index 60cb7cbcda3..fbf8ade3110 100644
--- a/spec/services/api/v3/work_package_collection_from_query_service_spec.rb
+++ b/spec/services/api/v3/work_package_collection_from_query_service_spec.rb
@@ -235,7 +235,7 @@ describe ::API::V3::WorkPackageCollectionFromQueryService,
end
end
- context 'timestamps' do
+ context 'when timestamps are given' do
let(:timestamps) { [Timestamp.parse("P-1Y"), Timestamp.now] }
let(:query) { build_stubbed(:query, timestamps:) }
@@ -245,7 +245,7 @@ describe ::API::V3::WorkPackageCollectionFromQueryService,
end
end
- context '_query' do
+ context 'when a _query object is given' do
# This is a workaround to allow the representer to access the query object itself.
# The attribute 'query' is already used by the representer and holds a Hash.
it 'has the query' do