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

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.rb
index 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}".constantize
clazz.new(@storage).method(:call).to_proc
end
end
diff --git a/modules/storages/app/workers/manage_nextcloud_integration_job.rb b/modules/storages/app/workers/manage_nextcloud_integration_job.rb
index 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}"
+ end
end
def project_folder_path(project)
@@ -129,10 +131,11 @@ class ManageNextcloudIntegrationJob < Cron::CronJob
def 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.result
end
def 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.rb
index 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 do
describe 'with missing OAuth token' do
before 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)
end
it 'must return ":not_authorized" ServiceResult' do
@@ -182,34 +184,31 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
describe 'with Nextcloud storage type selected' do
it '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_success
expect(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]
+ )
end
describe 'with origin user id containing whitespaces' do
@@ -280,7 +279,9 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
describe 'with missing OAuth token' do
before 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)
end
it 'must return ":not_authorized" ServiceResult' do
@@ -419,7 +420,9 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
describe 'with missing OAuth token' do
before 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)
end
it 'must return ":not_authorized" ServiceResult' do
diff --git a/modules/storages/spec/features/create_file_links_spec.rb b/modules/storages/spec/features/create_file_links_spec.rb
index 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 do
before do
allow(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.rb
index 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' do
describe 'POST /api/v3/work_packages/:work_package_id/file_links' do
let(: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' do
context 'when some embedded file link elements are NOT valid' do
let(: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' do
context 'when storage host is invalid' do
context 'when unknown host' do
- let(:storage_url1) { 'https://invalid.host.org/' }
+ let(:storage_url) { 'https://invalid.host.org/' }
it_behaves_like 'constraint violation' do
let(:message) { 'Storage does not exist' }
@@ -386,7 +386,7 @@ describe 'API v3 file links resource' do
end
context 'when nil' do
- let(:storage_url1) { nil }
+ let(:storage_url) { nil }
it_behaves_like 'constraint violation' do
let(:message) { "Storage can't be blank." }
@@ -394,7 +394,7 @@ describe 'API v3 file links resource' do
end
context 'when empty' do
- let(:storage_url1) { "" }
+ let(:storage_url) { "" }
it_behaves_like 'constraint violation' do
let(:message) { "Storage can't be blank." }
@@ -402,7 +402,7 @@ describe 'API v3 file links resource' do
end
context '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' do
let(:message) { 'Storage is not linked to project' }
@@ -437,7 +437,7 @@ describe 'API v3 file links resource' do
context "when more than #{Storages::Peripherals::ParseCreateParamsService::MAX_ELEMENTS} embedded elements" do
let(: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' do
let(:message) { "Too many elements created at once. Expected #{max} at most, got #{too_many}." }
@@ -558,9 +558,10 @@ describe 'API v3 file links resource' do
describe 'with successful response' do
before 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))
end
it 'responds successfully' do
@@ -573,9 +574,12 @@ describe 'API v3 file links resource' do
describe 'with query failed' do
before 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 path
end
diff --git a/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb b/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb
index 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 do
context 'with query failed' do
before 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' do
let(:error) { :not_authorized }
it { expect(last_response.status).to be(500) }
end
- context 'due to internal error' do
+ context 'with internal error' do
let(:error) { :error }
it { expect(last_response.status).to be(500) }
end
- context 'due to not found' do
+ context 'with not found' do
let(:error) { :not_found }
it 'fails with outbound request failure' do
@@ -146,9 +149,10 @@ describe 'API v3 storage files', content_type: :json, webmock: true do
describe 'with successful response' do
before 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))
end
subject { last_response.body }
@@ -166,9 +170,12 @@ describe 'API v3 storage files', content_type: :json, webmock: true do
context 'with query failed' do
before 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))
+ )
end
describe 'due to authorization failure' do
diff --git a/modules/storages/spec/workers/manage_nextcloud_integration_job_spec.rb b/modules/storages/spec/workers/manage_nextcloud_integration_job_spec.rb
index 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/IndexedLet
let(:group_users_response_body) do
<<~XML
<?xml version="1.0"?>
@@ -312,11 +313,13 @@ describe ManageNextcloudIntegrationJob, type: :job, webmock: true do
let(: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/IndexedLet
it 'has a schedule set' do
expect(described_class.cron_expression).to eq('*/5 * * * *')
end
+ # rubocop:disable RSpec/ExampleLength
it 'does the job' do
storage = create(:storage,
host: 'https://example.com',
@@ -442,4 +445,5 @@ describe ManageNextcloudIntegrationJob, type: :job, webmock: true do
expect(request_stubs).to all have_been_requested
end
+ # rubocop:enable RSpec/ExampleLength
end