Commit cbc43028 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'ee-resolve-spec-differences' into 'master'

EE: Resolve EE specific differences in the spec/ directory

See merge request gitlab-org/gitlab-ee!14823
parents 8d97cfde 0547e355
# frozen_string_literal: true
require('spec_helper')
describe Projects::ProjectMembersController do
let(:user) { create(:user) }
let(:project) { create(:project, :public, :access_requestable, namespace: namespace) }
let(:namespace) { create :group }
describe 'POST apply_import' do
subject(:apply_import) do
post(:apply_import, params: {
namespace_id: project.namespace,
project_id: project,
source_project_id: another_project.id
})
end
let(:another_project) { create(:project, :private) }
let(:member) { create(:user) }
before do
project.add_maintainer(user)
another_project.add_guest(member)
sign_in(user)
end
context 'when user can access source project members' do
before do
another_project.add_guest(user)
end
context 'and the project group has membership lock enabled' do
before do
project.namespace.update(membership_lock: true)
end
it 'responds with 403' do
apply_import
expect(response.status).to eq 403
end
end
end
end
describe 'POST create' do
let(:stranger) { create(:user) }
subject(:create_member) do
post :create, params: {
user_ids: stranger.id,
namespace_id: project.namespace,
access_level: access_level,
project_id: project
}
end
let(:access_level) { nil }
before do
project.add_maintainer(user)
sign_in(user)
end
context 'when project group has membership lock enabled' do
before do
project.namespace.update(membership_lock: true)
end
it 'responds with 403' do
create_member
expect(response.status).to eq 403
end
end
end
describe 'GET import' do
subject(:import) do
get :import, params: {
namespace_id: project.namespace,
project_id: project
}
end
before do
project.add_maintainer(user)
sign_in(user)
end
context 'when project group has membership lock enabled' do
before do
project.namespace.update(membership_lock: true)
end
it 'responds with 403' do
import
expect(response.status).to eq 403
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe "Profile access" do
include AccessMatchers
describe "GET /profile/keys" do
subject { profile_keys_path }
it { is_expected.to be_allowed_for :auditor }
end
describe "GET /profile" do
subject { profile_path }
it { is_expected.to be_allowed_for :auditor }
end
describe "GET /profile/account" do
subject { profile_account_path }
it { is_expected.to be_allowed_for :auditor }
end
describe "GET /profile/preferences" do
subject { profile_preferences_path }
it { is_expected.to be_allowed_for :auditor }
end
describe "GET /profile/audit_log" do
subject { audit_log_profile_path }
it { is_expected.to be_allowed_for :auditor }
end
describe "GET /profile/notifications" do
subject { profile_notifications_path }
it { is_expected.to be_allowed_for :auditor }
end
end
require 'spec_helper'
describe Gitlab::ObjectHierarchy do
let!(:parent) { create(:group) }
let!(:child1) { create(:group, parent: parent) }
let!(:child2) { create(:group, parent: child1) }
describe '#root' do
it 'includes only the roots' do
relation = described_class.new(Group.where(id: child2)).roots
expect(relation).to contain_exactly(parent)
end
it 'when quering parent it includes parent' do
relation = described_class.new(Group.where(id: parent)).roots
expect(relation).to contain_exactly(parent)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe API::Pipelines do
let(:user) { create(:user) }
let(:project) { create(:project, :repository, creator: user) }
let!(:pipeline) do
create(:ci_empty_pipeline, project: project, sha: project.commit.id,
ref: project.default_branch, user: user)
end
before do
project.add_maintainer(user)
end
describe 'DELETE /projects/:id/pipelines/:pipeline_id' do
context 'authorized user' do
let(:owner) { project.owner }
context 'when audit events is enabled' do
before do
stub_licensed_features(extended_audit_events: true, admin_audit_log: true)
end
it 'does not log an audit event' do
expect { delete api("/projects/#{project.id}/pipelines/#{pipeline.id}", owner) }.not_to change { SecurityEvent.count }
end
end
end
end
end
......@@ -4,8 +4,7 @@ require('spec_helper')
describe Projects::ProjectMembersController do
let(:user) { create(:user) }
let(:project) { create(:project, :public, :access_requestable, namespace: namespace) }
let(:namespace) { create :group }
let(:project) { create(:project, :public, :access_requestable) }
describe 'GET index' do
it 'has the project_members address with a 200 status code' do
......@@ -316,13 +315,6 @@ describe Projects::ProjectMembersController do
end
describe 'POST apply_import' do
subject(:apply_import) do
post(:apply_import, params: {
namespace_id: project.namespace,
project_id: project,
source_project_id: another_project.id
})
end
let(:another_project) { create(:project, :private) }
let(:member) { create(:user) }
......@@ -332,44 +324,40 @@ describe Projects::ProjectMembersController do
sign_in(user)
end
shared_context 'import applied' do
before do
post(:apply_import, params: {
namespace_id: project.namespace,
project_id: project,
source_project_id: another_project.id
})
end
end
context 'when user can access source project members' do
before do
another_project.add_guest(user)
end
it 'imports source project members' do
apply_import
include_context 'import applied'
it 'imports source project members' do
expect(project.team_members).to include member
expect(response).to set_flash.to 'Successfully imported'
expect(response).to redirect_to(
project_project_members_path(project)
)
end
context 'and the project group has membership lock enabled' do
before do
project.namespace.update(membership_lock: true)
end
it 'responds with 403' do
apply_import
expect(response.status).to eq 403
end
end
end
context 'when user is not member of a source project' do
it 'does not import team members' do
apply_import
include_context 'import applied'
it 'does not import team members' do
expect(project.team_members).not_to include member
end
it 'responds with not found' do
apply_import
expect(response.status).to eq 404
end
end
......@@ -377,78 +365,40 @@ describe Projects::ProjectMembersController do
describe 'POST create' do
let(:stranger) { create(:user) }
subject(:create_member) do
post :create, params: {
user_ids: stranger.id,
namespace_id: project.namespace,
access_level: access_level,
project_id: project
}
end
let(:access_level) { nil }
before do
project.add_maintainer(user)
sign_in(user)
end
context 'when creating owner' do
let(:access_level) { Member::OWNER }
it 'does not create a member' do
expect { create_member }.not_to change { project.members.count }
end
end
context 'when create maintainer' do
let(:access_level) { Member::MAINTAINER }
it 'creates a member' do
expect { create_member }.to change { project.members.count }.by(1)
end
end
context 'when project group has membership lock enabled' do
before do
project.namespace.update(membership_lock: true)
project.add_maintainer(user)
sign_in(user)
end
it 'responds with 403' do
create_member
expect(response.status).to eq 403
it 'does not create a member' do
expect do
post :create, params: {
user_ids: stranger.id,
namespace_id: project.namespace,
access_level: Member::OWNER,
project_id: project
}
end.to change { project.members.count }.by(0)
end
end
end
describe 'GET import' do
subject(:import) do
get :import, params: {
namespace_id: project.namespace,
project_id: project
}
end
before do
project.add_maintainer(user)
sign_in(user)
end
it 'responds with 200' do
import
expect(response.status).to eq 200
end
context 'when project group has membership lock enabled' do
context 'when create maintainer' do
before do
project.namespace.update(membership_lock: true)
project.add_maintainer(user)
sign_in(user)
end
it 'responds with 403' do
import
expect(response.status).to eq 403
it 'creates a member' do
expect do
post :create, params: {
user_ids: stranger.id,
namespace_id: project.namespace,
access_level: Member::MAINTAINER,
project_id: project
}
end.to change { project.members.count }.by(1)
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('ee', 'spec', 'db', 'schema_support')
require Rails.root.join('ee', 'spec', 'db', 'schema_support') if Gitlab.ee?
describe 'Database schema' do
prepend ::EE::DB::SchemaSupport
......
......@@ -16,7 +16,7 @@ describe 'Protected Tags', :js do
it "allows creating explicit protected tags" do
visit project_protected_tags_path(project)
set_protected_tag_name('some-tag')
set_allowed_to('create')
set_allowed_to('create') if Gitlab.ee?
click_on "Protect"
within(".protected-tags-list") { expect(page).to have_content('some-tag') }
......@@ -30,7 +30,7 @@ describe 'Protected Tags', :js do
visit project_protected_tags_path(project)
set_protected_tag_name('some-tag')
set_allowed_to('create')
set_allowed_to('create') if Gitlab.ee?
click_on "Protect"
within(".protected-tags-list") { expect(page).to have_content(commit.id[0..7]) }
......@@ -39,7 +39,7 @@ describe 'Protected Tags', :js do
it "displays an error message if the named tag does not exist" do
visit project_protected_tags_path(project)
set_protected_tag_name('some-tag')
set_allowed_to('create')
set_allowed_to('create') if Gitlab.ee?
click_on "Protect"
within(".protected-tags-list") { expect(page).to have_content('tag was removed') }
......@@ -50,7 +50,7 @@ describe 'Protected Tags', :js do
it "allows creating protected tags with a wildcard" do
visit project_protected_tags_path(project)
set_protected_tag_name('*-stable')
set_allowed_to('create')
set_allowed_to('create') if Gitlab.ee?
click_on "Protect"
within(".protected-tags-list") { expect(page).to have_content('*-stable') }
......@@ -64,7 +64,7 @@ describe 'Protected Tags', :js do
visit project_protected_tags_path(project)
set_protected_tag_name('*-stable')
set_allowed_to('create')
set_allowed_to('create') if Gitlab.ee?
click_on "Protect"
within(".protected-tags-list") do
......@@ -80,7 +80,7 @@ describe 'Protected Tags', :js do
visit project_protected_tags_path(project)
set_protected_tag_name('*-stable')
set_allowed_to('create')
set_allowed_to('create') if Gitlab.ee?
click_on "Protect"
visit project_protected_tags_path(project)
......
......@@ -10,7 +10,6 @@ describe "Profile access" do
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_allowed_for :auditor }
it { is_expected.to be_denied_for :visitor }
end
......@@ -19,7 +18,6 @@ describe "Profile access" do
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_allowed_for :auditor }
it { is_expected.to be_denied_for :visitor }
end
......@@ -28,7 +26,6 @@ describe "Profile access" do
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_allowed_for :auditor }
it { is_expected.to be_denied_for :visitor }
end
......@@ -37,7 +34,6 @@ describe "Profile access" do
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_allowed_for :auditor }
it { is_expected.to be_denied_for :visitor }
end
......@@ -46,7 +42,6 @@ describe "Profile access" do
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_allowed_for :auditor }
it { is_expected.to be_denied_for :visitor }
end
......@@ -55,7 +50,6 @@ describe "Profile access" do
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_allowed_for :auditor }
it { is_expected.to be_denied_for :visitor }
end
end
......@@ -8,7 +8,15 @@ describe 'Usage stats consent' do
let(:message) { 'To help improve GitLab, we would like to periodically collect usage information.' }
before do
allow_any_instance_of(EE::User).to receive(:has_current_license?).and_return false
if Gitlab.ee?
allow_any_instance_of(EE::User)
.to receive(:has_current_license?)
.and_return(false)
else
allow(user)
.to receive(:has_current_license?)
.and_return(false)
end
gitlab_sign_in(user)
end
......
......@@ -178,46 +178,6 @@ describe Gitlab::Ci::Config::Entry::Job do
end
end
context 'when parallel value is not correct' do
context 'when it is not a numeric value' do
let(:config) { { parallel: true } }
it 'returns error about invalid type' do
expect(entry).not_to be_valid
expect(entry.errors).to include 'job parallel is not a number'
end
end
context 'when it is lower than two' do
let(:config) { { parallel: 1 } }
it 'returns error about value too low' do
expect(entry).not_to be_valid
expect(entry.errors)
.to include 'job parallel must be greater than or equal to 2'
end
end
context 'when it is bigger than 50' do
let(:config) { { parallel: 51 } }
it 'returns error about value too high' do
expect(entry).not_to be_valid
expect(entry.errors)
.to include 'job parallel must be less than or equal to 50'
end
end
context 'when it is not an integer' do
let(:config) { { parallel: 1.5 } }
it 'returns error about wrong value' do
expect(entry).not_to be_valid
expect(entry.errors).to include 'job parallel must be an integer'
end
end
end
context 'when delayed job' do
context 'when start_in is specified' do
let(:config) { { script: 'echo', when: 'delayed', start_in: '1 day' } }
......
......@@ -4,66 +4,66 @@ describe Gitlab::GitRefValidator do
using RSpec::Parameterized::TableSyntax
context '.validate' do
it { expect(described_class.validate('feature/new')).to be_truthy }
it { expect(described_class.validate('implement_@all')).to be_truthy }
it { expect(described_class.validate('my_new_feature')).to be_truthy }
it { expect(described_class.validate('my-branch')).to be_truthy }
it { expect(described_class.validate('#1')).to be_truthy }
it { expect(described_class.validate('feature/refs/heads/foo')).to be_truthy }
it { expect(described_class.validate('feature/~new/')).to be_falsey }
it { expect(described_class.validate('feature/^new/')).to be_falsey }
it { expect(described_class.validate('feature/:new/')).to be_falsey }
it { expect(described_class.validate('feature/?new/')).to be_falsey }
it { expect(described_class.validate('feature/*new/')).to be_falsey }
it { expect(described_class.validate('feature/[new/')).to be_falsey }
it { expect(described_class.validate('feature/new/')).to be_falsey }
it { expect(described_class.validate('feature/new.')).to be_falsey }
it { expect(described_class.validate('feature\@{')).to be_falsey }
it { expect(described_class.validate('feature\new')).to be_falsey }
it { expect(described_class.validate('feature//new')).to be_falsey }
it { expect(described_class.validate('feature new')).to be_falsey }
it { expect(described_class.validate('refs/heads/')).to be_falsey }
it { expect(described_class.validate('refs/remotes/')).to be_falsey }
it { expect(described_class.validate('refs/heads/feature')).to be_falsey }
it { expect(described_class.validate('refs/remotes/origin')).to be_falsey }
it { expect(described_class.validate('-')).to be_falsey }
it { expect(described_class.validate('-branch')).to be_falsey }
it { expect(described_class.validate('+foo:bar')).to be_falsey }
it { expect(described_class.validate('foo:bar')).to be_falsey }
it { expect(described_class.validate('.tag')).to be_falsey }
it { expect(described_class.validate('my branch')).to be_falsey }
it { expect(described_class.validate("\xA0\u0000\xB0")).to be_falsey }
it { expect(described_class.validate('feature/new')).to be true }
it { expect(described_class.validate('implement_@all')).to be true }
it { expect(described_class.validate('my_new_feature')).to be true }
it { expect(described_class.validate('my-branch')).to be true }
it { expect(described_class.validate('#1')).to be true }
it { expect(described_class.validate('feature/refs/heads/foo')).to be true }
it { expect(described_class.validate('feature/~new/')).to be false }
it { expect(described_class.validate('feature/^new/')).to be false }
it { expect(described_class.validate('feature/:new/')).to be false }
it { expect(described_class.validate('feature/?new/')).to be false }
it { expect(described_class.validate('feature/*new/')).to be false }
it { expect(described_class.validate('feature/[new/')).to be false }
it { expect(described_class.validate('feature/new/')).to be false }
it { expect(described_class.validate('feature/new.')).to be false }
it { expect(described_class.validate('feature\@{')).to be false }
it { expect(described_class.validate('feature\new')).to be false }
it { expect(described_class.validate('feature//new')).to be false }
it { expect(described_class.validate('feature new')).to be false }
it { expect(described_class.validate('refs/heads/')).to be false }
it { expect(described_class.validate('refs/remotes/')).to be false }
it { expect(described_class.validate('refs/heads/feature')).to be false }
it { expect(described_class.validate('refs/remotes/origin')).to be false }
it { expect(described_class.validate('-')).to be false }
it { expect(described_class.validate('-branch')).to be false }
it { expect(described_class.validate('+foo:bar')).to be false }
it { expect(described_class.validate('foo:bar')).to be false }
it { expect(described_class.validate('.tag')).to be false }
it { expect(described_class.validate('my branch')).to be false }
it { expect(described_class.validate("\xA0\u0000\xB0")).to be false }
end
context '.validate_merge_request_branch' do
it { expect(described_class.validate_merge_request_branch('HEAD')).to be_truthy }
it { expect(described_class.validate_merge_request_branch('feature/new')).to be_truthy }
it { expect(described_class.validate_merge_request_branch('implement_@all')).to be_truthy }
it { expect(described_class.validate_merge_request_branch('my_new_feature')).to be_truthy }
it { expect(described_class.validate_merge_request_branch('my-branch')).to be_truthy }
it { expect(described_class.validate_merge_request_branch('#1')).to be_truthy }
it { expect(described_class.validate_merge_request_branch('feature/refs/heads/foo')).to be_truthy }
it { expect(described_class.validate_merge_request_branch('feature/~new/')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('feature/^new/')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('feature/:new/')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('feature/?new/')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('feature/*new/')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('feature/[new/')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('feature/new/')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('feature/new.')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('feature\@{')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('feature\new')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('feature//new')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('feature new')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('refs/heads/master')).to be_truthy }
it { expect(described_class.validate_merge_request_branch('refs/heads/')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('refs/remotes/')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('-')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('-branch')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('+foo:bar')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('foo:bar')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('.tag')).to be_falsey }
it { expect(described_class.validate_merge_request_branch('my branch')).to be_falsey }
it { expect(described_class.validate_merge_request_branch("\xA0\u0000\xB0")).to be_falsey }
it { expect(described_class.validate_merge_request_branch('HEAD')).to be true }
it { expect(described_class.validate_merge_request_branch('feature/new')).to be true }
it { expect(described_class.validate_merge_request_branch('implement_@all')).to be true }
it { expect(described_class.validate_merge_request_branch('my_new_feature')).to be true }
it { expect(described_class.validate_merge_request_branch('my-branch')).to be true }
it { expect(described_class.validate_merge_request_branch('#1')).to be true }
it { expect(described_class.validate_merge_request_branch('feature/refs/heads/foo')).to be true }
it { expect(described_class.validate_merge_request_branch('feature/~new/')).to be false }
it { expect(described_class.validate_merge_request_branch('feature/^new/')).to be false }
it { expect(described_class.validate_merge_request_branch('feature/:new/')).to be false }
it { expect(described_class.validate_merge_request_branch('feature/?new/')).to be false }
it { expect(described_class.validate_merge_request_branch('feature/*new/')).to be false }
it { expect(described_class.validate_merge_request_branch('feature/[new/')).to be false }
it { expect(described_class.validate_merge_request_branch('feature/new/')).to be false }
it { expect(described_class.validate_merge_request_branch('feature/new.')).to be false }
it { expect(described_class.validate_merge_request_branch('feature\@{')).to be false }
it { expect(described_class.validate_merge_request_branch('feature\new')).to be false }
it { expect(described_class.validate_merge_request_branch('feature//new')).to be false }
it { expect(described_class.validate_merge_request_branch('feature new')).to be false }
it { expect(described_class.validate_merge_request_branch('refs/heads/master')).to be true }
it { expect(described_class.validate_merge_request_branch('refs/heads/')).to be false }
it { expect(described_class.validate_merge_request_branch('refs/remotes/')).to be false }
it { expect(described_class.validate_merge_request_branch('-')).to be false }
it { expect(described_class.validate_merge_request_branch('-branch')).to be false }
it { expect(described_class.validate_merge_request_branch('+foo:bar')).to be false }
it { expect(described_class.validate_merge_request_branch('foo:bar')).to be false }
it { expect(described_class.validate_merge_request_branch('.tag')).to be false }
it { expect(described_class.validate_merge_request_branch('my branch')).to be false }
it { expect(described_class.validate_merge_request_branch("\xA0\u0000\xB0")).to be false }
end
end
......@@ -145,20 +145,6 @@ describe Gitlab::ObjectHierarchy do
end
end
describe '#root' do
it 'includes only the roots' do
relation = described_class.new(Group.where(id: child2)).roots
expect(relation).to contain_exactly(parent)
end
it 'when quering parent it includes parent' do
relation = described_class.new(Group.where(id: parent)).roots
expect(relation).to contain_exactly(parent)
end
end
describe '#all_objects' do
let(:relation) do
described_class.new(Group.where(id: child1.id)).all_objects
......
......@@ -272,6 +272,7 @@ describe Gitlab::SearchResults do
milestone_1 = create(:milestone, project: private_project_1, title: 'Private project with access milestone', state: 'closed')
milestone_2 = create(:milestone, project: internal_project, title: 'Internal project milestone')
milestone_3 = create(:milestone, project: public_project_1, title: 'Public project with milestones enabled milestone')
# Global search scope takes user authorized projects, internal projects and public projects.
limit_projects = ProjectsFinder.new(current_user: user).execute
milestones = described_class.new(user, limit_projects, 'milestone').objects('milestones')
......
......@@ -532,14 +532,8 @@ describe API::Pipelines do
expect(json_response['message']).to eq '404 Not found'
end
context 'when audit events is enabled' do
before do
stub_licensed_features(extended_audit_events: true, admin_audit_log: true)
end
it 'does not log an audit event' do
expect { delete api("/projects/#{project.id}/pipelines/#{pipeline.id}", owner) }.not_to change { SecurityEvent.count }
end
it 'does not log an audit event' do
expect { delete api("/projects/#{project.id}/pipelines/#{pipeline.id}", owner) }.not_to change { SecurityEvent.count }
end
context 'when the pipeline has jobs' 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