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

Makes tests pass xD

Marcello Rochaee38a4be1f67
diff --git a/modules/storages/lib/api/v3/file_links/file_links_download_api.rb b/modules/storages/lib/api/v3/file_links/file_links_download_api.rb
index 479e1e96a8a..d2760fb561c 100644
--- a/modules/storages/lib/api/v3/file_links/file_links_download_api.rb
+++ b/modules/storages/lib/api/v3/file_links/file_links_download_api.rb
@@ -33,10 +33,11 @@ class API::V3::FileLinks::FileLinksDownloadAPI < API::OpenProjectAPI
resources :download do
get do
Storages::Peripherals::StorageRequests
- .new(storage: @file_link.storage)
- .download_link_query
- .call(user: User.current, file_link: @file_link)
- .match(
+ .call(
+ storage: @file_link.storage,
+ operation: :download_link_query,
+ user: User.current, file_link: @file_link
+ ).match(
on_success: ->(url) do
redirect(url, body: "The requested resource can be downloaded from #{url}")
status(303)
diff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
index cb9005dd95c..65844334f8b 100644
--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb
+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
@@ -86,7 +86,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'must return a download link URL' do
result = subject.call(operation: :download_link_query, storage:, user:, file_link:)
expect(result).to be_success
- expect(result.result).to be_eql(uri)
+ expect(result.result).to eql(uri)
end
context 'if Nextcloud is running on a sub path' do
@@ -95,7 +95,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'must return a download link URL' do
result = subject.call(operation: :download_link_query, storage:, user:, file_link:)
expect(result).to be_success
- expect(result.result).to be_eql(uri)
+ expect(result.result).to eql(uri)
end
end
end
@@ -145,7 +145,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it "must return :#{symbol} ServiceResult" do
result = subject.call(operation: :download_link_query, user:, file_link:, storage:)
expect(result).to be_failure
- expect(result.errors.code).to be(symbol)
+ expect(result.errors.code).to eq(symbol)
end
end
end
@@ -310,9 +310,9 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'must return an upload link URL' do
link = subject.call(operation: :upload_link_query, storage:, user:, data: query_payload)
.result
- expect(link.destination.path).to be_eql("/index.php/apps/integration_openproject/direct-upload/#{upload_token}")
- expect(link.destination.host).to be_eql(URI(url).host)
- expect(link.destination.scheme).to be_eql(URI(url).scheme)
+ expect(link.destination.path).to eql("/index.php/apps/integration_openproject/direct-upload/#{upload_token}")
+ expect(link.destination.host).to eql(URI(url).host)
+ expect(link.destination.scheme).to eql(URI(url).scheme)
expect(link.destination.user).to be_nil
expect(link.destination.password).to be_nil
expect(link.method).to eq(:post)
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_api_spec.rb
similarity index 97%
rename from modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb
rename to modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb
index ee9e2e76e2b..7857f548a7a 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_api_spec.rb
@@ -558,10 +558,10 @@ RSpec.describe 'API v3 file links resource' do
describe 'with successful response' do
before do
- 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))
+ Storages::Peripherals::Registry.stub(
+ 'queries.nextcloud.download_link_query',
+ ->(_) { ServiceResult.success(result: url) }
+ )
end
it 'responds successfully' do
@@ -574,11 +574,9 @@ RSpec.describe 'API v3 file links resource' do
describe 'with query failed' do
before do
- 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))
+ Storages::Peripherals::Registry.stub(
+ 'queries.nextcloud.download_link_query',
+ ->(_) { ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error)) }
)
get path
diff --git a/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb b/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb
index ba1f054a6f6..a1d46287d24 100644
--- a/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb
+++ b/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb
@@ -28,14 +28,11 @@
require 'spec_helper'
require_module_spec_helper
-require 'dry/container/stub'
RSpec.describe 'API v3 storage files', content_type: :json, webmock: true do
include API::V3::Utilities::PathHelper
include StorageServerHelpers
- Storages::Peripherals::Registry.enable_stubs!
-
let(:permissions) { %i(view_work_packages view_file_links) }
let(:project) { create(:project) }
@@ -61,8 +58,6 @@ RSpec.describe 'API v3 storage files', content_type: :json, webmock: true do
login_as current_user
end
- after { Storages::Peripherals::Registry.unstub }
-
describe 'GET /api/v3/storages/:storage_id/files' do
let(:path) { api_v3_paths.storage_files(storage.id) }
@@ -292,10 +287,10 @@ RSpec.describe 'API v3 storage files', content_type: :json, webmock: true do
describe 'with successful response' do
before do
- 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))
+ Storages::Peripherals::Registry.stub(
+ 'queries.nextcloud.upload_link_query',
+ ->(_) { ServiceResult.success(result: upload_link) }
+ )
end
subject { last_response.body }
diff --git a/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rb b/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rb
index 440ad7a4c02..60f3b7caf8c 100644
--- a/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rb
+++ b/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rb
@@ -29,7 +29,6 @@
#++
require 'spec_helper'
-require 'dry/container/stub'
RSpec.describe Storages::FileLinkSyncService, type: :model do
let(:user) { create(:user) }
@@ -47,9 +46,6 @@ RSpec.describe Storages::FileLinkSyncService, type: :model do
subject(:service) { described_class.new(user:).call(file_links) }
- before { Storages::Peripherals::Registry.enable_stubs! }
- after { Storages::Peripherals::Registry.unstub }
-
describe '#call' do
context 'with one file link' do
let(:file_info) { build(:storage_file_info) }
diff --git a/modules/storages/spec/spec_helper.rb b/modules/storages/spec/spec_helper.rb
index 15d27f62fe6..8c8d772a756 100644
--- a/modules/storages/spec/spec_helper.rb
+++ b/modules/storages/spec/spec_helper.rb
@@ -33,5 +33,11 @@
# This will include any support file from OpenProject core
require 'spec_helper'
require 'dry/container/stub'
+
# Loads files from relative support/ directory
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
+
+RSpec.configure do |config|
+ config.before(:suite) { Storages::Peripherals::Registry.enable_stubs! }
+ config.append_after { Storages::Peripherals::Registry.unstub }
+end