Commit 491f1375 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'rs-empty_project' into 'master'

Use `:empty_project` in Project, User, MergeRequest, and MoveToProjectFinder specs

See merge request !8648
parents 34ef6ce3 a3d8c0b2
......@@ -2,13 +2,13 @@ require 'spec_helper'
describe MoveToProjectFinder do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
let(:no_access_project) { create(:project) }
let(:guest_project) { create(:project) }
let(:reporter_project) { create(:project) }
let(:developer_project) { create(:project) }
let(:master_project) { create(:project) }
let(:no_access_project) { create(:empty_project) }
let(:guest_project) { create(:empty_project) }
let(:reporter_project) { create(:empty_project) }
let(:developer_project) { create(:empty_project) }
let(:master_project) { create(:empty_project) }
subject { described_class.new(user) }
......@@ -37,7 +37,7 @@ describe MoveToProjectFinder do
it 'does not return archived projects' do
reporter_project.team << [user, :reporter]
reporter_project.update_attributes(archived: true)
other_reporter_project = create(:project)
other_reporter_project = create(:empty_project)
other_reporter_project.team << [user, :reporter]
expect(subject.execute(project).to_a).to eq([other_reporter_project])
......@@ -46,7 +46,7 @@ describe MoveToProjectFinder do
it 'does not return projects for which issues are disabled' do
reporter_project.team << [user, :reporter]
reporter_project.update_attributes(issues_enabled: false)
other_reporter_project = create(:project)
other_reporter_project = create(:empty_project)
other_reporter_project.team << [user, :reporter]
expect(subject.execute(project).to_a).to eq([other_reporter_project])
......@@ -83,10 +83,10 @@ describe MoveToProjectFinder do
end
it 'returns projects matching a search query' do
foo_project = create(:project)
foo_project = create(:empty_project)
foo_project.team << [user, :master]
wadus_project = create(:project, name: 'wadus')
wadus_project = create(:empty_project, name: 'wadus')
wadus_project.team << [user, :master]
expect(subject.execute(project).to_a).to eq([wadus_project, foo_project])
......
......@@ -65,7 +65,7 @@ describe MergeRequest, models: true do
end
describe '#target_branch_sha' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
subject { create(:merge_request, source_project: project, target_project: project) }
......@@ -150,7 +150,7 @@ describe MergeRequest, models: true do
end
it 'supports a cross-project reference' do
another_project = build(:project, name: 'another-project', namespace: project.namespace)
another_project = build(:empty_project, name: 'another-project', namespace: project.namespace)
expect(merge_request.to_reference(another_project)).to eq "sample-project!1"
end
......@@ -245,8 +245,8 @@ describe MergeRequest, models: true do
describe '#for_fork?' do
it 'returns true if the merge request is for a fork' do
subject.source_project = create(:project, namespace: create(:group))
subject.target_project = create(:project, namespace: create(:group))
subject.source_project = build_stubbed(:empty_project, namespace: create(:group))
subject.target_project = build_stubbed(:empty_project, namespace: create(:group))
expect(subject.for_fork?).to be_truthy
end
......@@ -501,8 +501,8 @@ describe MergeRequest, models: true do
end
describe '#diverged_commits_count' do
let(:project) { create(:project) }
let(:fork_project) { create(:project, forked_from_project: project) }
let(:project) { create(:project, :repository) }
let(:fork_project) { create(:project, :repository, forked_from_project: project) }
context 'when the target branch does not exist anymore' do
subject { create(:merge_request, source_project: project, target_project: project) }
......@@ -727,7 +727,7 @@ describe MergeRequest, models: true do
end
describe '#participants' do
let(:project) { create(:project, :public) }
let(:project) { create(:empty_project, :public) }
let(:mr) do
create(:merge_request, source_project: project, target_project: project)
......@@ -768,7 +768,7 @@ describe MergeRequest, models: true do
end
describe '#check_if_can_be_merged' do
let(:project) { create(:project, only_allow_merge_if_build_succeeds: true) }
let(:project) { create(:empty_project, only_allow_merge_if_build_succeeds: true) }
subject { create(:merge_request, source_project: project, merge_status: :unchecked) }
......@@ -789,7 +789,7 @@ describe MergeRequest, models: true do
it 'becomes unmergeable' do
expect { subject.check_if_can_be_merged }.to change { subject.merge_status }.to('cannot_be_merged')
end
it 'creates Todo on unmergeability' do
expect_any_instance_of(TodoService).to receive(:merge_request_became_unmergeable).with(subject)
......@@ -810,7 +810,7 @@ describe MergeRequest, models: true do
end
describe '#mergeable?' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
subject { create(:merge_request, source_project: project) }
......@@ -830,7 +830,7 @@ describe MergeRequest, models: true do
end
describe '#mergeable_state?' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
subject { create(:merge_request, source_project: project) }
......@@ -957,7 +957,7 @@ describe MergeRequest, models: true do
let(:merge_request) { create(:merge_request_with_diff_notes, source_project: project) }
context 'when project.only_allow_merge_if_all_discussions_are_resolved == true' do
let(:project) { create(:project, only_allow_merge_if_all_discussions_are_resolved: true) }
let(:project) { create(:project, :repository, only_allow_merge_if_all_discussions_are_resolved: true) }
context 'with all discussions resolved' do
before do
......@@ -991,7 +991,7 @@ describe MergeRequest, models: true do
end
context 'when project.only_allow_merge_if_all_discussions_are_resolved == false' do
let(:project) { create(:project, only_allow_merge_if_all_discussions_are_resolved: false) }
let(:project) { create(:project, :repository, only_allow_merge_if_all_discussions_are_resolved: false) }
context 'with unresolved discussions' do
before do
......@@ -1006,7 +1006,7 @@ describe MergeRequest, models: true do
end
describe "#environments" do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
let(:merge_request) { create(:merge_request, source_project: project) }
context 'with multiple environments' do
......@@ -1024,7 +1024,7 @@ describe MergeRequest, models: true do
context 'with environments on source project' do
let(:source_project) do
create(:project) do |fork_project|
create(:project, :repository) do |fork_project|
fork_project.create_forked_project_link(forked_to_project_id: fork_project.id, forked_from_project_id: project.id)
end
end
......@@ -1401,8 +1401,8 @@ describe MergeRequest, models: true do
end
describe "#source_project_missing?" do
let(:project) { create(:project) }
let(:fork_project) { create(:project, forked_from_project: project) }
let(:project) { create(:empty_project) }
let(:fork_project) { create(:empty_project, forked_from_project: project) }
let(:user) { create(:user) }
let(:unlink_project) { Projects::UnlinkForkService.new(fork_project, user) }
......@@ -1439,8 +1439,8 @@ describe MergeRequest, models: true do
end
describe "#closed_without_fork?" do
let(:project) { create(:project) }
let(:fork_project) { create(:project, forked_from_project: project) }
let(:project) { create(:empty_project) }
let(:fork_project) { create(:empty_project, forked_from_project: project) }
let(:user) { create(:user) }
let(:unlink_project) { Projects::UnlinkForkService.new(fork_project, user) }
......@@ -1485,9 +1485,9 @@ describe MergeRequest, models: true do
end
context 'forked project' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
let(:fork_project) { create(:project, forked_from_project: project, namespace: user.namespace) }
let(:fork_project) { create(:empty_project, forked_from_project: project, namespace: user.namespace) }
let!(:merge_request) do
create(:closed_merge_request,
......@@ -1531,7 +1531,7 @@ describe MergeRequest, models: true do
status: status)
end
let(:project) { create(:project, :public, only_allow_merge_if_build_succeeds: true) }
let(:project) { create(:project, :public, :repository, only_allow_merge_if_build_succeeds: true) }
let(:developer) { create(:user) }
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request, source_project: project) }
......
......@@ -73,9 +73,7 @@ describe Project, models: true do
context 'after initialized' do
it "has a project_feature" do
project = FactoryGirl.build(:project)
expect(project.project_feature.present?).to be_present
expect(Project.new.project_feature).to be_present
end
end
......@@ -129,7 +127,7 @@ describe Project, models: true do
end
describe 'validation' do
let!(:project) { create(:project) }
let!(:project) { create(:empty_project) }
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:namespace_id) }
......@@ -148,7 +146,7 @@ describe Project, models: true do
it { is_expected.to validate_presence_of(:repository_storage) }
it 'does not allow new projects beyond user limits' do
project2 = build(:project)
project2 = build(:empty_project)
allow(project2).to receive(:creator).and_return(double(can_create_project?: false, projects_limit: 0).as_null_object)
expect(project2).not_to be_valid
expect(project2.errors[:limit_reached].first).to match(/Personal project creation is not allowed/)
......@@ -157,7 +155,7 @@ describe Project, models: true do
describe 'wiki path conflict' do
context "when the new path has been used by the wiki of other Project" do
it 'has an error on the name attribute' do
new_project = build_stubbed(:project, namespace_id: project.namespace_id, path: "#{project.path}.wiki")
new_project = build_stubbed(:empty_project, namespace_id: project.namespace_id, path: "#{project.path}.wiki")
expect(new_project).not_to be_valid
expect(new_project.errors[:name].first).to eq('has already been taken')
......@@ -166,8 +164,8 @@ describe Project, models: true do
context "when the new wiki path has been used by the path of other Project" do
it 'has an error on the name attribute' do
project_with_wiki_suffix = create(:project, path: 'foo.wiki')
new_project = build_stubbed(:project, namespace_id: project_with_wiki_suffix.namespace_id, path: 'foo')
project_with_wiki_suffix = create(:empty_project, path: 'foo.wiki')
new_project = build_stubbed(:empty_project, namespace_id: project_with_wiki_suffix.namespace_id, path: 'foo')
expect(new_project).not_to be_valid
expect(new_project.errors[:name].first).to eq('has already been taken')
......@@ -176,7 +174,7 @@ describe Project, models: true do
end
context 'repository storages inclussion' do
let(:project2) { build(:project, repository_storage: 'missing') }
let(:project2) { build(:empty_project, repository_storage: 'missing') }
before do
storages = { 'custom' => 'tmp/tests/custom_repositories' }
......@@ -352,7 +350,7 @@ describe Project, models: true do
end
describe '#repository_storage_path' do
let(:project) { create(:project, repository_storage: 'custom') }
let(:project) { create(:empty_project, repository_storage: 'custom') }
before do
FileUtils.mkdir('tmp/tests/custom_repositories')
......@@ -412,7 +410,7 @@ describe Project, models: true do
describe 'last_activity methods' do
let(:timestamp) { 2.hours.ago }
# last_activity_at gets set to created_at upon creation
let(:project) { create(:project, created_at: timestamp, updated_at: timestamp) }
let(:project) { create(:empty_project, created_at: timestamp, updated_at: timestamp) }
describe 'last_activity' do
it 'alias last_activity to last_event' do
......@@ -496,7 +494,7 @@ describe Project, models: true do
context 'with namespace' do
before do
@group = create :group, name: 'gitlab'
@project = create(:project, name: 'gitlabhq', namespace: @group)
@project = create(:empty_project, name: 'gitlabhq', namespace: @group)
end
it { expect(@project.to_param).to eq('gitlabhq') }
......@@ -522,7 +520,7 @@ describe Project, models: true do
end
describe '#repository' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
it 'returns valid repo' do
expect(project.repository).to be_kind_of(Repository)
......@@ -530,20 +528,22 @@ describe Project, models: true do
end
describe '#default_issues_tracker?' do
let(:project) { create(:project) }
let(:ext_project) { create(:redmine_project) }
it "is true if used internal tracker" do
project = build(:empty_project)
expect(project.default_issues_tracker?).to be_truthy
end
it "is false if used other tracker" do
expect(ext_project.default_issues_tracker?).to be_falsey
# NOTE: The current nature of this factory requires persistence
project = create(:redmine_project)
expect(project.default_issues_tracker?).to be_falsey
end
end
describe '#external_issue_tracker' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
let(:ext_project) { create(:redmine_project) }
context 'on existing projects with no value for has_external_issue_tracker' do
......@@ -578,7 +578,7 @@ describe Project, models: true do
end
describe '#cache_has_external_issue_tracker' do
let(:project) { create(:project, has_external_issue_tracker: nil) }
let(:project) { create(:empty_project, has_external_issue_tracker: nil) }
it 'stores true if there is any external_issue_tracker' do
services = double(:service, external_issue_trackers: [RedmineService.new])
......@@ -600,9 +600,9 @@ describe Project, models: true do
end
describe '#has_wiki?' do
let(:no_wiki_project) { create(:project, wiki_access_level: ProjectFeature::DISABLED, has_external_wiki: false) }
let(:wiki_enabled_project) { create(:project) }
let(:external_wiki_project) { create(:project, has_external_wiki: true) }
let(:no_wiki_project) { create(:empty_project, wiki_access_level: ProjectFeature::DISABLED, has_external_wiki: false) }
let(:wiki_enabled_project) { create(:empty_project) }
let(:external_wiki_project) { create(:empty_project, has_external_wiki: true) }
it 'returns true if project is wiki enabled or has external wiki' do
expect(wiki_enabled_project).to have_wiki
......@@ -612,7 +612,7 @@ describe Project, models: true do
end
describe '#external_wiki' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
context 'with an active external wiki' do
before do
......@@ -663,7 +663,7 @@ describe Project, models: true do
end
describe '#open_branches' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
before do
project.protected_branches.create(name: 'master')
......@@ -685,7 +685,7 @@ describe Project, models: true do
it 'counts stars from multiple users' do
user1 = create :user
user2 = create :user
project = create :project, :public
project = create(:empty_project, :public)
expect(project.star_count).to eq(0)
......@@ -707,8 +707,8 @@ describe Project, models: true do
it 'counts stars on the right project' do
user = create :user
project1 = create :project, :public
project2 = create :project, :public
project1 = create(:empty_project, :public)
project2 = create(:empty_project, :public)
expect(project1.star_count).to eq(0)
expect(project2.star_count).to eq(0)
......@@ -740,7 +740,7 @@ describe Project, models: true do
end
describe '#avatar_type' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
it 'is true if avatar is image' do
project.update_attribute(:avatar, 'uploads/avatar.png')
......@@ -756,7 +756,7 @@ describe Project, models: true do
describe '#avatar_url' do
subject { project.avatar_url }
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
context 'When avatar file is uploaded' do
before do
......@@ -791,7 +791,7 @@ describe Project, models: true do
end
describe '#pipeline_for' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
let!(:pipeline) { create_pipeline }
shared_examples 'giving the correct pipeline' do
......@@ -825,7 +825,7 @@ describe Project, models: true do
end
describe '#builds_enabled' do
let(:project) { create :project }
let(:project) { create(:empty_project) }
subject { project.builds_enabled }
......@@ -877,7 +877,7 @@ describe Project, models: true do
end
describe '.visible_to_user' do
let!(:project) { create(:project, :private) }
let!(:project) { create(:empty_project, :private) }
let!(:user) { create(:user) }
subject { described_class.visible_to_user(user) }
......@@ -975,7 +975,7 @@ describe Project, models: true do
end
describe '#visibility_level_allowed?' do
let(:project) { create(:project, :internal) }
let(:project) { create(:empty_project, :internal) }
context 'when checking on non-forked project' do
it { expect(project.visibility_level_allowed?(Gitlab::VisibilityLevel::PRIVATE)).to be_truthy }
......@@ -984,8 +984,8 @@ describe Project, models: true do
end
context 'when checking on forked project' do
let(:project) { create(:project, :internal) }
let(:forked_project) { create(:project, forked_from_project: project) }
let(:project) { create(:empty_project, :internal) }
let(:forked_project) { create(:empty_project, forked_from_project: project) }
it { expect(forked_project.visibility_level_allowed?(Gitlab::VisibilityLevel::PRIVATE)).to be_truthy }
it { expect(forked_project.visibility_level_allowed?(Gitlab::VisibilityLevel::INTERNAL)).to be_truthy }
......@@ -994,7 +994,7 @@ describe Project, models: true do
end
describe '.search' do
let(:project) { create(:project, description: 'kitten mittens') }
let(:project) { create(:empty_project, description: 'kitten mittens') }
it 'returns projects with a matching name' do
expect(described_class.search(project.name)).to eq([project])
......@@ -1052,7 +1052,7 @@ describe Project, models: true do
end
describe '#rename_repo' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
let(:gitlab_shell) { Gitlab::Shell.new }
before do
......@@ -1102,7 +1102,7 @@ describe Project, models: true do
end
describe '#expire_caches_before_rename' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
let(:repo) { double(:repo, exists?: true) }
let(:wiki) { double(:wiki, exists?: true) }
......@@ -1123,7 +1123,7 @@ describe Project, models: true do
end
describe '.search_by_title' do
let(:project) { create(:project, name: 'kittens') }
let(:project) { create(:empty_project, name: 'kittens') }
it 'returns projects with a matching name' do
expect(described_class.search_by_title(project.name)).to eq([project])
......@@ -1142,8 +1142,8 @@ describe Project, models: true do
let(:private_group) { create(:group, visibility_level: 0) }
let(:internal_group) { create(:group, visibility_level: 10) }
let(:private_project) { create :project, :private, group: private_group }
let(:internal_project) { create :project, :internal, group: internal_group }
let(:private_project) { create :empty_project, :private, group: private_group }
let(:internal_project) { create :empty_project, :internal, group: internal_group }
context 'when group is private project can not be internal' do
it { expect(private_project.visibility_level_allowed?(Gitlab::VisibilityLevel::INTERNAL)).to be_falsey }
......@@ -1155,7 +1155,7 @@ describe Project, models: true do
end
describe '#create_repository' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
let(:shell) { Gitlab::Shell.new }
before do
......@@ -1197,7 +1197,7 @@ describe Project, models: true do
describe '#protected_branch?' do
context 'existing project' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
it 'returns true when the branch matches a protected branch via direct match' do
create(:protected_branch, project: project, name: "foo")
......@@ -1381,7 +1381,7 @@ describe Project, models: true do
name: name)
end
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
let(:pipeline) { create_pipeline }
context 'with many builds' do
......@@ -1461,7 +1461,7 @@ describe Project, models: true do
end
context 'not forked' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
it 'schedules a RepositoryImportWorker job' do
expect(RepositoryImportWorker).to receive(:perform_async).with(project.id)
......@@ -1472,19 +1472,19 @@ describe Project, models: true do
end
describe '#gitlab_project_import?' do
subject(:project) { build(:project, import_type: 'gitlab_project') }
subject(:project) { build(:empty_project, import_type: 'gitlab_project') }
it { expect(project.gitlab_project_import?).to be true }
end
describe '#gitea_import?' do
subject(:project) { build(:project, import_type: 'gitea') }
subject(:project) { build(:empty_project, import_type: 'gitea') }
it { expect(project.gitea_import?).to be true }
end
describe '#lfs_enabled?' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
shared_examples 'project overrides group' do
it 'returns true when enabled in project' do
......@@ -1546,7 +1546,7 @@ describe Project, models: true do
end
describe '#change_head' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
it 'calls the before_change_head and after_change_head methods' do
expect(project.repository).to receive(:before_change_head)
......@@ -1574,7 +1574,7 @@ describe Project, models: true do
end
describe '#pushes_since_gc' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
after do
project.reset_pushes_since_gc
......@@ -1596,7 +1596,7 @@ describe Project, models: true do
end
describe '#increment_pushes_since_gc' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
after do
project.reset_pushes_since_gc
......@@ -1610,7 +1610,7 @@ describe Project, models: true do
end
describe '#reset_pushes_since_gc' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
after do
project.reset_pushes_since_gc
......@@ -1626,7 +1626,7 @@ describe Project, models: true do
end
describe '#environments_for' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
let(:environment) { create(:environment, project: project) }
context 'tagged deployment' do
......@@ -1678,7 +1678,7 @@ describe Project, models: true do
end
describe '#environments_recently_updated_on_branch' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
let(:environment) { create(:environment, project: project) }
context 'when last deployment to environment is the most recent one' do
......
......@@ -48,7 +48,7 @@ describe User, models: true do
describe '#project_members' do
it 'does not include project memberships for which user is a requester' do
user = create(:user)
project = create(:project, :public, :access_requestable)
project = create(:empty_project, :public, :access_requestable)
project.request_access(user)
expect(user.project_members).to be_empty
......@@ -386,13 +386,15 @@ describe User, models: true do
describe 'projects' do
before do
@user = create :user
@project = create :project, namespace: @user.namespace
@project_2 = create :project, group: create(:group) # Grant MASTER access to the user
@project_3 = create :project, group: create(:group) # Grant DEVELOPER access to the user
@user = create(:user)
@project_2.team << [@user, :master]
@project_3.team << [@user, :developer]
@project = create(:empty_project, namespace: @user.namespace)
@project_2 = create(:empty_project, group: create(:group)) do |project|
project.add_master(@user)
end
@project_3 = create(:empty_project, group: create(:group)) do |project|
project.add_developer(@user)
end
end
it { expect(@user.authorized_projects).to include(@project) }
......@@ -435,7 +437,7 @@ describe User, models: true do
describe 'namespaced' do
before do
@user = create :user
@project = create :project, namespace: @user.namespace
@project = create(:empty_project, namespace: @user.namespace)
end
it { expect(@user.several_namespaces?).to be_falsey }
......@@ -517,7 +519,7 @@ describe User, models: true do
before do
User.delete_all
@user = create :user
@project = create :project
@project = create(:empty_project)
end
it { expect(User.not_in_project(@project)).to include(@user, @project.owner) }
......@@ -927,8 +929,8 @@ describe User, models: true do
describe "#starred?" do
it "determines if user starred a project" do
user = create :user
project1 = create :project, :public
project2 = create :project, :public
project1 = create(:empty_project, :public)
project2 = create(:empty_project, :public)
expect(user.starred?(project1)).to be_falsey
expect(user.starred?(project2)).to be_falsey
......@@ -954,7 +956,7 @@ describe User, models: true do
describe "#toggle_star" do
it "toggles stars" do
user = create :user
project = create :project, :public
project = create(:empty_project, :public)
expect(user.starred?(project)).to be_falsey
user.toggle_star(project)
......@@ -994,9 +996,9 @@ describe User, models: true do
describe "#contributed_projects" do
subject { create(:user) }
let!(:project1) { create(:project) }
let!(:project2) { create(:project, forked_from_project: project3) }
let!(:project3) { create(:project) }
let!(:project1) { create(:empty_project) }
let!(:project2) { create(:empty_project, forked_from_project: project3) }
let!(:project3) { create(:empty_project) }
let!(:merge_request) { create(:merge_request, source_project: project2, target_project: project3, author: subject) }
let!(:push_event) { create(:event, action: Event::PUSHED, project: project1, target: project1, author: subject) }
let!(:merge_event) { create(:event, action: Event::CREATED, project: project3, target: merge_request, author: subject) }
......@@ -1038,8 +1040,8 @@ describe User, models: true do
describe "#recent_push" do
subject { create(:user) }
let!(:project1) { create(:project) }
let!(:project2) { create(:project, forked_from_project: project1) }
let!(:project1) { create(:project, :repository) }
let!(:project2) { create(:project, :repository, forked_from_project: project1) }
let!(:push_data) do
Gitlab::DataBuilder::Push.build_sample(project2, subject)
end
......@@ -1113,7 +1115,7 @@ describe User, models: true do
it "includes user's personal projects" do
user = create(:user)
project = create(:project, :private, namespace: user.namespace)
project = create(:empty_project, :private, namespace: user.namespace)
expect(user.authorized_projects).to include(project)
end
......@@ -1121,7 +1123,7 @@ describe User, models: true do
it "includes personal projects user has been given access to" do
user1 = create(:user)
user2 = create(:user)
project = create(:project, :private, namespace: user1.namespace)
project = create(:empty_project, :private, namespace: user1.namespace)
project.team << [user2, Gitlab::Access::DEVELOPER]
......@@ -1130,7 +1132,7 @@ describe User, models: true do
it "includes projects of groups user has been added to" do
group = create(:group)
project = create(:project, group: group)
project = create(:empty_project, group: group)
user = create(:user)
group.add_developer(user)
......@@ -1140,7 +1142,7 @@ describe User, models: true do
it "does not include projects of groups user has been removed from" do
group = create(:group)
project = create(:project, group: group)
project = create(:empty_project, group: group)
user = create(:user)
member = group.add_developer(user)
......@@ -1152,7 +1154,7 @@ describe User, models: true do
it "includes projects shared with user's group" do
user = create(:user)
project = create(:project, :private)
project = create(:empty_project, :private)
group = create(:group)
group.add_reporter(user)
......@@ -1164,7 +1166,7 @@ describe User, models: true do
it "does not include destroyed projects user had access to" do
user1 = create(:user)
user2 = create(:user)
project = create(:project, :private, namespace: user1.namespace)
project = create(:empty_project, :private, namespace: user1.namespace)
project.team << [user2, Gitlab::Access::DEVELOPER]
expect(user2.authorized_projects).to include(project)
......@@ -1175,7 +1177,7 @@ describe User, models: true do
it "does not include projects of destroyed groups user had access to" do
group = create(:group)
project = create(:project, namespace: group)
project = create(:empty_project, namespace: group)
user = create(:user)
group.add_developer(user)
......@@ -1190,14 +1192,9 @@ describe User, models: true do
let(:user) { create(:user) }
it 'includes projects for which the user access level is above or equal to reporter' do
create(:project)
reporter_project = create(:project)
developer_project = create(:project)
master_project = create(:project)
reporter_project.team << [user, :reporter]
developer_project.team << [user, :developer]
master_project.team << [user, :master]
reporter_project = create(:empty_project) { |p| p.add_reporter(user) }
developer_project = create(:empty_project) { |p| p.add_developer(user) }
master_project = create(:empty_project) { |p| p.add_master(user) }
expect(user.projects_where_can_admin_issues.to_a).to eq([master_project, developer_project, reporter_project])
expect(user.can?(:admin_issue, master_project)).to eq(true)
......@@ -1206,10 +1203,8 @@ describe User, models: true do
end
it 'does not include for which the user access level is below reporter' do
project = create(:project)
guest_project = create(:project)
guest_project.team << [user, :guest]
project = create(:empty_project)
guest_project = create(:empty_project) { |p| p.add_guest(user) }
expect(user.projects_where_can_admin_issues.to_a).to be_empty
expect(user.can?(:admin_issue, guest_project)).to eq(false)
......@@ -1217,15 +1212,14 @@ describe User, models: true do
end
it 'does not include archived projects' do
project = create(:project)
project.update_attributes(archived: true)
project = create(:empty_project, :archived)
expect(user.projects_where_can_admin_issues.to_a).to be_empty
expect(user.can?(:admin_issue, project)).to eq(false)
end
it 'does not include projects for which issues are disabled' do
project = create(:project, issues_access_level: ProjectFeature::DISABLED)
project = create(:empty_project, issues_access_level: ProjectFeature::DISABLED)
expect(user.projects_where_can_admin_issues.to_a).to be_empty
expect(user.can?(:admin_issue, project)).to eq(false)
......@@ -1241,7 +1235,7 @@ describe User, models: true do
end
context 'without any projects' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
it 'does not load' do
expect(user.ci_authorized_runners).to be_empty
......@@ -1250,7 +1244,7 @@ describe User, models: true do
context 'with personal projects runners' do
let(:namespace) { create(:namespace, owner: user) }
let(:project) { create(:project, namespace: namespace) }
let(:project) { create(:empty_project, namespace: namespace) }
it 'loads' do
expect(user.ci_authorized_runners).to contain_exactly(runner)
......@@ -1281,7 +1275,7 @@ describe User, models: true do
context 'with groups projects runners' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
let(:project) { create(:empty_project, group: group) }
def add_user(access)
group.add_user(user, access)
......@@ -1291,7 +1285,7 @@ describe User, models: true do
end
context 'with other projects runners' do
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
def add_user(access)
project.team << [user, access]
......@@ -1321,8 +1315,8 @@ describe User, models: true do
end
describe '#projects_with_reporter_access_limited_to' do
let(:project1) { create(:project) }
let(:project2) { create(:project) }
let(:project1) { create(:empty_project) }
let(:project2) { create(:empty_project) }
let(:user) { create(:user) }
before 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