Fixing many bugs in specs

pull/10183/head
Wieland Lindenthal 3 years ago
parent a8df00e619
commit 9138b2d134
No known key found for this signature in database
GPG Key ID: 7ACCABE64832A0C6
  1. 6
      modules/storages/app/contracts/storages/storages/base_contract.rb
  2. 8
      modules/storages/app/models/storages/storage.rb
  3. 15
      modules/storages/spec/contracts/storages/shared_contract_examples.rb
  4. 22
      modules/storages/spec/models/storage_spec.rb
  5. 4
      modules/storages/spec/services/storages/create_service_spec.rb
  6. 4
      modules/storages/spec/services/storages/delete_service_spec.rb

@ -31,12 +31,18 @@ require 'uri'
module Storages::Storages
class BaseContract < ::ModelContract
PROVIDER_TYPES = %w[nextcloud].freeze
MINIMAL_NEXTCLOUD_VERSION = 23
include ::Storages::Storages::Concerns::ManageStoragesGuarded
include ActiveModel::Validations
attribute :name
validates :name, length: { minimum: 1, maximum: 255 }, allow_nil: false
attribute :provider_type
validates :provider_type, inclusion: { in: ->(*) { PROVIDER_TYPES } }, allow_nil: false
attribute :creator, writable: false do
validate_creator_is_user
end

@ -32,14 +32,6 @@ class Storages::Storage < ApplicationRecord
has_many :projects_storages, dependent: :destroy, class_name: 'Storages::ProjectStorage'
has_many :projects, through: :projects_storages
PROVIDER_TYPES = %w[nextcloud].freeze
validates_uniqueness_of :host
validates :name, length: { minimum: 1, maximum: 255 }, allow_nil: false
validates_uniqueness_of :name
validates :provider_type, inclusion: { in: ->(*) { PROVIDER_TYPES } }, allow_nil: false
def visible_to?(user)
user.allowed_to_globally?(:view_file_links)
end
end

@ -93,13 +93,8 @@ shared_examples_for 'storage contract', webmock: true do
it_behaves_like 'contract is invalid'
end
context 'as it is not unique' do
before do
::Storages::Storage.create(name: storage_name,
provider_type: storage_provider_type,
host: storage_host,
creator: storage_creator)
end
context 'as it is nil' do
let(:storage_name) { nil }
it_behaves_like 'contract is invalid'
end
@ -132,6 +127,12 @@ shared_examples_for 'storage contract', webmock: true do
it_behaves_like 'contract is invalid'
end
context 'as host is an empty string' do
let(:storage_host) { '' }
it_behaves_like 'contract is invalid'
end
context 'as host is nil' do
let(:storage_host) { nil }

@ -42,30 +42,14 @@ describe ::Storages::Storage, type: :model do
storage = described_class.create default_attributes
expect(storage).to be_valid
end
it "fails the validation if name is empty string" do
expect(described_class.create(default_attributes.merge({ name: "" }))).to be_invalid
end
it "fails the validation if name is nil" do
expect(described_class.create(default_attributes.merge({ name: nil }))).to be_invalid
end
it "fails the validation if host is empty string" do
expect(described_class.create(default_attributes.merge({ host: '' }))).to be_invalid
end
it "fails the validation if host is nil" do
expect(described_class.create(default_attributes.merge({ host: nil }))).to be_invalid
end
context "having already one instance" do
context "with one instance already present" do
let(:old_storage) { described_class.create default_attributes }
before do
old_storage
end
it "fails the validation if name is not unique" do
expect(described_class.create(default_attributes.merge({ host: 'https://example2.com' }))).to be_invalid
end

@ -32,5 +32,7 @@ require 'spec_helper'
require 'services/base_services/behaves_like_create_service'
describe ::Storages::Storages::CreateService, type: :model do
it_behaves_like 'BaseServices create service'
it_behaves_like 'BaseServices create service' do
let(:factory) { :storage }
end
end

@ -30,5 +30,7 @@ require 'spec_helper'
require 'services/base_services/behaves_like_delete_service'
describe ::Storages::Storages::DeleteService, type: :model do
it_behaves_like 'BaseServices delete service'
it_behaves_like 'BaseServices delete service' do
let(:factory) { :storage }
end
end

Loading…
Cancel
Save