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

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.rb
index 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::Storages
class BaseContract < ::ModelContract
- PROVIDER_TYPES = %w[nextcloud].freeze
MINIMAL_NEXTCLOUD_VERSION = 23
include ::Storages::Storages::Concerns::ManageStoragesGuarded
@@ -41,7 +40,7 @@ module Storages::Storages
validates :name, length: { minimum: 1, maximum: 255 }, allow_nil: false
attribute :provider_type
- validates :provider_type, inclusion: { in: ->(*) { PROVIDER_TYPES } }, allow_nil: false
+ validates :provider_type, inclusion: { in: ->(*) { Storages::Storage::PROVIDER_TYPES } }, allow_nil: false
attribute :creator, writable: false do
validate_creator_is_user
diff --git a/modules/storages/app/contracts/storages/storages/delete_contract.rb b/modules/storages/app/contracts/storages/storages/delete_contract.rb
index 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 Storages
module Storages
class DeleteContract < ::DeleteContract
include ::Storages::Storages::Concerns::ManageStoragesGuarded
+
+ delete_permission :admin
end
end
end
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rb
index 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 :host
validates_uniqueness_of :name
diff --git a/modules/storages/spec/contracts/storages/shared_contract_examples.rb b/modules/storages/spec/contracts/storages/shared_contract_examples.rb
index 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 do
let(: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 do
let(: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
- }
- }
- }
- }
- }
- end
before 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)
end
end
diff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rb
index 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 do
let(:admin) { create(:admin) }
before do
login_as admin
end
- it 'creates, edits and deletes storages' do
+ it 'creates, edits and deletes storages', webmock: true do
visit storages_path
expect(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 do
expect(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 do
expect(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]').click
diff --git a/modules/storages/spec/support/storage_server_helpers.rb b/modules/storages/spec/support/storage_server_helpers.rb
new file mode 100644
index 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