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
[#61178] Extract user_query stub to a method.
Pavel Balashou3e517c617ffd
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.rbindex 049ae17fb7d..096b26b63fe 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@@ -31,9 +31,8 @@require "spec_helper"require_module_spec_helper-RSpec.describe "API v3 storage files", :webmock, content_type: :json do+RSpec.describe "API v3 storage files", :storage_server_helpers, :webmock, content_type: :json doinclude API::V3::Utilities::PathHelper- include StorageServerHelperslet(:permissions) { %i(view_work_packages view_file_links) }let(:project) { create(:project) }diff --git a/modules/storages/spec/requests/api/v3/storages/storage_folders_api_spec.rb b/modules/storages/spec/requests/api/v3/storages/storage_folders_api_spec.rbindex fddfa2a9bdc..beeae1561a0 100644--- a/modules/storages/spec/requests/api/v3/storages/storage_folders_api_spec.rb+++ b/modules/storages/spec/requests/api/v3/storages/storage_folders_api_spec.rb@@ -31,9 +31,8 @@require "spec_helper"require_module_spec_helper-RSpec.describe "API v3 storage folders", :webmock, content_type: :json do+RSpec.describe "API v3 storage folders", :storage_server_helpers, :webmock, content_type: :json doinclude API::V3::Utilities::PathHelper- include StorageServerHelperslet(:permissions) { %i(view_work_packages view_file_links manage_file_links) }let(:project) { create(:project) }diff --git a/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb b/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rbindex 844a1a3d8db..013a557f046 100644--- a/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb+++ b/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb@@ -31,9 +31,8 @@require "spec_helper"require_module_spec_helper-RSpec.describe "API v3 storages resource", :webmock, content_type: :json do+RSpec.describe "API v3 storages resource", :storage_server_helpers, :webmock, content_type: :json doinclude API::V3::Utilities::PathHelper- include StorageServerHelpersinclude UserPermissionsHelpershared_let(:permissions) { %i(view_work_packages view_file_links) }diff --git a/spec/requests/oauth_clients/callback_flow_spec.rb b/spec/requests/oauth_clients/callback_flow_spec.rbindex 28c27210000..8a22f004bd7 100644--- a/spec/requests/oauth_clients/callback_flow_spec.rb+++ b/spec/requests/oauth_clients/callback_flow_spec.rb@@ -104,9 +104,9 @@ RSpec.describe "OAuthClient callback endpoint" docontext "with valid params" docontext "without errors" do- it "redirects to the URL that was referenced by the state param and held by a cookie", :webmock do- stub_request(:get, File.join(storage.host, "/ocs/v1.php/cloud/user"))- .to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"), headers: {})+ it "redirects to the URL that was referenced by the state param and held by a cookie", :storage_server_helpers,+ :webmock do+ stub_nextcloud_user_query(storage.host)uri.query = URI.encode_www_form([["code", code], ["state", state]])get uri.to_sdiff --git a/spec/services/oauth_clients/connection_manager_spec.rb b/spec/services/oauth_clients/connection_manager_spec.rbindex 694f2aeb897..cbdc5f1fe07 100644--- a/spec/services/oauth_clients/connection_manager_spec.rb+++ b/spec/services/oauth_clients/connection_manager_spec.rb@@ -98,7 +98,7 @@ RSpec.describe OAuthClients::ConnectionManager, :webmock, type: :model dosubject { instance.code_to_token(code) }- context "with happy path" do+ context "with happy path", :storage_server_helpers dobefore do# Simulate a successful authorization returning the tokensresponse_body = {@@ -111,12 +111,7 @@ RSpec.describe OAuthClients::ConnectionManager, :webmock, type: :model dostub_request(:any, File.join(host, "/index.php/apps/oauth2/api/v1/token")).to_return(status: 200, body: response_body, headers: { "content-type" => "application/json; charset=utf-8" })- stub_request(:get, File.join(host, "/ocs/v1.php/cloud/user")).with(- headers: {- "Authorization" => "Bearer yjTDZ...RYvRH",- "Ocs-Apirequest" => "true"- }- ).to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"), headers: {})+ stub_nextcloud_user_query(host)endit "returns a valid ClientToken object and issues an appropriate event" dodiff --git a/spec/services/remote_identities/create_service_spec.rb b/spec/services/remote_identities/create_service_spec.rbindex 0d8fb885ae3..e6f64065abb 100644--- a/spec/services/remote_identities/create_service_spec.rb+++ b/spec/services/remote_identities/create_service_spec.rb@@ -4,7 +4,7 @@ require "spec_helper"require "services/base_services/behaves_like_create_service"-RSpec.describe RemoteIdentities::CreateService, :webmock, type: :model do+RSpec.describe RemoteIdentities::CreateService, :storage_server_helpers, :webmock, type: :model dolet(:user) { create(:user) }let(:storage) { create(:nextcloud_storage_configured) }let(:oauth_config) { storage.oauth_configuration }@@ -16,9 +16,7 @@ RSpec.describe RemoteIdentities::CreateService, :webmock, type: :model dosubject(:service) { described_class.new(user:, oauth_config:, oauth_client_token:) }- before do- stub_request(:get, File.join(storage.host, "/ocs/v1.php/cloud/user")).to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"), headers: {})- end+ before { stub_nextcloud_user_query(storage.host) }describe ".call" doit "requires a user, a oauth configuration and a rack token" dodiff --git a/modules/storages/spec/support/storage_server_helpers.rb b/spec/support/storage_server_helpers.rbsimilarity index 94%rename from modules/storages/spec/support/storage_server_helpers.rbrename to spec/support/storage_server_helpers.rbindex c7851705ff1..d8e19ed6ab8 100644--- a/modules/storages/spec/support/storage_server_helpers.rb+++ b/spec/support/storage_server_helpers.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -129,6 +131,11 @@ module StorageServerHelpersendend+ def stub_nextcloud_user_query(host)+ stub_request(:get, normalize_url("#{host}/ocs/v1.php/cloud/user"))+ .to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"))+ end+def stub_outbound_storage_files_request_for(storage:, remote_identity:)root_xml_response = build(:webdav_data)folder1_xml_response = build(:webdav_data_folder)@@ -152,7 +159,7 @@ module StorageServerHelpers.to_return(status: 207, body: folder1_xml_response, headers: {})stub_request(:get, normalize_url("#{storage.host}/ocs/v1.php/apps/integration_openproject/fileinfo/11")).to_return(status: 200, body: folder1_fileinfo_response.to_json, headers: {})- stub_request(:get, normalize_url("#{storage.host}/ocs/v1.php/cloud/user")).to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"))+ stub_nextcloud_user_query(storage.host)stub_request(:delete,normalize_url("#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \