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
baseline api: rubocop refactoring
Sebastian Fiedlschuster8bbbebaafc5f
diff --git a/app/models/journable/with_historic_attributes.rb b/app/models/journable/with_historic_attributes.rbindex 82e53104c5c..1b8244f3436 100644--- a/app/models/journable/with_historic_attributes.rb+++ b/app/models/journable/with_historic_attributes.rb@@ -70,7 +70,8 @@# work_package.subject # => "Subject at PT0S (current time)"#class Journable::WithHistoricAttributes < SimpleDelegator- attr_accessor :timestamps, :query, :include_only_changed_attributes, :attributes_by_timestamp, :matches_query_filters_at_timestamps+ attr_accessor :timestamps, :query, :include_only_changed_attributes, :attributes_by_timestamp,+ :matches_query_filters_at_timestampsdef initialize(journable, timestamps: nil, query: nil, include_only_changed_attributes: false)super(journable)@@ -172,7 +173,7 @@ class Journable::WithHistoricAttributes < SimpleDelegatordef convert_attributes_hash_to_struct(attributes)Class.new(OpenStruct) dodef as_json(options = nil)- self.to_h.as_json(options)+ to_h.as_json(options)endend.new(attributes)enddiff --git a/app/services/api/v3/parse_query_params_service.rb b/app/services/api/v3/parse_query_params_service.rbindex 00c1f4021f0..31eef768fdc 100644--- a/app/services/api/v3/parse_query_params_service.rb+++ b/app/services/api/v3/parse_query_params_service.rb@@ -60,6 +60,7 @@ module APIresultend+ # rubocop:disable Metrics/AbcSizedef parsed_params(params)ServiceResult.success result: {group_by: group_by_from_params(params),@@ -79,6 +80,7 @@ module APIresult.errors.add(:base, e.message)resultend+ # rubocop:enable Metrics/AbcSizedef determine_allowed_empty(params)allow_empty = params.keysdiff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rbindex 81460d79b07..2fabe95eed4 100644--- a/lib/api/v3/utilities/path_helper.rb+++ b/lib/api/v3/utilities/path_helper.rb@@ -487,7 +487,7 @@ module APIdef self.work_package(id, timestamps: nil)"#{root}/work_packages/#{id}" + \if (param_value = timestamps_to_param_value(timestamps)).present?- "?" + {timestamps: param_value}.to_query+ "?#{{ timestamps: param_value }.to_query}"end.to_send@@ -546,12 +546,13 @@ module APIdef self.timestamps_to_param_value(timestamps)timestamps = Timestamp.parse_multiple(timestamps) if timestamps.is_a? Stringtimestamps = [timestamps] if timestamps.is_a? Timestamp- if timestamps.present? and timestamps.kind_of? Array and timestamps != [Timestamp.now]+ if timestamps.present? and timestamps.is_a? Array and timestamps != [Timestamp.now]timestamps.collect { |timestamp| timestamp.absolute.iso8601 }.join(",")endend- def self.path_for(path, filters: nil, sort_by: nil, group_by: nil, page_size: nil, offset: nil, select: nil, timestamps: nil)+ def self.path_for(path, filters: nil, sort_by: nil, group_by: nil, page_size: nil, offset: nil,+ select: nil, timestamps: nil)timestamps = timestamps_to_param_value(timestamps)query_params = {diff --git a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb b/lib/api/v3/work_packages/eager_loading/historic_attributes.rbindex ad336644731..c008259c698 100644--- a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb+++ b/lib/api/v3/work_packages/eager_loading/historic_attributes.rb@@ -26,6 +26,7 @@# See COPYRIGHT and LICENSE files for more details.#+++# rubocop:disable Metrics/AbcSizemodule API::V3::WorkPackages::EagerLoadingclass HistoricAttributes < Baseattr_accessor :timestamps, :query@@ -36,7 +37,8 @@ module API::V3::WorkPackages::EagerLoadingwork_package.baseline_attributes = work_package_with_historic_attributes.baseline_attributeswork_package.attributes_by_timestamp = work_package_with_historic_attributes.attributes_by_timestampwork_package.baseline_timestamp = work_package_with_historic_attributes.baseline_timestamp- work_package.matches_query_filter_at_baseline_timestamp = work_package_with_historic_attributes.matches_query_filter_at_baseline_timestamp?+ work_package.matches_query_filter_at_baseline_timestamp = \+ work_package_with_historic_attributes.matches_query_filter_at_baseline_timestamp?work_package.matches_query_filters_at_timestamps = work_package_with_historic_attributes.matches_query_filters_at_timestampsend@@ -52,7 +54,6 @@ module API::V3::WorkPackages::EagerLoadingJournable::WithHistoricAttributes.wrap_multiple(work_packages, timestamps: @timestamps, query: @query)endend-endmodule HistoricAttributesAccessors@@ -79,3 +80,4 @@ module API::V3::WorkPackages::EagerLoadingendendend+# rubocop:enable Metrics/AbcSizediff --git a/lib/api/v3/work_packages/show_end_point.rb b/lib/api/v3/work_packages/show_end_point.rbindex 0cfd21f17a7..261b9258ce9 100644--- a/lib/api/v3/work_packages/show_end_point.rb+++ b/lib/api/v3/work_packages/show_end_point.rb@@ -36,4 +36,4 @@ module API::V3::WorkPackagestimestamps: Timestamp.parse_multiple(request.params[:timestamps]))endend-end\ No newline at end of file+enddiff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rbindex 3db7a34a38c..7e5dc59b274 100644--- a/lib/api/v3/work_packages/work_package_collection_representer.rb+++ b/lib/api/v3/work_packages/work_package_collection_representer.rb@@ -82,8 +82,8 @@ module API# and set those to be the represented collection.# A potential ordering is reapplied to the work package collection in ruby.- # TODO: Should we pass the timestamps only through the `query` rather than passing them separately?- @represented = ::API::V3::WorkPackages::WorkPackageEagerLoadingWrapper.wrap(represented, current_user, timestamps:, query: _query)+ @represented = ::API::V3::WorkPackages::WorkPackageEagerLoadingWrapper \+ .wrap(represented, current_user, timestamps:, query: _query)endlink :sumsSchema dodiff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rbindex 76cea344485..ff378688693 100644--- a/lib/api/v3/work_packages/work_package_representer.rb+++ b/lib/api/v3/work_packages/work_package_representer.rb@@ -452,14 +452,14 @@ module APIif: ->(*) { respond_to?(:baseline_attributes) and baseline_attributes.present? },getter: ->(*) dobaseline_attributes.to_h.merge({- "_links": {- "self": {- "href": API::V3::Utilities::PathHelper::ApiV3Path.work_package(id, timestamps: baseline_timestamp)+ '_links': {+ 'self': {+ 'href': API::V3::Utilities::PathHelper::ApiV3Path.work_package(id, timestamps: baseline_timestamp)}},- "_meta": {- "timestamp": baseline_timestamp.to_s,- "matchesFilters": matches_query_filter_at_baseline_timestamp?+ '_meta': {+ 'timestamp': baseline_timestamp.to_s,+ 'matchesFilters': matches_query_filter_at_baseline_timestamp?}.compact})end,@@ -472,13 +472,13 @@ module APIgetter: ->(*) doattributes_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)+ '_links': {+ 'self': {+ 'href': API::V3::Utilities::PathHelper::ApiV3Path.work_package(id, timestamps: timestamp)}},- "_meta": {- "matchesFilters": matches_query_filter_at_timestamp?(timestamp)+ '_meta': {+ 'matchesFilters': matches_query_filter_at_timestamp?(timestamp)}.compact})]end.to_hdiff --git a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rbindex 580ef598ebe..21f00737fd7 100644--- a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb@@ -85,7 +85,7 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter doit 'has the absolute timestamps within the self link' doTimecop.freeze do- is_expected+ expect(subject).to include_json(absolute_timestamps_query_param.to_json).at_path('_links/self/href')end@@ -97,7 +97,7 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter doit 'has no timestamps within the self link' doTimecop.freeze do- is_expected+ expect(subject).not_to include_json("timestamps".to_json).at_path('_links/self/href')end@@ -276,7 +276,7 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter dodescribe 'ancestors' doit 'are being eager loaded' dorepresenter.represented.each do |wp|- expect(wp.work_package_ancestors).to be_kind_of(Array)+ expect(wp.work_package_ancestors).to be_a(Array)expect(wp.ancestors).to eq(wp.work_package_ancestors)endend@@ -528,8 +528,8 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter do.extract!(*Journal::WorkPackageJournal.attribute_names) \.symbolize_keys.merge(attributes)create(:work_package_journal, version:,- journable:, created_at: timestamp, updated_at: timestamp,- data: build(:journal_work_package_journal, journal_attributes))+ journable:, created_at: timestamp, updated_at: timestamp,+ data: build(:journal_work_package_journal, journal_attributes))endbefore do@@ -552,13 +552,13 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter doit 'embeds the properties of the baseline work package in attributesByTimestamp' doexpect(collection).to be_json_eql("The original work package".to_json)- .at_path("_embedded/elements/0/_embedded/attributesByTimestamp/#{timestamps.first.to_s}/subject")+ .at_path("_embedded/elements/0/_embedded/attributesByTimestamp/#{timestamps.first}/subject")endit 'embeds the link to the baseline work package in attributesByTimestamp' doexpect(collection).to be_json_eql(api_v3_paths.work_package(work_package.id, timestamps: timestamps.first).to_json)- .at_path("_embedded/elements/0/_embedded/attributesByTimestamp/#{timestamps.first.to_s}/_links/self/href")+ .at_path("_embedded/elements/0/_embedded/attributesByTimestamp/#{timestamps.first}/_links/self/href")endit 'embeds the properties of the baseline work package in baselineAttributes' do@@ -579,46 +579,51 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter dolet(:absolute_timestamps_query_param) { { timestamps: absolute_timestamp_strings.join(",") }.to_query }it 'has the absolute timestamps within the self link' do- is_expected+ expect(subject).to include_json(absolute_timestamps_query_param.to_json).at_path('_embedded/elements/0/_links/self/href')endend- context 'baseline and current' do+ context 'with baseline and current timestamps' dolet(:timestamps) { [Timestamp.parse("2022-01-01T00:00:00Z"), Timestamp.parse("PT0S")] }+it_behaves_like 'includes the properties of the current work package'it_behaves_like 'embeds the properties of the baseline work package'it_behaves_like 'has the absolute timestamps within the self link'end- context 'current only' do+ context 'with current timestamp only' dolet(:timestamps) { [Timestamp.parse("PT0S")] }+it_behaves_like 'includes the properties of the current work package'it 'has no timestamps within the self link' do- is_expected+ expect(subject).not_to include_json("timestamps".to_json).at_path('_embedded/elements/0/_links/self/href')endend- context 'baseline only' do+ context 'with baseline timestamp only' dolet(:timestamps) { [Timestamp.parse("2022-01-01T00:00:00Z")] }+it 'includes the properties of the baseline work package' doexpect(collection).to be_json_eql("The original work package".to_json).at_path('_embedded/elements/0/subject')end+it_behaves_like 'has the absolute timestamps within the self link'end- context 'empty' do+ context 'with empty timestamp' dolet(:timestamps) { [] }+it_behaves_like 'includes the properties of the current work package'it 'has no timestamps within the self link' do- is_expected+ expect(subject).not_to include_json("timestamps".to_json).at_path('_embedded/elements/0/_links/self/href')end@@ -642,7 +647,7 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter domember_with_permissions: %i[view_work_packages view_file_links])end- context 'baseline and current' do+ context 'with baseline and current timestamps' dolet(:timestamps) { [Timestamp.parse("2022-01-01T00:00:00Z"), Timestamp.parse("PT0S")] }describe 'baselineAttributes' dodiff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rbindex 89bce741742..45ce3bf9008 100644--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb@@ -1328,8 +1328,8 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do.extract!(*Journal::WorkPackageJournal.attribute_names) \.symbolize_keys.merge(attributes)create(:work_package_journal, version:,- journable:, created_at: timestamp, updated_at: timestamp,- data: build(:journal_work_package_journal, journal_attributes))+ journable:, created_at: timestamp, updated_at: timestamp,+ data: build(:journal_work_package_journal, journal_attributes))endbefore do@@ -1337,7 +1337,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do# in spec/support/api/v3/work_packages/work_package_representer_eager_loading.rb.# However, I feel more comfortable if we test the real thing here.#- allow(::API::V3::WorkPackages::WorkPackageEagerLoadingWrapper)+ allow(API::V3::WorkPackages::WorkPackageEagerLoadingWrapper).to receive(:wrap_one).and_call_original@@ -1369,8 +1369,8 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doit 'has no information about whether the work package matches the query filters at the baseline time' \'because there are no filters without a query' do- expect(subject)- .not_to have_json_path('_embedded/baselineAttributes/_meta/matchesFilters')+ expect(subject)+ .not_to have_json_path('_embedded/baselineAttributes/_meta/matchesFilters')endenddiff --git a/spec/models/journable/historic_active_record_relation_spec.rb b/spec/models/journable/historic_active_record_relation_spec.rbindex ddbaf9428ae..68bb40ab5a7 100644--- a/spec/models/journable/historic_active_record_relation_spec.rb+++ b/spec/models/journable/historic_active_record_relation_spec.rb@@ -384,6 +384,7 @@ describe Journable::HistoricActiveRecordRelation dodescribe "#first" dodescribe "for columns that don't exist in the journal-data table" dolet(:column_name) { :lock_version }+subject { historic_relation.first.send(column_name) }specify "the column name does exist in the journable table" do@@ -395,7 +396,7 @@ describe Journable::HistoricActiveRecordRelation doendit "has the attribute with null value" do- expect(historic_relation.first.attributes_before_type_cast[column_name]).to be nil+ expect(historic_relation.first.attributes_before_type_cast[column_name]).to be_nilendit "has the typecasted value matching the journable class's data type" dodiff --git a/spec/models/journable/timestamps_spec.rb b/spec/models/journable/timestamps_spec.rbindex d3002ef3521..1fd6677e490 100644--- a/spec/models/journable/timestamps_spec.rb+++ b/spec/models/journable/timestamps_spec.rb@@ -560,7 +560,7 @@ describe Journable::Timestamps doendit "has the attribute with null value" do- expect(subject.attributes_before_type_cast[column_name]).to be nil+ expect(subject.attributes_before_type_cast[column_name]).to be_nilendit "has the typecasted value matching the journable class's data type" dodiff --git a/spec/models/timestamp_spec.rb b/spec/models/timestamp_spec.rbindex 696d7e70f1e..66b3aaadfd7 100644--- a/spec/models/timestamp_spec.rb+++ b/spec/models/timestamp_spec.rb@@ -368,7 +368,7 @@ describe Timestamp dosubject { Query.where("updated_at < ?", timestamp.to_time) }it "raises no error" do- expect { subject }.not_to raise_error TypeError+ expect { subject }.not_to raise_errorendendenddiff --git a/spec/requests/api/v3/work_packages/show_resource_spec.rb b/spec/requests/api/v3/work_packages/show_resource_spec.rbindex 87428aa519e..8abe6edd0db 100644--- a/spec/requests/api/v3/work_packages/show_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/show_resource_spec.rb@@ -229,13 +229,13 @@ describe 'API v3 Work package resource',endlet(:original_journal) docreate_journal(journable: work_package, timestamp: baseline_time - 1.day,- version: 1,- attributes: { subject: "The original work package" })+ version: 1,+ attributes: { subject: "The original work package" })endlet(:current_journal) docreate_journal(journable: work_package, timestamp: 1.day.ago,- version: 2,- attributes: { subject: "The current work package" })+ version: 2,+ attributes: { subject: "The current work package" })enddef create_journal(journable:, version:, timestamp:, attributes: {})@@ -244,8 +244,8 @@ describe 'API v3 Work package resource',.extract!(*Journal::WorkPackageJournal.attribute_names) \.symbolize_keys.merge(attributes)create(:work_package_journal, version:,- journable:, created_at: timestamp, updated_at: timestamp,- data: build(:journal_work_package_journal, journal_attributes))+ journable:, created_at: timestamp, updated_at: timestamp,+ data: build(:journal_work_package_journal, journal_attributes))endbefore do@@ -269,10 +269,10 @@ describe 'API v3 Work package resource',it 'embeds the attributesByTimestamp' doexpect(subject).to be_json_eql("The original work package".to_json)- .at_path("_embedded/attributesByTimestamp/#{timestamps.first.to_s}/subject")+ .at_path("_embedded/attributesByTimestamp/#{timestamps.first}/subject")expect(subject).to be_json_eql("The current work package".to_json)- .at_path("_embedded/attributesByTimestamp/#{timestamps.last.to_s}/subject")+ .at_path("_embedded/attributesByTimestamp/#{timestamps.last}/subject")endit 'has the current attributes as attributes' dodiff --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.rbindex fff79363b41..60cb7cbcda3 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@@ -237,7 +237,7 @@ describe ::API::V3::WorkPackageCollectionFromQueryService,context 'timestamps' dolet(:timestamps) { [Timestamp.parse("P-1Y"), Timestamp.now] }- let(:query) { build_stubbed(:query, timestamps: timestamps) }+ let(:query) { build_stubbed(:query, timestamps:) }it 'has the query timestamps' doexpect(subject.timestamps)