Commit 92da471b authored by James Lopez's avatar James Lopez

Merge branch 'ee-project-controller-spec-optimization' into 'master'

Dry up some FactoryBot usage with let_it_be in the EE ProjectsController spec

See merge request gitlab-org/gitlab!46162
parents d4e08b04 f050000d
...@@ -3,17 +3,19 @@ ...@@ -3,17 +3,19 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ProjectsController do RSpec.describe ProjectsController do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) }
let_it_be(:public_project) { create(:project, :public, :repository) }
before do before do
project.add_maintainer(user) project.add_maintainer(user)
sign_in(user) sign_in(user)
end end
describe "GET show" do describe 'GET show' do
let(:public_project) { create(:project, :public, :repository) }
render_views render_views
subject { get :show, params: { namespace_id: public_project.namespace.path, id: public_project.path } } subject { get :show, params: { namespace_id: public_project.namespace.path, id: public_project.path } }
...@@ -102,7 +104,6 @@ RSpec.describe ProjectsController do ...@@ -102,7 +104,6 @@ RSpec.describe ProjectsController do
end end
context 'custom project templates' do context 'custom project templates' do
let(:group) { create(:group) }
let(:project_template) { create(:project, :repository, :public, :metrics_dashboard_enabled, namespace: group) } let(:project_template) { create(:project, :repository, :public, :metrics_dashboard_enabled, namespace: group) }
let(:templates_params) do let(:templates_params) do
{ {
...@@ -446,7 +447,6 @@ RSpec.describe ProjectsController do ...@@ -446,7 +447,6 @@ RSpec.describe ProjectsController do
end end
context 'Archive & Unarchive actions' do context 'Archive & Unarchive actions' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) } let(:project) { create(:project, group: group) }
let(:archived_project) { create(:project, :archived, group: group) } let(:archived_project) { create(:project, :archived, group: group) }
...@@ -502,14 +502,12 @@ RSpec.describe ProjectsController do ...@@ -502,14 +502,12 @@ RSpec.describe ProjectsController do
end end
describe 'DELETE #destroy' do describe 'DELETE #destroy' do
let(:owner) { create(:user) } let(:project) { create(:project, group: group) }
let(:group) { create(:group) }
let(:project) { create(:project, group: group)}
before do before do
group.add_user(owner, Gitlab::Access::OWNER) group.add_user(user, Gitlab::Access::OWNER)
controller.instance_variable_set(:@project, project) controller.instance_variable_set(:@project, project)
sign_in(owner) sign_in(user)
end end
shared_examples 'deletes project right away' do shared_examples 'deletes project right away' do
...@@ -578,7 +576,7 @@ RSpec.describe ProjectsController do ...@@ -578,7 +576,7 @@ RSpec.describe ProjectsController do
end end
context 'for projects in user namespace' do context 'for projects in user namespace' do
let(:project) { create(:project, namespace: owner.namespace)} let(:project) { create(:project, namespace: user.namespace) }
it_behaves_like 'deletes project right away' it_behaves_like 'deletes project right away'
end end
...@@ -594,12 +592,11 @@ RSpec.describe ProjectsController do ...@@ -594,12 +592,11 @@ RSpec.describe ProjectsController do
end end
describe 'POST #restore' do describe 'POST #restore' do
let(:owner) { create(:user) } let(:project) { create(:project, namespace: user.namespace) }
let(:project) { create(:project, namespace: owner.namespace)}
before do before do
controller.instance_variable_set(:@project, project) controller.instance_variable_set(:@project, project)
sign_in(owner) sign_in(user)
end end
it 'restores project deletion' do it 'restores project deletion' 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