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
Address Rubocop style issues.
Pavel Balashova8040f907ef4
diff --git a/modules/storages/app/common/storages/peripherals/storage_requests.rb b/modules/storages/app/common/storages/peripherals/storage_requests.rbindex 1def1670179..95a23e79f27 100644--- a/modules/storages/app/common/storages/peripherals/storage_requests.rb+++ b/modules/storages/app/common/storages/peripherals/storage_requests.rb@@ -51,7 +51,8 @@ module Storages::Peripherals(COMMANDS + QUERIES).each do |request|define_method(request) do- clazz = "::Storages::Peripherals::StorageInteraction::#{@storage.short_provider_type.capitalize}::#{request.to_s.classify}".constantize+ clazz = "::Storages::Peripherals::StorageInteraction::" \+ "#{@storage.short_provider_type.capitalize}::#{request.to_s.classify}".constantizeclazz.new(@storage).method(:call).to_procendenddiff --git a/modules/storages/app/workers/manage_nextcloud_integration_job.rb b/modules/storages/app/workers/manage_nextcloud_integration_job.rbindex f5dcb13ddb1..dd36c3617f5 100644--- a/modules/storages/app/workers/manage_nextcloud_integration_job.rb+++ b/modules/storages/app/workers/manage_nextcloud_integration_job.rb@@ -99,7 +99,9 @@ class ManageNextcloudIntegrationJob < Cron::CronJob@requests.set_permissions_command.call(path: @group_folder, permissions:)- .on_failure { |r| raise "set_permissions_command(path: #{@group_folder}, permissions: #{permissions}) failed: #{r.inspect}" }+ .on_failure do |r|+ raise "set_permissions_command(path: #{@group_folder}, permissions: #{permissions}) failed: #{r.inspect}"+ endenddef project_folder_path(project)@@ -129,10 +131,11 @@ class ManageNextcloudIntegrationJob < Cron::CronJobdef folders_properties@folders_properties ||= @requests- .propfind_query- .call(depth: '1', path: @group_folder, props: %w[oc:fileid])- .on_failure { |r| raise "propfind_query(depth: 1, path: #{@group_folder}, props: #{%w[oc:fileid]}) failed: #{r.inspect}" }- .result+ .propfind_query+ .call(depth: '1', path: @group_folder, props: %w[oc:fileid])+ .on_failure do |r|+ raise "propfind_query(depth: 1, path: #{@group_folder}, props: #{%w[oc:fileid]}) failed: #{r.inspect}"+ end.resultenddef rename_folder(source:, target:)diff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rbindex ff843123fb2..cbda8f7af91 100644--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb@@ -114,7 +114,9 @@ describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with missing OAuth token' dobefore do- allow_any_instance_of(OAuthClients::ConnectionManager).to receive(:get_access_token).and_return(ServiceResult.failure)+ instance = instance_double(OAuthClients::ConnectionManager)+ allow(OAuthClients::ConnectionManager).to receive(:new).and_return(instance)+ allow(instance).to receive(:get_access_token).and_return(ServiceResult.failure)endit 'must return ":not_authorized" ServiceResult' do@@ -182,34 +184,31 @@ describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with Nextcloud storage type selected' doit 'returns a list files directories with names and permissions' do- result = subject- .files_query- .call(folder: nil, user:)+ result = subject.files_query.call(folder: nil, user:)expect(result).to be_successexpect(result.result.files.size).to eq(4)expect(result.result.ancestors.size).to eq(0)expect(result.result.parent).not_to be_nil-- expect(result).to be_success- expect(result.result.files[0].name).to eq('Folder1')- expect(result.result.files[0].mime_type).to eq('application/x-op-directory')- expect(result.result.files[0].id).to eq('11')- expect(result.result.files[0].permissions).to include(:readable)- expect(result.result.files[0].permissions).to include(:writeable)-- expect(result.result.files[1].mime_type).to eq('application/x-op-directory')- expect(result.result.files[1].permissions).to include(:readable)- expect(result.result.files[1].permissions).not_to include(:writeable)-- expect(result.result.files[2].mime_type).to eq('text/markdown')- expect(result.result.files[2].name).to eq('README.md')- expect(result.result.files[2].id).to eq('12')- expect(result.result.files[2].permissions).to include(:readable)- expect(result.result.files[2].permissions).to include(:writeable)-- expect(result.result.files[3].mime_type).to eq('application/pdf')- expect(result.result.files[3].permissions).to include(:readable)- expect(result.result.files[3].permissions).not_to include(:writeable)+ expect(result.result.files[0]).to have_attributes(+ id: '11',+ name: 'Folder1',+ mime_type: 'application/x-op-directory',+ permissions: include(:readable, :writeable)+ )+ expect(result.result.files[1]).to have_attributes(+ mime_type: 'application/x-op-directory',+ permissions: %i[readable]+ )+ expect(result.result.files[2]).to have_attributes(+ id: '12',+ name: 'README.md',+ mime_type: 'text/markdown',+ permissions: include(:readable, :writeable)+ )+ expect(result.result.files[3]).to have_attributes(+ mime_type: 'application/pdf',+ permissions: %i[readable]+ )enddescribe 'with origin user id containing whitespaces' do@@ -280,7 +279,9 @@ describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with missing OAuth token' dobefore do- allow_any_instance_of(OAuthClients::ConnectionManager).to receive(:get_access_token).and_return(ServiceResult.failure)+ instance = instance_double(OAuthClients::ConnectionManager)+ allow(OAuthClients::ConnectionManager).to receive(:new).and_return(instance)+ allow(instance).to receive(:get_access_token).and_return(ServiceResult.failure)endit 'must return ":not_authorized" ServiceResult' do@@ -419,7 +420,9 @@ describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with missing OAuth token' dobefore do- allow_any_instance_of(OAuthClients::ConnectionManager).to receive(:get_access_token).and_return(ServiceResult.failure)+ instance = instance_double(OAuthClients::ConnectionManager)+ allow(OAuthClients::ConnectionManager).to receive(:new).and_return(instance)+ allow(instance).to receive(:get_access_token).and_return(ServiceResult.failure)endit 'must return ":not_authorized" ServiceResult' dodiff --git a/modules/storages/spec/features/create_file_links_spec.rb b/modules/storages/spec/features/create_file_links_spec.rbindex aae68a97d87..4b77a80a267 100644--- a/modules/storages/spec/features/create_file_links_spec.rb+++ b/modules/storages/spec/features/create_file_links_spec.rb@@ -59,15 +59,16 @@ describe 'Managing file links in work package', js: true, webmock: true dobefore doallow(Storages::FileLinkSyncService).to receive(:new).and_return(sync_service)- stub_request(:get, "https://host1.example.com/ocs/v1.php/cloud/user").- with(+ stub_request(:get, "https://host1.example.com/ocs/v1.php/cloud/user")+ .with(headers: {- 'Authorization'=>'Bearer 1234567890-1',- 'Host'=>'host1.example.com',- 'Ocs-Apirequest'=>'true',+ 'Authorization' => 'Bearer 1234567890-1',+ 'Host' => 'host1.example.com',+ 'Ocs-Apirequest' => 'true','Accept' => "application/json"- }).- to_return(status: 200, body: "", headers: {})+ }+ )+ .to_return(status: 200, body: "", headers: {})stub_request(:propfind, "#{storage.host}/remote.php/dav/files/#{oauth_client_token.origin_user_id}/").to_return(status: 207, body: root_xml_response, headers: {})stub_request(:propfind, "#{storage.host}/remote.php/dav/files/#{oauth_client_token.origin_user_id}/Folder1")diff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rbindex 96a59f5a726..f19ebbbe054 100644--- a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb@@ -78,6 +78,7 @@ describe 'API v3 file links resource' do.and_return(ServiceResult.success(result: oauth_client_token))allow(connection_manager).to receive(:authorization_state).and_return(:connected)+allow(connection_manager).to receive(:get_authorization_uri).and_return('https://example.com/authorize')@@ -229,8 +230,7 @@ describe 'API v3 file links resource' dodescribe 'POST /api/v3/work_packages/:work_package_id/file_links' dolet(:path) { api_v3_paths.file_links(work_package.id) }let(:permissions) { %i(view_work_packages manage_file_links) }- let(:storage_url1) { storage.host }- let(:storage_url2) { storage.host }+ let(:storage_url) { storage.host }let(:params) do{_type: "Collection",@@ -255,11 +255,11 @@ describe 'API v3 file links resource' do},_links: {storageUrl: {- href: storage_url1+ href: storage_url}}},- build(:file_link_element, storage_url: storage_url2)+ build(:file_link_element, storage_url: storage.host)]end@@ -293,8 +293,8 @@ describe 'API v3 file links resource' docontext 'when some embedded file link elements are NOT valid' dolet(:embedded_elements) do[- build(:file_link_element, :invalid, storage_url: storage_url1),- build(:file_link_element, origin_name: "the valid one", storage_url: storage_url1)+ build(:file_link_element, :invalid, storage_url:),+ build(:file_link_element, origin_name: "the valid one", storage_url:)]end@@ -378,7 +378,7 @@ describe 'API v3 file links resource' docontext 'when storage host is invalid' docontext 'when unknown host' do- let(:storage_url1) { 'https://invalid.host.org/' }+ let(:storage_url) { 'https://invalid.host.org/' }it_behaves_like 'constraint violation' dolet(:message) { 'Storage does not exist' }@@ -386,7 +386,7 @@ describe 'API v3 file links resource' doendcontext 'when nil' do- let(:storage_url1) { nil }+ let(:storage_url) { nil }it_behaves_like 'constraint violation' dolet(:message) { "Storage can't be blank." }@@ -394,7 +394,7 @@ describe 'API v3 file links resource' doendcontext 'when empty' do- let(:storage_url1) { "" }+ let(:storage_url) { "" }it_behaves_like 'constraint violation' dolet(:message) { "Storage can't be blank." }@@ -402,7 +402,7 @@ describe 'API v3 file links resource' doendcontext 'when not linked to the project of the work package' do- let(:storage_url1) { another_storage.host }+ let(:storage_url) { another_storage.host }it_behaves_like 'constraint violation' dolet(:message) { 'Storage is not linked to project' }@@ -437,7 +437,7 @@ describe 'API v3 file links resource' docontext "when more than #{Storages::Peripherals::ParseCreateParamsService::MAX_ELEMENTS} embedded elements" dolet(:max) { Storages::Peripherals::ParseCreateParamsService::MAX_ELEMENTS }let(:too_many) { max + 1 }- let(:embedded_elements) { build_list(:file_link_element, too_many, storage_url: storage_url1) }+ let(:embedded_elements) { build_list(:file_link_element, too_many, storage_url:) }it_behaves_like 'constraint violation' dolet(:message) { "Too many elements created at once. Expected #{max} at most, got #{too_many}." }@@ -558,9 +558,10 @@ describe 'API v3 file links resource' dodescribe 'with successful response' dobefore do- allow_any_instance_of(- Storages::Peripherals::StorageInteraction::Nextcloud::DownloadLinkQuery- ).to receive(:call).and_return(ServiceResult.success(result: url))+ clazz = Storages::Peripherals::StorageInteraction::Nextcloud::DownloadLinkQuery+ instance = instance_double(clazz)+ allow(clazz).to receive(:new).and_return(instance)+ allow(instance).to receive(:call).and_return(ServiceResult.success(result: url))endit 'responds successfully' do@@ -573,9 +574,12 @@ describe 'API v3 file links resource' dodescribe 'with query failed' dobefore do- allow_any_instance_of(- Storages::Peripherals::StorageInteraction::Nextcloud::DownloadLinkQuery- ).to receive(:call).and_return(ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error)))+ clazz = Storages::Peripherals::StorageInteraction::Nextcloud::DownloadLinkQuery+ instance = instance_double(clazz)+ allow(clazz).to receive(:new).and_return(instance)+ allow(instance).to receive(:call).and_return(+ ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error))+ )get pathenddiff --git a/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb b/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rbindex 1585b0a3678..cf0ad391b8c 100644--- a/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb+++ b/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb@@ -103,24 +103,27 @@ describe 'API v3 storage files', content_type: :json, webmock: true docontext 'with query failed' dobefore do- allow_any_instance_of(- Storages::Peripherals::StorageInteraction::Nextcloud::FilesQuery- ).to receive(:call).and_return(ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error)))+ clazz = Storages::Peripherals::StorageInteraction::Nextcloud::FilesQuery+ instance = instance_double(clazz)+ allow(clazz).to receive(:new).and_return(instance)+ allow(instance).to receive(:call).and_return(+ ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error))+ )end- context 'due to authorization failure' do+ context 'with authorization failure' dolet(:error) { :not_authorized }it { expect(last_response.status).to be(500) }end- context 'due to internal error' do+ context 'with internal error' dolet(:error) { :error }it { expect(last_response.status).to be(500) }end- context 'due to not found' do+ context 'with not found' dolet(:error) { :not_found }it 'fails with outbound request failure' do@@ -146,9 +149,10 @@ describe 'API v3 storage files', content_type: :json, webmock: true dodescribe 'with successful response' dobefore do- allow_any_instance_of(- Storages::Peripherals::StorageInteraction::Nextcloud::UploadLinkQuery- ).to receive(:call).and_return(ServiceResult.success(result: upload_link))+ clazz = Storages::Peripherals::StorageInteraction::Nextcloud::UploadLinkQuery+ instance = instance_double(clazz)+ allow(clazz).to receive(:new).and_return(instance)+ allow(instance).to receive(:call).and_return(ServiceResult.success(result: upload_link))endsubject { last_response.body }@@ -166,9 +170,12 @@ describe 'API v3 storage files', content_type: :json, webmock: true docontext 'with query failed' dobefore do- allow_any_instance_of(- Storages::Peripherals::StorageInteraction::Nextcloud::UploadLinkQuery- ).to receive(:call).and_return(ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error)))+ clazz = Storages::Peripherals::StorageInteraction::Nextcloud::UploadLinkQuery+ instance = instance_double(clazz)+ allow(clazz).to receive(:new).and_return(instance)+ allow(instance).to receive(:call).and_return(+ ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error))+ )enddescribe 'due to authorization failure' dodiff --git a/modules/storages/spec/workers/manage_nextcloud_integration_job_spec.rb b/modules/storages/spec/workers/manage_nextcloud_integration_job_spec.rbindex d99a23db171..0a16fd9b029 100644--- a/modules/storages/spec/workers/manage_nextcloud_integration_job_spec.rb+++ b/modules/storages/spec/workers/manage_nextcloud_integration_job_spec.rb@@ -29,6 +29,7 @@require 'spec_helper'describe ManageNextcloudIntegrationJob, type: :job, webmock: true do+ # rubocop:disable RSpec/IndexedLetlet(:group_users_response_body) do<<~XML<?xml version="1.0"?>@@ -312,11 +313,13 @@ describe ManageNextcloudIntegrationJob, type: :job, webmock: true dolet(:project2) { create(:project, name: 'Jedi Project Folder ///', members: { user => role }) }let(:user) { create(:user) }let(:role) { create(:role, permissions: %w[read_files write_files]) }+ # rubocop:enable RSpec/IndexedLetit 'has a schedule set' doexpect(described_class.cron_expression).to eq('*/5 * * * *')end+ # rubocop:disable RSpec/ExampleLengthit 'does the job' dostorage = create(:storage,host: 'https://example.com',@@ -442,4 +445,5 @@ describe ManageNextcloudIntegrationJob, type: :job, webmock: true doexpect(request_stubs).to all have_been_requestedend+ # rubocop:enable RSpec/ExampleLengthend