Commit 4ae63977 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'rs-spec-models-parity-ee' into 'master'

CE-EE parity for spec/models

Closes #6665

See merge request gitlab-org/gitlab-ee!6277
parents 364cc667 8a5afebb
...@@ -124,4 +124,89 @@ describe ApplicationSetting do ...@@ -124,4 +124,89 @@ describe ApplicationSetting do
end end
end end
end end
describe '#repository_size_limit column' do
it 'support values up to 8 exabytes' do
setting.update_column(:repository_size_limit, 8.exabytes - 1)
setting.reload
expect(setting.repository_size_limit).to eql(8.exabytes - 1)
end
end
describe 'elasticsearch licensing' do
before do
setting.elasticsearch_search = true
setting.elasticsearch_indexing = true
end
def expect_is_es_licensed
expect(License).to receive(:feature_available?).with(:elastic_search).at_least(:once)
end
it 'disables elasticsearch when unlicensed' do
expect_is_es_licensed.and_return(false)
expect(setting.elasticsearch_indexing?).to be_falsy
expect(setting.elasticsearch_indexing).to be_falsy
expect(setting.elasticsearch_search?).to be_falsy
expect(setting.elasticsearch_search).to be_falsy
end
it 'enables elasticsearch when licensed' do
expect_is_es_licensed.and_return(true)
expect(setting.elasticsearch_indexing?).to be_truthy
expect(setting.elasticsearch_indexing).to be_truthy
expect(setting.elasticsearch_search?).to be_truthy
expect(setting.elasticsearch_search).to be_truthy
end
end
describe '#elasticsearch_url' do
it 'presents a single URL as a one-element array' do
setting.elasticsearch_url = 'http://example.com'
expect(setting.elasticsearch_url).to eq(%w[http://example.com])
end
it 'presents multiple URLs as a many-element array' do
setting.elasticsearch_url = 'http://example.com,https://invalid.invalid:9200'
expect(setting.elasticsearch_url).to eq(%w[http://example.com https://invalid.invalid:9200])
end
it 'strips whitespace from around URLs' do
setting.elasticsearch_url = ' http://example.com, https://invalid.invalid:9200 '
expect(setting.elasticsearch_url).to eq(%w[http://example.com https://invalid.invalid:9200])
end
it 'strips trailing slashes from URLs' do
setting.elasticsearch_url = 'http://example.com/, https://example.com:9200/, https://example.com:9200/prefix//'
expect(setting.elasticsearch_url).to eq(%w[http://example.com https://example.com:9200 https://example.com:9200/prefix])
end
end
describe '#elasticsearch_config' do
it 'places all elasticsearch configuration values into a hash' do
setting.update!(
elasticsearch_url: 'http://example.com:9200',
elasticsearch_aws: false,
elasticsearch_aws_region: 'test-region',
elasticsearch_aws_access_key: 'test-access-key',
elasticsearch_aws_secret_access_key: 'test-secret-access-key'
)
expect(setting.elasticsearch_config).to eq(
url: ['http://example.com:9200'],
aws: false,
aws_region: 'test-region',
aws_access_key: 'test-access-key',
aws_secret_access_key: 'test-secret-access-key'
)
end
end
end end
...@@ -4,9 +4,109 @@ describe ProtectedBranch do ...@@ -4,9 +4,109 @@ describe ProtectedBranch do
subject { create(:protected_branch) } subject { create(:protected_branch) }
let(:project) { subject.project } let(:project) { subject.project }
let(:user) { create(:user) }
shared_examples 'uniqueness validation' do |access_level_class|
let(:factory_name) { access_level_class.to_s.underscore.sub('/', '_').to_sym }
let(:association_name) { access_level_class.to_s.underscore.sub('protected_branch/', '').pluralize.to_sym }
human_association_name = access_level_class.to_s.underscore.humanize.sub('Protected branch/', '')
context "while checking uniqueness of a role-based #{human_association_name}" do
it "allows a single #{human_association_name} for a role (per protected branch)" do
first_protected_branch = create(:protected_branch, default_access_level: false)
second_protected_branch = create(:protected_branch, default_access_level: false)
first_protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
second_protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
expect(first_protected_branch).to be_valid
expect(second_protected_branch).to be_valid
first_protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
expect(first_protected_branch).to be_invalid
expect(first_protected_branch.errors.full_messages.first).to match("access level has already been taken")
end
it "does not count a user-based #{human_association_name} with an `access_level` set" do
protected_branch = create(:protected_branch, default_access_level: false)
protected_branch.send(association_name) << build(factory_name, user: user, access_level: Gitlab::Access::MASTER)
protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
expect(protected_branch).to be_valid
end
it "does not count a group-based #{human_association_name} with an `access_level` set" do
group = create(:group)
protected_branch = create(:protected_branch, default_access_level: false)
protected_branch.send(association_name) << build(factory_name, group: group, access_level: Gitlab::Access::MASTER)
protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
expect(protected_branch).to be_valid
end
end
context "while checking uniqueness of a user-based #{human_association_name}" do
it "allows a single #{human_association_name} for a user (per protected branch)" do
first_protected_branch = create(:protected_branch, default_access_level: false)
second_protected_branch = create(:protected_branch, default_access_level: false)
first_protected_branch.send(association_name) << build(factory_name, user: user)
second_protected_branch.send(association_name) << build(factory_name, user: user)
expect(first_protected_branch).to be_valid
expect(second_protected_branch).to be_valid
first_protected_branch.send(association_name) << build(factory_name, user: user)
expect(first_protected_branch).to be_invalid
expect(first_protected_branch.errors.full_messages.first).to match("user has already been taken")
end
it "ignores the `access_level` while validating a user-based #{human_association_name}" do
protected_branch = create(:protected_branch, default_access_level: false)
protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
protected_branch.send(association_name) << build(factory_name, user: user, access_level: Gitlab::Access::MASTER)
expect(protected_branch).to be_valid
end
end
context "while checking uniqueness of a group-based #{human_association_name}" do
let(:group) { create(:group) }
it "allows a single #{human_association_name} for a group (per protected branch)" do
first_protected_branch = create(:protected_branch, default_access_level: false)
second_protected_branch = create(:protected_branch, default_access_level: false)
first_protected_branch.send(association_name) << build(factory_name, group: group)
second_protected_branch.send(association_name) << build(factory_name, group: group)
expect(first_protected_branch).to be_valid
expect(second_protected_branch).to be_valid
first_protected_branch.send(association_name) << build(factory_name, group: group)
expect(first_protected_branch).to be_invalid
expect(first_protected_branch.errors.full_messages.first).to match("group has already been taken")
end
it "ignores the `access_level` while validating a group-based #{human_association_name}" do
protected_branch = create(:protected_branch, default_access_level: false)
protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
protected_branch.send(association_name) << build(factory_name, group: group, access_level: Gitlab::Access::MASTER)
expect(protected_branch).to be_valid
end
end
end
it_behaves_like 'uniqueness validation', ProtectedBranch::MergeAccessLevel
it_behaves_like 'uniqueness validation', ProtectedBranch::PushAccessLevel
describe '#can_unprotect?' do describe '#can_unprotect?' do
let(:user) { create(:user) }
let(:admin) { create(:user, :admin) } let(:admin) { create(:user, :admin) }
let(:master) do let(:master) do
create(:user).tap { |user| project.add_master(user) } create(:user).tap { |user| project.add_master(user) }
......
...@@ -5,6 +5,10 @@ describe Group do ...@@ -5,6 +5,10 @@ describe Group do
it { is_expected.to include_module(EE::Group) } it { is_expected.to include_module(EE::Group) }
describe 'associations' do
it { is_expected.to have_many(:audit_events).dependent(false) }
end
describe 'states' do describe 'states' do
it { is_expected.to be_ldap_sync_ready } it { is_expected.to be_ldap_sync_ready }
......
require 'spec_helper'
describe Identity do
describe 'relations' do
it { is_expected.to belong_to(:saml_provider) }
end
context 'with saml_provider' do
it 'allows user to have records with different groups' do
_identity_one = create(:identity, provider: 'group_saml', saml_provider: create(:saml_provider))
identity_two = create(:identity, provider: 'group_saml', saml_provider: create(:saml_provider))
expect(identity_two).to be_valid
end
end
end
require 'spec_helper'
describe RemoteMirror do
let(:project) { create(:project, :repository, :remote_mirror) }
describe '#sync' do
let(:remote_mirror) { project.remote_mirrors.first }
context 'as a Geo secondary' do
it 'returns nil' do
allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
expect(remote_mirror.sync).to be_nil
end
end
end
end
...@@ -7,6 +7,13 @@ describe Repository do ...@@ -7,6 +7,13 @@ describe Repository do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:repository) { project.repository } let(:repository) { project.repository }
def create_remote_branch(remote_name, branch_name, target)
rugged = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
repository.rugged
end
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", target.id)
end
describe '#after_sync' do describe '#after_sync' do
it 'expires repository cache' do it 'expires repository cache' do
expect(repository).to receive(:expire_all_method_caches) expect(repository).to receive(:expire_all_method_caches)
...@@ -62,4 +69,25 @@ describe Repository do ...@@ -62,4 +69,25 @@ describe Repository do
end end
end end
end end
describe '#after_sync' do
it 'expires repository cache' do
expect(repository).to receive(:expire_all_method_caches)
expect(repository).to receive(:expire_branch_cache)
expect(repository).to receive(:expire_content_cache)
repository.after_sync
end
end
describe '#upstream_branches' do
it 'returns branches from the upstream remote' do
masterrev = repository.find_branch('master').dereferenced_target
create_remote_branch('upstream', 'upstream_branch', masterrev)
expect(repository.upstream_branches.size).to eq(1)
expect(repository.upstream_branches.first).to be_an_instance_of(Gitlab::Git::Branch)
expect(repository.upstream_branches.first.name).to eq('upstream_branch')
end
end
end end
require 'spec_helper'
describe Service do
describe 'Available services' do
it { expect(described_class.available_services_names).to include("jenkins", "jira") }
end
end
...@@ -489,91 +489,6 @@ describe ApplicationSetting do ...@@ -489,91 +489,6 @@ describe ApplicationSetting do
end end
end end
describe '#repository_size_limit column' do
it 'support values up to 8 exabytes' do
setting.update_column(:repository_size_limit, 8.exabytes - 1)
setting.reload
expect(setting.repository_size_limit).to eql(8.exabytes - 1)
end
end
describe 'elasticsearch licensing' do
before do
setting.elasticsearch_search = true
setting.elasticsearch_indexing = true
end
def expect_is_es_licensed
expect(License).to receive(:feature_available?).with(:elastic_search).at_least(:once)
end
it 'disables elasticsearch when unlicensed' do
expect_is_es_licensed.and_return(false)
expect(setting.elasticsearch_indexing?).to be_falsy
expect(setting.elasticsearch_indexing).to be_falsy
expect(setting.elasticsearch_search?).to be_falsy
expect(setting.elasticsearch_search).to be_falsy
end
it 'enables elasticsearch when licensed' do
expect_is_es_licensed.and_return(true)
expect(setting.elasticsearch_indexing?).to be_truthy
expect(setting.elasticsearch_indexing).to be_truthy
expect(setting.elasticsearch_search?).to be_truthy
expect(setting.elasticsearch_search).to be_truthy
end
end
describe '#elasticsearch_url' do
it 'presents a single URL as a one-element array' do
setting.elasticsearch_url = 'http://example.com'
expect(setting.elasticsearch_url).to eq(%w[http://example.com])
end
it 'presents multiple URLs as a many-element array' do
setting.elasticsearch_url = 'http://example.com,https://invalid.invalid:9200'
expect(setting.elasticsearch_url).to eq(%w[http://example.com https://invalid.invalid:9200])
end
it 'strips whitespace from around URLs' do
setting.elasticsearch_url = ' http://example.com, https://invalid.invalid:9200 '
expect(setting.elasticsearch_url).to eq(%w[http://example.com https://invalid.invalid:9200])
end
it 'strips trailing slashes from URLs' do
setting.elasticsearch_url = 'http://example.com/, https://example.com:9200/, https://example.com:9200/prefix//'
expect(setting.elasticsearch_url).to eq(%w[http://example.com https://example.com:9200 https://example.com:9200/prefix])
end
end
describe '#elasticsearch_config' do
it 'places all elasticsearch configuration values into a hash' do
setting.update!(
elasticsearch_url: 'http://example.com:9200',
elasticsearch_aws: false,
elasticsearch_aws_region: 'test-region',
elasticsearch_aws_access_key: 'test-access-key',
elasticsearch_aws_secret_access_key: 'test-secret-access-key'
)
expect(setting.elasticsearch_config).to eq(
url: ['http://example.com:9200'],
aws: false,
aws_region: 'test-region',
aws_access_key: 'test-access-key',
aws_secret_access_key: 'test-secret-access-key'
)
end
end
describe '#allowed_key_types' do describe '#allowed_key_types' do
it 'includes all key types by default' do it 'includes all key types by default' do
expect(setting.allowed_key_types).to contain_exactly(*described_class::SUPPORTED_KEY_TYPES) expect(setting.allowed_key_types).to contain_exactly(*described_class::SUPPORTED_KEY_TYPES)
......
...@@ -18,7 +18,6 @@ describe Group do ...@@ -18,7 +18,6 @@ describe Group do
it { is_expected.to have_many(:uploads) } it { is_expected.to have_many(:uploads) }
it { is_expected.to have_one(:chat_team) } it { is_expected.to have_one(:chat_team) }
it { is_expected.to have_many(:custom_attributes).class_name('GroupCustomAttribute') } it { is_expected.to have_many(:custom_attributes).class_name('GroupCustomAttribute') }
it { is_expected.to have_many(:audit_events).dependent(false) }
it { is_expected.to have_many(:badges).class_name('GroupBadge') } it { is_expected.to have_many(:badges).class_name('GroupBadge') }
describe '#members & #requesters' do describe '#members & #requesters' do
......
...@@ -3,7 +3,6 @@ require 'spec_helper' ...@@ -3,7 +3,6 @@ require 'spec_helper'
describe Identity do describe Identity do
describe 'relations' do describe 'relations' do
it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:saml_provider) }
end end
describe 'fields' do describe 'fields' do
...@@ -105,13 +104,4 @@ describe Identity do ...@@ -105,13 +104,4 @@ describe Identity do
end end
end end
end end
context 'with saml_provider' do
it 'allows user to have records with different groups' do
_identity_one = create(:identity, provider: 'group_saml', saml_provider: create(:saml_provider))
identity_two = create(:identity, provider: 'group_saml', saml_provider: create(:saml_provider))
expect(identity_two).to be_valid
end
end
end end
...@@ -7,105 +7,6 @@ describe ProtectedBranch do ...@@ -7,105 +7,6 @@ describe ProtectedBranch do
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
end end
describe "Uniqueness validations" do
[ProtectedBranch::MergeAccessLevel, ProtectedBranch::PushAccessLevel].each do |access_level_class|
let(:user) { create(:user) }
let(:factory_name) { access_level_class.to_s.underscore.sub('/', '_').to_sym }
let(:association_name) { access_level_class.to_s.underscore.sub('protected_branch/', '').pluralize.to_sym }
human_association_name = access_level_class.to_s.underscore.humanize.sub('Protected branch/', '')
context "while checking uniqueness of a role-based #{human_association_name}" do
it "allows a single #{human_association_name} for a role (per protected branch)" do
first_protected_branch = create(:protected_branch, default_access_level: false)
second_protected_branch = create(:protected_branch, default_access_level: false)
first_protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
second_protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
expect(first_protected_branch).to be_valid
expect(second_protected_branch).to be_valid
first_protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
expect(first_protected_branch).to be_invalid
expect(first_protected_branch.errors.full_messages.first).to match("access level has already been taken")
end
it "does not count a user-based #{human_association_name} with an `access_level` set" do
protected_branch = create(:protected_branch, default_access_level: false)
protected_branch.send(association_name) << build(factory_name, user: user, access_level: Gitlab::Access::MASTER)
protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
expect(protected_branch).to be_valid
end
it "does not count a group-based #{human_association_name} with an `access_level` set" do
group = create(:group)
protected_branch = create(:protected_branch, default_access_level: false)
protected_branch.send(association_name) << build(factory_name, group: group, access_level: Gitlab::Access::MASTER)
protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
expect(protected_branch).to be_valid
end
end
context "while checking uniqueness of a user-based #{human_association_name}" do
it "allows a single #{human_association_name} for a user (per protected branch)" do
first_protected_branch = create(:protected_branch, default_access_level: false)
second_protected_branch = create(:protected_branch, default_access_level: false)
first_protected_branch.send(association_name) << build(factory_name, user: user)
second_protected_branch.send(association_name) << build(factory_name, user: user)
expect(first_protected_branch).to be_valid
expect(second_protected_branch).to be_valid
first_protected_branch.send(association_name) << build(factory_name, user: user)
expect(first_protected_branch).to be_invalid
expect(first_protected_branch.errors.full_messages.first).to match("user has already been taken")
end
it "ignores the `access_level` while validating a user-based #{human_association_name}" do
protected_branch = create(:protected_branch, default_access_level: false)
protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
protected_branch.send(association_name) << build(factory_name, user: user, access_level: Gitlab::Access::MASTER)
expect(protected_branch).to be_valid
end
end
context "while checking uniqueness of a group-based #{human_association_name}" do
let(:group) { create(:group) }
it "allows a single #{human_association_name} for a group (per protected branch)" do
first_protected_branch = create(:protected_branch, default_access_level: false)
second_protected_branch = create(:protected_branch, default_access_level: false)
first_protected_branch.send(association_name) << build(factory_name, group: group)
second_protected_branch.send(association_name) << build(factory_name, group: group)
expect(first_protected_branch).to be_valid
expect(second_protected_branch).to be_valid
first_protected_branch.send(association_name) << build(factory_name, group: group)
expect(first_protected_branch).to be_invalid
expect(first_protected_branch.errors.full_messages.first).to match("group has already been taken")
end
it "ignores the `access_level` while validating a group-based #{human_association_name}" do
protected_branch = create(:protected_branch, default_access_level: false)
protected_branch.send(association_name) << build(factory_name, access_level: Gitlab::Access::MASTER)
protected_branch.send(association_name) << build(factory_name, group: group, access_level: Gitlab::Access::MASTER)
expect(protected_branch).to be_valid
end
end
end
end
describe 'Validation' do describe 'Validation' do
it { is_expected.to validate_presence_of(:project) } it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:name) }
......
...@@ -173,14 +173,6 @@ describe RemoteMirror do ...@@ -173,14 +173,6 @@ describe RemoteMirror do
end end
end end
context 'as a Geo secondary' do
it 'returns nil' do
allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
expect(remote_mirror.sync).to be_nil
end
end
context 'with remote mirroring enabled' do context 'with remote mirroring enabled' do
context 'with only protected branches enabled' do context 'with only protected branches enabled' do
context 'when it did not update in the last minute' do context 'when it did not update in the last minute' do
......
...@@ -2316,17 +2316,6 @@ describe Repository do ...@@ -2316,17 +2316,6 @@ describe Repository do
end end
end end
describe '#upstream_branches' do
it 'returns branches from the upstream remote' do
masterrev = repository.find_branch('master').dereferenced_target
create_remote_branch('upstream', 'upstream_branch', masterrev)
expect(repository.upstream_branches.size).to eq(1)
expect(repository.upstream_branches.first).to be_an_instance_of(Gitlab::Git::Branch)
expect(repository.upstream_branches.first.name).to eq('upstream_branch')
end
end
describe '#commit_count' do describe '#commit_count' do
context 'with a non-existing repository' do context 'with a non-existing repository' do
it 'returns 0' do it 'returns 0' do
...@@ -2425,16 +2414,6 @@ describe Repository do ...@@ -2425,16 +2414,6 @@ describe Repository do
end end
end end
describe '#after_sync' do
it 'expires repository cache' do
expect(repository).to receive(:expire_all_method_caches)
expect(repository).to receive(:expire_branch_cache)
expect(repository).to receive(:expire_content_cache)
repository.after_sync
end
end
def create_remote_branch(remote_name, branch_name, target) def create_remote_branch(remote_name, branch_name, target)
rugged = Gitlab::GitalyClient::StorageSettings.allow_disk_access do rugged = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
repository.rugged repository.rugged
......
...@@ -73,10 +73,6 @@ describe Service do ...@@ -73,10 +73,6 @@ describe Service do
end end
end end
describe "Available services" do
it { expect(described_class.available_services_names).to include("jenkins", "jira") }
end
describe "Template" do describe "Template" do
describe '.build_from_template' do describe '.build_from_template' do
context 'when template is invalid' do context 'when template is invalid' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment