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