Commit e6b3a055 authored by Igor Drozdov's avatar Igor Drozdov

Speed up spec/controllers/groups_controller_spec.rb

parent 334e139d
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe GroupsController do RSpec.describe GroupsController, factory_default: :keep do
include ExternalAuthorizationServiceHelpers include ExternalAuthorizationServiceHelpers
let(:user) { create(:user) } let_it_be_with_refind(:group) { create_default(:group, :public) }
let(:admin) { create(:admin) } let_it_be_with_refind(:project) { create(:project, namespace: group) }
let(:group) { create(:group, :public) } let_it_be(:user) { create(:user) }
let(:project) { create(:project, namespace: group) } let_it_be(:admin) { create(:admin) }
let!(:group_member) { create(:group_member, group: group, user: user) } let_it_be(:group_member) { create(:group_member, group: group, user: user) }
let!(:owner) { group.add_owner(create(:user)).user } let_it_be(:owner) { group.add_owner(create(:user)).user }
let!(:maintainer) { group.add_maintainer(create(:user)).user } let_it_be(:maintainer) { group.add_maintainer(create(:user)).user }
let!(:developer) { group.add_developer(create(:user)).user } let_it_be(:developer) { group.add_developer(create(:user)).user }
let!(:guest) { group.add_guest(create(:user)).user } let_it_be(:guest) { group.add_guest(create(:user)).user }
shared_examples 'member with ability to create subgroups' do shared_examples 'member with ability to create subgroups' do
it 'renders the new page' do it 'renders the new page' do
...@@ -57,7 +57,6 @@ RSpec.describe GroupsController do ...@@ -57,7 +57,6 @@ RSpec.describe GroupsController do
describe 'GET #show' do describe 'GET #show' do
before do before do
sign_in(user) sign_in(user)
project
end end
let(:format) { :html } let(:format) { :html }
...@@ -82,7 +81,6 @@ RSpec.describe GroupsController do ...@@ -82,7 +81,6 @@ RSpec.describe GroupsController do
describe 'GET #details' do describe 'GET #details' do
before do before do
sign_in(user) sign_in(user)
project
end end
let(:format) { :html } let(:format) { :html }
...@@ -131,12 +129,9 @@ RSpec.describe GroupsController do ...@@ -131,12 +129,9 @@ RSpec.describe GroupsController do
end end
describe 'GET #activity' do describe 'GET #activity' do
render_views
context 'as json' do context 'as json' do
before do before do
sign_in(user) sign_in(user)
project
end end
it 'includes events from all projects in group and subgroups', :sidekiq_might_not_need_inline do it 'includes events from all projects in group and subgroups', :sidekiq_might_not_need_inline do
...@@ -157,10 +152,6 @@ RSpec.describe GroupsController do ...@@ -157,10 +152,6 @@ RSpec.describe GroupsController do
end end
context 'when user has no permission to see the event' do context 'when user has no permission to see the event' do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
let(:project_with_restricted_access) do let(:project_with_restricted_access) do
create(:project, :public, issues_access_level: ProjectFeature::PRIVATE, group: group) create(:project, :public, issues_access_level: ProjectFeature::PRIVATE, group: group)
end end
...@@ -552,8 +543,6 @@ RSpec.describe GroupsController do ...@@ -552,8 +543,6 @@ RSpec.describe GroupsController do
end end
context 'when there is a conflicting group path' do context 'when there is a conflicting group path' do
render_views
let!(:conflict_group) { create(:group, path: SecureRandom.hex(12) ) } let!(:conflict_group) { create(:group, path: SecureRandom.hex(12) ) }
let!(:old_name) { group.name } let!(:old_name) { group.name }
...@@ -794,6 +783,7 @@ RSpec.describe GroupsController do ...@@ -794,6 +783,7 @@ RSpec.describe GroupsController do
context 'when transferring to a subgroup goes right' do context 'when transferring to a subgroup goes right' do
let(:new_parent_group) { create(:group, :public) } let(:new_parent_group) { create(:group, :public) }
let(:group) { create(:group, :public) }
let!(:group_member) { create(:group_member, :owner, group: group, user: user) } let!(:group_member) { create(:group_member, :owner, group: group, user: user) }
let!(:new_parent_group_member) { create(:group_member, :owner, group: new_parent_group, user: user) } let!(:new_parent_group_member) { create(:group_member, :owner, group: new_parent_group, user: user) }
...@@ -805,11 +795,8 @@ RSpec.describe GroupsController do ...@@ -805,11 +795,8 @@ RSpec.describe GroupsController do
} }
end end
it 'returns a notice' do it 'returns a notice and redirects to the new path' do
expect(flash[:notice]).to eq("Group '#{group.name}' was successfully transferred.") expect(flash[:notice]).to eq("Group '#{group.name}' was successfully transferred.")
end
it 'redirects to the new path' do
expect(response).to redirect_to("/#{new_parent_group.path}/#{group.path}") expect(response).to redirect_to("/#{new_parent_group.path}/#{group.path}")
end end
end end
...@@ -826,17 +813,15 @@ RSpec.describe GroupsController do ...@@ -826,17 +813,15 @@ RSpec.describe GroupsController do
} }
end end
it 'returns a notice' do it 'returns a notice and redirects to the new path' do
expect(flash[:notice]).to eq("Group '#{group.name}' was successfully transferred.") expect(flash[:notice]).to eq("Group '#{group.name}' was successfully transferred.")
end
it 'redirects to the new path' do
expect(response).to redirect_to("/#{group.path}") expect(response).to redirect_to("/#{group.path}")
end end
end end
context 'When the transfer goes wrong' do context 'When the transfer goes wrong' do
let(:new_parent_group) { create(:group, :public) } let(:new_parent_group) { create(:group, :public) }
let(:group) { create(:group, :public) }
let!(:group_member) { create(:group_member, :owner, group: group, user: user) } let!(:group_member) { create(:group_member, :owner, group: group, user: user) }
let!(:new_parent_group_member) { create(:group_member, :owner, group: new_parent_group, user: user) } let!(:new_parent_group_member) { create(:group_member, :owner, group: new_parent_group, user: user) }
...@@ -850,17 +835,15 @@ RSpec.describe GroupsController do ...@@ -850,17 +835,15 @@ RSpec.describe GroupsController do
} }
end end
it 'returns an alert' do it 'returns an alert and redirects to the current path' do
expect(flash[:alert]).to eq "Transfer failed: namespace directory cannot be moved" expect(flash[:alert]).to eq "Transfer failed: namespace directory cannot be moved"
end
it 'redirects to the current path' do
expect(response).to redirect_to(edit_group_path(group)) expect(response).to redirect_to(edit_group_path(group))
end end
end end
context 'when the user is not allowed to transfer the group' do context 'when the user is not allowed to transfer the group' do
let(:new_parent_group) { create(:group, :public) } let(:new_parent_group) { create(:group, :public) }
let(:group) { create(:group, :public) }
let!(:group_member) { create(:group_member, :guest, group: group, user: user) } let!(:group_member) { create(:group_member, :guest, group: group, user: user) }
let!(:new_parent_group_member) { create(:group_member, :guest, group: new_parent_group, user: user) } let!(:new_parent_group_member) { create(:group_member, :guest, group: new_parent_group, user: user) }
...@@ -879,6 +862,7 @@ RSpec.describe GroupsController do ...@@ -879,6 +862,7 @@ RSpec.describe GroupsController do
context 'transferring when a project has container images' do context 'transferring when a project has container images' do
let(:group) { create(:group, :public, :nested) } let(:group) { create(:group, :public, :nested) }
let(:project) { create(:project, namespace: group) }
let!(:group_member) { create(:group_member, :owner, group: group, user: user) } let!(:group_member) { create(:group_member, :owner, group: group, user: user) }
before do before do
...@@ -979,6 +963,8 @@ RSpec.describe GroupsController do ...@@ -979,6 +963,8 @@ RSpec.describe GroupsController do
end end
context 'when there is no file available to download' do context 'when there is no file available to download' do
let(:admin) { create(:admin) }
before do before do
sign_in(admin) sign_in(admin)
end end
...@@ -1149,9 +1135,7 @@ RSpec.describe GroupsController do ...@@ -1149,9 +1135,7 @@ RSpec.describe GroupsController do
describe "GET #activity as JSON" do describe "GET #activity as JSON" do
include DesignManagementTestHelpers include DesignManagementTestHelpers
render_views
let(:project) { create(:project, :public, group: group) }
let(:other_project) { create(:project, :public, group: group) } let(:other_project) { create(:project, :public, group: group) }
def get_activity def get_activity
......
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