Commit 36cc3b92 authored by Robert Speicher's avatar Robert Speicher

Convert most User model specs to use `:empty_project`

parent caac3727
......@@ -49,7 +49,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
......@@ -400,13 +400,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) }
......@@ -449,7 +451,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 }
......@@ -531,7 +533,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) }
......@@ -970,8 +972,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
......@@ -997,7 +999,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)
......@@ -1058,9 +1060,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) }
......@@ -1102,8 +1104,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
......@@ -1177,7 +1179,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
......@@ -1185,7 +1187,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]
......@@ -1194,7 +1196,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)
......@@ -1204,7 +1206,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)
......@@ -1216,7 +1218,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)
......@@ -1228,7 +1230,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)
......@@ -1239,7 +1241,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)
......@@ -1254,14 +1256,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)
......@@ -1270,10 +1267,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)
......@@ -1281,15 +1276,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)
......@@ -1305,7 +1299,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
......@@ -1314,7 +1308,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)
......@@ -1345,7 +1339,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)
......@@ -1355,7 +1349,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]
......@@ -1385,8 +1379,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