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
fix feature test for admin storages CRUD
Christophe Bliard4065602d8e99
diff --git a/modules/storages/app/contracts/storages/storages/base_contract.rb b/modules/storages/app/contracts/storages/storages/base_contract.rbindex 17cc4ea2624..685a31b93d7 100644--- a/modules/storages/app/contracts/storages/storages/base_contract.rb+++ b/modules/storages/app/contracts/storages/storages/base_contract.rb@@ -31,7 +31,6 @@ require 'uri'module Storages::Storagesclass BaseContract < ::ModelContract- PROVIDER_TYPES = %w[nextcloud].freezeMINIMAL_NEXTCLOUD_VERSION = 23include ::Storages::Storages::Concerns::ManageStoragesGuarded@@ -41,7 +40,7 @@ module Storages::Storagesvalidates :name, length: { minimum: 1, maximum: 255 }, allow_nil: falseattribute :provider_type- validates :provider_type, inclusion: { in: ->(*) { PROVIDER_TYPES } }, allow_nil: false+ validates :provider_type, inclusion: { in: ->(*) { Storages::Storage::PROVIDER_TYPES } }, allow_nil: falseattribute :creator, writable: false dovalidate_creator_is_userdiff --git a/modules/storages/app/contracts/storages/storages/delete_contract.rb b/modules/storages/app/contracts/storages/storages/delete_contract.rbindex 71e18a770e3..363c5713bf5 100644--- a/modules/storages/app/contracts/storages/storages/delete_contract.rb+++ b/modules/storages/app/contracts/storages/storages/delete_contract.rb@@ -31,6 +31,8 @@ module Storagesmodule Storagesclass DeleteContract < ::DeleteContractinclude ::Storages::Storages::Concerns::ManageStoragesGuarded++ delete_permission :adminendendenddiff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex 4b2b13ac167..b7913d21959 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -46,6 +46,8 @@ class Storages::Storage < ApplicationRecord# We can get the list of projects with this Storage enabled.has_many :projects, through: :projects_storages+ PROVIDER_TYPES = %w[nextcloud].freeze+# Uniqueness - no two storages should have the same host.validates_uniqueness_of :hostvalidates_uniqueness_of :namediff --git a/modules/storages/spec/contracts/storages/shared_contract_examples.rb b/modules/storages/spec/contracts/storages/shared_contract_examples.rbindex 115ba870859..66ffaeabde5 100644--- a/modules/storages/spec/contracts/storages/shared_contract_examples.rb+++ b/modules/storages/spec/contracts/storages/shared_contract_examples.rb@@ -28,9 +28,9 @@# See COPYRIGHT and LICENSE files for more details.#++-require 'spec_helper'+require_relative '../../spec_helper'-shared_examples_for 'storage contract', webmock: true do+shared_examples_for 'storage contract', :storage_server_helpers, webmock: true dolet(:storage_name) { 'Storage 1' }let(:storage_provider_type) { 'nextcloud' }let(:storage_host) { 'https://host1.example.com' }@@ -38,38 +38,15 @@ shared_examples_for 'storage contract', webmock: true dolet(:current_user) { create(:admin) }- let(:host_response_body) { '{"data": "that you want to return"}' }let(:host_response_code) { '200' }let(:host_response_message) { 'OK' }let(:host_response_major_version) { 23 }- let(:host_response_body) do- %{- {- "ocs": {- "data": {- "version": {- "major": #{host_response_major_version},- "minor": 0,- "micro": 0,- "string": "23.0.0",- "edition": "",- "extendedSupport": false- }- }- }- }- }- endbefore do- unless storage_host.nil?- stub_request(- :get,- File.join(storage_host, '/ocs/v2.php/cloud/capabilities')- ).to_return(- status: host_response_code,- body: host_response_body- )+ if storage_host.present?+ mock_server_capabilities_response(storage_host,+ response_code: host_response_code,+ response_nextcloud_major_version: host_response_major_version)endenddiff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rbindex 5de209a4a0c..4515223ae77 100644--- a/modules/storages/spec/features/admin_storages_spec.rb+++ b/modules/storages/spec/features/admin_storages_spec.rb@@ -30,14 +30,14 @@require_relative '../spec_helper'-describe 'Admin storages', type: :feature, js: true do+describe 'Admin storages', :storage_server_helpers, type: :feature, js: true dolet(:admin) { create(:admin) }before dologin_as adminend- it 'creates, edits and deletes storages' do+ it 'creates, edits and deletes storages', webmock: true dovisit storages_pathexpect(page).to have_title('File storages')expect(page.find('.title-container')).to have_text('File storages')@@ -50,6 +50,7 @@ describe 'Admin storages', type: :feature, js: true doexpect(page).to have_select 'storages_storage[provider_type]', selected: 'Nextcloud'expect(page).to have_field('storages_storage[name]', with: 'Nextcloud')+ mock_server_capabilities_response("https://example.com")page.find('#storages_storage_name').set("NC 1")page.find('#storages_storage_host').set("https://example.com")page.find('button[type=submit]').click@@ -66,6 +67,7 @@ describe 'Admin storages', type: :feature, js: true doexpect(page).to have_title("Edit: NC 1")expect(page.find('.title-container')).to have_text('Edit: NC 1')+ mock_server_capabilities_response("https://other.example.com")page.find('#storages_storage_name').set("Other NC")page.find('#storages_storage_host').set("https://other.example.com")page.find('button[type=submit]').clickdiff --git a/modules/storages/spec/support/storage_server_helpers.rb b/modules/storages/spec/support/storage_server_helpers.rbnew file mode 100644index 00000000000..6d94bc0e242--- /dev/null+++ b/modules/storages/spec/support/storage_server_helpers.rb@@ -0,0 +1,61 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module StorageServerHelpers+ def mock_server_capabilities_response(nextcloud_host, response_code: '200', response_nextcloud_major_version: 23)+ response_body =+ %{+ {+ "ocs": {+ "data": {+ "version": {+ "major": #{response_nextcloud_major_version},+ "minor": 0,+ "micro": 0,+ "string": "#{response_nextcloud_major_version}.0.0",+ "edition": "",+ "extendedSupport": false+ }+ }+ }+ }+ }++ stub_request(+ :get,+ File.join(nextcloud_host, '/ocs/v2.php/cloud/capabilities')+ ).to_return(+ status: response_code,+ body: response_body+ )+ end+end++RSpec.configure do |c|+ c.include StorageServerHelpers, :storage_server_helpers+end