Commit 43e1481c authored by Douwe Maan's avatar Douwe Maan

Merge branch 'rs-single-line-rspec-hook-cop' into 'master'

Add a custom RSpec/SingleLineHook cop

Closes #24891

See merge request !11911
parents 557cbba7 4daf9c00
...@@ -1064,6 +1064,13 @@ RSpec/NotToNot: ...@@ -1064,6 +1064,13 @@ RSpec/NotToNot:
RSpec/RepeatedDescription: RSpec/RepeatedDescription:
Enabled: false Enabled: false
# Ensure RSpec hook blocks are always multi-line.
RSpec/SingleLineHook:
Enabled: true
Exclude:
- 'spec/factories/*'
- 'spec/requests/api/v3/*'
# Checks for stubbed test subjects. # Checks for stubbed test subjects.
RSpec/SubjectStub: RSpec/SubjectStub:
Enabled: false Enabled: false
......
module RuboCop
module Cop
module RSpec
# This cop checks for single-line hook blocks
#
# @example
#
# # bad
# before { do_something }
# after(:each) { undo_something }
#
# # good
# before do
# do_something
# end
#
# after(:each) do
# undo_something
# end
class SingleLineHook < RuboCop::Cop::RSpec::Cop
MESSAGE = "Don't use single-line hook blocks.".freeze
def_node_search :rspec_hook?, <<~PATTERN
(send nil {:after :around :before} ...)
PATTERN
def on_block(node)
return unless rspec_hook?(node)
return unless node.single_line?
add_offense(node, :expression, MESSAGE)
end
end
end
end
end
...@@ -15,3 +15,4 @@ require_relative 'cop/migration/remove_index' ...@@ -15,3 +15,4 @@ require_relative 'cop/migration/remove_index'
require_relative 'cop/migration/reversible_add_column_with_default' require_relative 'cop/migration/reversible_add_column_with_default'
require_relative 'cop/migration/timestamps' require_relative 'cop/migration/timestamps'
require_relative 'cop/migration/update_column_in_batches' require_relative 'cop/migration/update_column_in_batches'
require_relative 'cop/rspec/single_line_hook'
...@@ -2,7 +2,10 @@ require 'spec_helper' ...@@ -2,7 +2,10 @@ require 'spec_helper'
describe Admin::IdentitiesController do describe Admin::IdentitiesController do
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
before { sign_in(admin) }
before do
sign_in(admin)
end
describe 'UPDATE identity' do describe 'UPDATE identity' do
let(:user) { create(:omniauth_user, provider: 'ldapmain', extern_uid: 'uid=myuser,ou=people,dc=example,dc=com') } let(:user) { create(:omniauth_user, provider: 'ldapmain', extern_uid: 'uid=myuser,ou=people,dc=example,dc=com') }
......
...@@ -3,7 +3,9 @@ require 'spec_helper' ...@@ -3,7 +3,9 @@ require 'spec_helper'
describe Admin::ServicesController do describe Admin::ServicesController do
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
before { sign_in(admin) } before do
sign_in(admin)
end
describe 'GET #edit' do describe 'GET #edit' do
let!(:project) { create(:empty_project) } let!(:project) { create(:empty_project) }
......
...@@ -200,7 +200,9 @@ describe AutocompleteController do ...@@ -200,7 +200,9 @@ describe AutocompleteController do
end end
context 'skip_users parameter included' do context 'skip_users parameter included' do
before { sign_in(user) } before do
sign_in(user)
end
it 'skips the user IDs passed' do it 'skips the user IDs passed' do
get(:users, skip_users: [user, user2].map(&:id)) get(:users, skip_users: [user, user2].map(&:id))
......
...@@ -16,10 +16,14 @@ describe Groups::GroupMembersController do ...@@ -16,10 +16,14 @@ describe Groups::GroupMembersController do
describe 'POST create' do describe 'POST create' do
let(:group_user) { create(:user) } let(:group_user) { create(:user) }
before { sign_in(user) } before do
sign_in(user)
end
context 'when user does not have enough rights' do context 'when user does not have enough rights' do
before { group.add_developer(user) } before do
group.add_developer(user)
end
it 'returns 403' do it 'returns 403' do
post :create, group_id: group, post :create, group_id: group,
...@@ -32,7 +36,9 @@ describe Groups::GroupMembersController do ...@@ -32,7 +36,9 @@ describe Groups::GroupMembersController do
end end
context 'when user has enough rights' do context 'when user has enough rights' do
before { group.add_owner(user) } before do
group.add_owner(user)
end
it 'adds user to members' do it 'adds user to members' do
post :create, group_id: group, post :create, group_id: group,
...@@ -59,7 +65,9 @@ describe Groups::GroupMembersController do ...@@ -59,7 +65,9 @@ describe Groups::GroupMembersController do
describe 'DELETE destroy' do describe 'DELETE destroy' do
let(:member) { create(:group_member, :developer, group: group) } let(:member) { create(:group_member, :developer, group: group) }
before { sign_in(user) } before do
sign_in(user)
end
context 'when member is not found' do context 'when member is not found' do
it 'returns 403' do it 'returns 403' do
...@@ -71,7 +79,9 @@ describe Groups::GroupMembersController do ...@@ -71,7 +79,9 @@ describe Groups::GroupMembersController do
context 'when member is found' do context 'when member is found' do
context 'when user does not have enough rights' do context 'when user does not have enough rights' do
before { group.add_developer(user) } before do
group.add_developer(user)
end
it 'returns 403' do it 'returns 403' do
delete :destroy, group_id: group, id: member delete :destroy, group_id: group, id: member
...@@ -82,7 +92,9 @@ describe Groups::GroupMembersController do ...@@ -82,7 +92,9 @@ describe Groups::GroupMembersController do
end end
context 'when user has enough rights' do context 'when user has enough rights' do
before { group.add_owner(user) } before do
group.add_owner(user)
end
it '[HTML] removes user from members' do it '[HTML] removes user from members' do
delete :destroy, group_id: group, id: member delete :destroy, group_id: group, id: member
...@@ -103,7 +115,9 @@ describe Groups::GroupMembersController do ...@@ -103,7 +115,9 @@ describe Groups::GroupMembersController do
end end
describe 'DELETE leave' do describe 'DELETE leave' do
before { sign_in(user) } before do
sign_in(user)
end
context 'when member is not found' do context 'when member is not found' do
it 'returns 404' do it 'returns 404' do
...@@ -115,7 +129,9 @@ describe Groups::GroupMembersController do ...@@ -115,7 +129,9 @@ describe Groups::GroupMembersController do
context 'when member is found' do context 'when member is found' do
context 'and is not an owner' do context 'and is not an owner' do
before { group.add_developer(user) } before do
group.add_developer(user)
end
it 'removes user from members' do it 'removes user from members' do
delete :leave, group_id: group delete :leave, group_id: group
...@@ -134,7 +150,9 @@ describe Groups::GroupMembersController do ...@@ -134,7 +150,9 @@ describe Groups::GroupMembersController do
end end
context 'and is an owner' do context 'and is an owner' do
before { group.add_owner(user) } before do
group.add_owner(user)
end
it 'cannot removes himself from the group' do it 'cannot removes himself from the group' do
delete :leave, group_id: group delete :leave, group_id: group
...@@ -144,7 +162,9 @@ describe Groups::GroupMembersController do ...@@ -144,7 +162,9 @@ describe Groups::GroupMembersController do
end end
context 'and is a requester' do context 'and is a requester' do
before { group.request_access(user) } before do
group.request_access(user)
end
it 'removes user from members' do it 'removes user from members' do
delete :leave, group_id: group delete :leave, group_id: group
...@@ -159,7 +179,9 @@ describe Groups::GroupMembersController do ...@@ -159,7 +179,9 @@ describe Groups::GroupMembersController do
end end
describe 'POST request_access' do describe 'POST request_access' do
before { sign_in(user) } before do
sign_in(user)
end
it 'creates a new GroupMember that is not a team member' do it 'creates a new GroupMember that is not a team member' do
post :request_access, group_id: group post :request_access, group_id: group
...@@ -174,7 +196,9 @@ describe Groups::GroupMembersController do ...@@ -174,7 +196,9 @@ describe Groups::GroupMembersController do
describe 'POST approve_access_request' do describe 'POST approve_access_request' do
let(:member) { create(:group_member, :access_request, group: group) } let(:member) { create(:group_member, :access_request, group: group) }
before { sign_in(user) } before do
sign_in(user)
end
context 'when member is not found' do context 'when member is not found' do
it 'returns 403' do it 'returns 403' do
...@@ -186,7 +210,9 @@ describe Groups::GroupMembersController do ...@@ -186,7 +210,9 @@ describe Groups::GroupMembersController do
context 'when member is found' do context 'when member is found' do
context 'when user does not have enough rights' do context 'when user does not have enough rights' do
before { group.add_developer(user) } before do
group.add_developer(user)
end
it 'returns 403' do it 'returns 403' do
post :approve_access_request, group_id: group, id: member post :approve_access_request, group_id: group, id: member
...@@ -197,7 +223,9 @@ describe Groups::GroupMembersController do ...@@ -197,7 +223,9 @@ describe Groups::GroupMembersController do
end end
context 'when user has enough rights' do context 'when user has enough rights' do
before { group.add_owner(user) } before do
group.add_owner(user)
end
it 'adds user to members' do it 'adds user to members' do
post :approve_access_request, group_id: group, id: member post :approve_access_request, group_id: group, id: member
......
...@@ -94,7 +94,10 @@ describe NotificationSettingsController do ...@@ -94,7 +94,10 @@ describe NotificationSettingsController do
context 'not authorized' do context 'not authorized' do
let(:private_project) { create(:empty_project, :private) } let(:private_project) { create(:empty_project, :private) }
before { sign_in(user) }
before do
sign_in(user)
end
it 'returns 404' do it 'returns 404' do
post :create, post :create,
...@@ -120,7 +123,9 @@ describe NotificationSettingsController do ...@@ -120,7 +123,9 @@ describe NotificationSettingsController do
end end
context 'when authorized' do context 'when authorized' do
before{ sign_in(user) } before do
sign_in(user)
end
it 'returns success' do it 'returns success' do
put :update, put :update,
...@@ -152,7 +157,9 @@ describe NotificationSettingsController do ...@@ -152,7 +157,9 @@ describe NotificationSettingsController do
context 'not authorized' do context 'not authorized' do
let(:other_user) { create(:user) } let(:other_user) { create(:user) }
before { sign_in(other_user) } before do
sign_in(other_user)
end
it 'returns 404' do it 'returns 404' do
put :update, put :update,
......
...@@ -4,7 +4,9 @@ describe Profiles::PersonalAccessTokensController do ...@@ -4,7 +4,9 @@ describe Profiles::PersonalAccessTokensController do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:token_attributes) { attributes_for(:personal_access_token) } let(:token_attributes) { attributes_for(:personal_access_token) }
before { sign_in(user) } before do
sign_in(user)
end
describe '#create' do describe '#create' do
def created_token def created_token
...@@ -38,7 +40,9 @@ describe Profiles::PersonalAccessTokensController do ...@@ -38,7 +40,9 @@ describe Profiles::PersonalAccessTokensController do
let!(:inactive_personal_access_token) { create(:personal_access_token, :revoked, user: user) } let!(:inactive_personal_access_token) { create(:personal_access_token, :revoked, user: user) }
let!(:impersonation_personal_access_token) { create(:personal_access_token, :impersonation, user: user) } let!(:impersonation_personal_access_token) { create(:personal_access_token, :impersonation, user: user) }
before { get :index } before do
get :index
end
it "retrieves active personal access tokens" do it "retrieves active personal access tokens" do
expect(assigns(:active_personal_access_tokens)).to include(active_personal_access_token) expect(assigns(:active_personal_access_tokens)).to include(active_personal_access_token)
......
...@@ -281,7 +281,9 @@ describe Projects::CommitController do ...@@ -281,7 +281,9 @@ describe Projects::CommitController do
end end
context 'when the path does not exist in the diff' do context 'when the path does not exist in the diff' do
before { diff_for_path(id: commit.id, old_path: existing_path.succ, new_path: existing_path.succ) } before do
diff_for_path(id: commit.id, old_path: existing_path.succ, new_path: existing_path.succ)
end
it 'returns a 404' do it 'returns a 404' do
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -302,7 +304,9 @@ describe Projects::CommitController do ...@@ -302,7 +304,9 @@ describe Projects::CommitController do
end end
context 'when the commit does not exist' do context 'when the commit does not exist' do
before { diff_for_path(id: commit.id.succ, old_path: existing_path, new_path: existing_path) } before do
diff_for_path(id: commit.id.succ, old_path: existing_path, new_path: existing_path)
end
it 'returns a 404' do it 'returns a 404' do
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
......
...@@ -128,7 +128,9 @@ describe Projects::CompareController do ...@@ -128,7 +128,9 @@ describe Projects::CompareController do
end end
context 'when the path does not exist in the diff' do context 'when the path does not exist in the diff' do
before { diff_for_path(from: ref_from, to: ref_to, old_path: existing_path.succ, new_path: existing_path.succ) } before do
diff_for_path(from: ref_from, to: ref_to, old_path: existing_path.succ, new_path: existing_path.succ)
end
it 'returns a 404' do it 'returns a 404' do
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -149,7 +151,9 @@ describe Projects::CompareController do ...@@ -149,7 +151,9 @@ describe Projects::CompareController do
end end
context 'when the from ref does not exist' do context 'when the from ref does not exist' do
before { diff_for_path(from: ref_from.succ, to: ref_to, old_path: existing_path, new_path: existing_path) } before do
diff_for_path(from: ref_from.succ, to: ref_to, old_path: existing_path, new_path: existing_path)
end
it 'returns a 404' do it 'returns a 404' do
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -157,7 +161,9 @@ describe Projects::CompareController do ...@@ -157,7 +161,9 @@ describe Projects::CompareController do
end end
context 'when the to ref does not exist' do context 'when the to ref does not exist' do
before { diff_for_path(from: ref_from, to: ref_to.succ, old_path: existing_path, new_path: existing_path) } before do
diff_for_path(from: ref_from, to: ref_to.succ, old_path: existing_path, new_path: existing_path)
end
it 'returns a 404' do it 'returns a 404' do
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
......
...@@ -14,7 +14,9 @@ describe Projects::ForksController do ...@@ -14,7 +14,9 @@ describe Projects::ForksController do
end end
context 'when fork is public' do context 'when fork is public' do
before { forked_project.update_attribute(:visibility_level, Project::PUBLIC) } before do
forked_project.update_attribute(:visibility_level, Project::PUBLIC)
end
it 'is visible for non logged in users' do it 'is visible for non logged in users' do
get_forks get_forks
...@@ -35,7 +37,9 @@ describe Projects::ForksController do ...@@ -35,7 +37,9 @@ describe Projects::ForksController do
end end
context 'when user is logged in' do context 'when user is logged in' do
before { sign_in(project.creator) } before do
sign_in(project.creator)
end
context 'when user is not a Project member neither a group member' do context 'when user is not a Project member neither a group member' do
it 'does not see the Project listed' do it 'does not see the Project listed' do
...@@ -46,7 +50,9 @@ describe Projects::ForksController do ...@@ -46,7 +50,9 @@ describe Projects::ForksController do
end end
context 'when user is a member of the Project' do context 'when user is a member of the Project' do
before { forked_project.team << [project.creator, :developer] } before do
forked_project.team << [project.creator, :developer]
end
it 'sees the project listed' do it 'sees the project listed' do
get_forks get_forks
...@@ -56,7 +62,9 @@ describe Projects::ForksController do ...@@ -56,7 +62,9 @@ describe Projects::ForksController do
end end
context 'when user is a member of the Group' do context 'when user is a member of the Group' do
before { forked_project.group.add_developer(project.creator) } before do
forked_project.group.add_developer(project.creator)
end
it 'sees the project listed' do it 'sees the project listed' do
get_forks get_forks
......
...@@ -22,7 +22,10 @@ describe Projects::GroupLinksController do ...@@ -22,7 +22,10 @@ describe Projects::GroupLinksController do
end end
context 'when user has access to group he want to link project to' do context 'when user has access to group he want to link project to' do
before { group.add_developer(user) } before do
group.add_developer(user)
end
include_context 'link project to group' include_context 'link project to group'
it 'links project with selected group' do it 'links project with selected group' do
......
...@@ -212,7 +212,9 @@ describe Projects::IssuesController do ...@@ -212,7 +212,9 @@ describe Projects::IssuesController do
let(:another_project) { create(:empty_project, :private) } let(:another_project) { create(:empty_project, :private) }
context 'when user has access to move issue' do context 'when user has access to move issue' do
before { another_project.team << [user, :reporter] } before do
another_project.team << [user, :reporter]
end
it 'moves issue to another project' do it 'moves issue to another project' do
move_issue move_issue
...@@ -250,14 +252,18 @@ describe Projects::IssuesController do ...@@ -250,14 +252,18 @@ describe Projects::IssuesController do
end end
context 'when an issue is identified as spam' do context 'when an issue is identified as spam' do
before { allow_any_instance_of(AkismetService).to receive(:is_spam?).and_return(true) } before do
allow_any_instance_of(AkismetService).to receive(:is_spam?).and_return(true)
end
context 'when captcha is not verified' do context 'when captcha is not verified' do
def update_spam_issue def update_spam_issue
update_issue(title: 'Spam Title', description: 'Spam lives here') update_issue(title: 'Spam Title', description: 'Spam lives here')
end end
before { allow_any_instance_of(described_class).to receive(:verify_recaptcha).and_return(false) } before do
allow_any_instance_of(described_class).to receive(:verify_recaptcha).and_return(false)
end
it 'rejects an issue recognized as a spam' do it 'rejects an issue recognized as a spam' do
expect(Gitlab::Recaptcha).to receive(:load_configurations!).and_return(true) expect(Gitlab::Recaptcha).to receive(:load_configurations!).and_return(true)
...@@ -620,14 +626,18 @@ describe Projects::IssuesController do ...@@ -620,14 +626,18 @@ describe Projects::IssuesController do
end end
context 'when an issue is identified as spam' do context 'when an issue is identified as spam' do
before { allow_any_instance_of(AkismetService).to receive(:is_spam?).and_return(true) } before do
allow_any_instance_of(AkismetService).to receive(:is_spam?).and_return(true)
end
context 'when captcha is not verified' do context 'when captcha is not verified' do
def post_spam_issue def post_spam_issue
post_new_issue(title: 'Spam Title', description: 'Spam lives here') post_new_issue(title: 'Spam Title', description: 'Spam lives here')
end end
before { allow_any_instance_of(described_class).to receive(:verify_recaptcha).and_return(false) } before do
allow_any_instance_of(described_class).to receive(:verify_recaptcha).and_return(false)
end
it 'rejects an issue recognized as a spam' do it 'rejects an issue recognized as a spam' do
expect { post_spam_issue }.not_to change(Issue, :count) expect { post_spam_issue }.not_to change(Issue, :count)
...@@ -739,7 +749,10 @@ describe Projects::IssuesController do ...@@ -739,7 +749,10 @@ describe Projects::IssuesController do
describe "DELETE #destroy" do describe "DELETE #destroy" do
context "when the user is a developer" do context "when the user is a developer" do
before { sign_in(user) } before do
sign_in(user)
end
it "rejects a developer to destroy an issue" do it "rejects a developer to destroy an issue" do
delete :destroy, namespace_id: project.namespace, project_id: project, id: issue.iid delete :destroy, namespace_id: project.namespace, project_id: project, id: issue.iid
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -751,7 +764,9 @@ describe Projects::IssuesController do ...@@ -751,7 +764,9 @@ describe Projects::IssuesController do
let(:namespace) { create(:namespace, owner: owner) } let(:namespace) { create(:namespace, owner: owner) }
let(:project) { create(:empty_project, namespace: namespace) } let(:project) { create(:empty_project, namespace: namespace) }
before { sign_in(owner) } before do
sign_in(owner)
end
it "deletes the issue" do it "deletes the issue" do
delete :destroy, namespace_id: project.namespace, project_id: project, id: issue.iid delete :destroy, namespace_id: project.namespace, project_id: project, id: issue.iid
......
...@@ -19,7 +19,10 @@ describe Projects::MergeRequestsController do ...@@ -19,7 +19,10 @@ describe Projects::MergeRequestsController do
render_views render_views
let(:fork_project) { create(:forked_project_with_submodules) } let(:fork_project) { create(:forked_project_with_submodules) }
before { fork_project.team << [user, :master] }
before do
fork_project.team << [user, :master]
end
context 'when rendering HTML response' do context 'when rendering HTML response' do
it 'renders new merge request widget template' do it 'renders new merge request widget template' do
...@@ -328,7 +331,9 @@ describe Projects::MergeRequestsController do ...@@ -328,7 +331,9 @@ describe Projects::MergeRequestsController do
end end
context 'when the sha parameter does not match the source SHA' do context 'when the sha parameter does not match the source SHA' do
before { post :merge, base_params.merge(sha: 'foo') } before do
post :merge, base_params.merge(sha: 'foo')
end
it 'returns :sha_mismatch' do it 'returns :sha_mismatch' do
expect(json_response).to eq('status' => 'sha_mismatch') expect(json_response).to eq('status' => 'sha_mismatch')
...@@ -473,7 +478,9 @@ describe Projects::MergeRequestsController do ...@@ -473,7 +478,9 @@ describe Projects::MergeRequestsController do
let(:namespace) { create(:namespace, owner: owner) } let(:namespace) { create(:namespace, owner: owner) }
let(:project) { create(:project, namespace: namespace) } let(:project) { create(:project, namespace: namespace) }
before { sign_in owner } before do
sign_in owner
end
it "deletes the merge request" do it "deletes the merge request" do
delete :destroy, namespace_id: project.namespace, project_id: project, id: merge_request.iid delete :destroy, namespace_id: project.namespace, project_id: project, id: merge_request.iid
...@@ -505,7 +512,9 @@ describe Projects::MergeRequestsController do ...@@ -505,7 +512,9 @@ describe Projects::MergeRequestsController do
context 'with default params' do context 'with default params' do
context 'as html' do context 'as html' do
before { go(format: 'html') } before do
go(format: 'html')
end
it 'renders the diff template' do it 'renders the diff template' do
expect(response).to render_template('diffs') expect(response).to render_template('diffs')
...@@ -513,7 +522,9 @@ describe Projects::MergeRequestsController do ...@@ -513,7 +522,9 @@ describe Projects::MergeRequestsController do
end end
context 'as json' do context 'as json' do
before { go(format: 'json') } before do
go(format: 'json')
end
it 'renders the diffs template to a string' do it 'renders the diffs template to a string' do
expect(response).to render_template('projects/merge_requests/show/_diffs') expect(response).to render_template('projects/merge_requests/show/_diffs')
...@@ -544,7 +555,9 @@ describe Projects::MergeRequestsController do ...@@ -544,7 +555,9 @@ describe Projects::MergeRequestsController do
context 'with ignore_whitespace_change' do context 'with ignore_whitespace_change' do
context 'as html' do context 'as html' do
before { go(format: 'html', w: 1) } before do
go(format: 'html', w: 1)
end
it 'renders the diff template' do it 'renders the diff template' do
expect(response).to render_template('diffs') expect(response).to render_template('diffs')
...@@ -552,7 +565,9 @@ describe Projects::MergeRequestsController do ...@@ -552,7 +565,9 @@ describe Projects::MergeRequestsController do
end end
context 'as json' do context 'as json' do
before { go(format: 'json', w: 1) } before do
go(format: 'json', w: 1)
end
it 'renders the diffs template to a string' do it 'renders the diffs template to a string' do
expect(response).to render_template('projects/merge_requests/show/_diffs') expect(response).to render_template('projects/merge_requests/show/_diffs')
...@@ -562,7 +577,9 @@ describe Projects::MergeRequestsController do ...@@ -562,7 +577,9 @@ describe Projects::MergeRequestsController do
end end
context 'with view' do context 'with view' do
before { go(view: 'parallel') } before do
go(view: 'parallel')
end
it 'saves the preferred diff view in a cookie' do it 'saves the preferred diff view in a cookie' do
expect(response.cookies['diff_view']).to eq('parallel') expect(response.cookies['diff_view']).to eq('parallel')
...@@ -605,7 +622,9 @@ describe Projects::MergeRequestsController do ...@@ -605,7 +622,9 @@ describe Projects::MergeRequestsController do
end end
context 'when the path does not exist in the diff' do context 'when the path does not exist in the diff' do
before { diff_for_path(id: merge_request.iid, old_path: 'files/ruby/nopen.rb', new_path: 'files/ruby/nopen.rb') } before do
diff_for_path(id: merge_request.iid, old_path: 'files/ruby/nopen.rb', new_path: 'files/ruby/nopen.rb')
end
it 'returns a 404' do it 'returns a 404' do
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -626,7 +645,9 @@ describe Projects::MergeRequestsController do ...@@ -626,7 +645,9 @@ describe Projects::MergeRequestsController do
end end
context 'when the merge request does not exist' do context 'when the merge request does not exist' do
before { diff_for_path(id: merge_request.iid.succ, old_path: existing_path, new_path: existing_path) } before do
diff_for_path(id: merge_request.iid.succ, old_path: existing_path, new_path: existing_path)
end
it 'returns a 404' do it 'returns a 404' do
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -670,7 +691,9 @@ describe Projects::MergeRequestsController do ...@@ -670,7 +691,9 @@ describe Projects::MergeRequestsController do
context 'when the source branch is in a different project to the target' do context 'when the source branch is in a different project to the target' do
let(:other_project) { create(:project) } let(:other_project) { create(:project) }
before { other_project.team << [user, :master] } before do
other_project.team << [user, :master]
end
context 'when the path exists in the diff' do context 'when the path exists in the diff' do
it 'disables diff notes' do it 'disables diff notes' do
...@@ -690,7 +713,9 @@ describe Projects::MergeRequestsController do ...@@ -690,7 +713,9 @@ describe Projects::MergeRequestsController do
end end
context 'when the path does not exist in the diff' do context 'when the path does not exist in the diff' do
before { diff_for_path(old_path: 'files/ruby/nopen.rb', new_path: 'files/ruby/nopen.rb', merge_request: { source_project: other_project, source_branch: 'feature', target_branch: 'master' }) } before do
diff_for_path(old_path: 'files/ruby/nopen.rb', new_path: 'files/ruby/nopen.rb', merge_request: { source_project: other_project, source_branch: 'feature', target_branch: 'master' })
end
it 'returns a 404' do it 'returns a 404' do
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -913,7 +938,9 @@ describe Projects::MergeRequestsController do ...@@ -913,7 +938,9 @@ describe Projects::MergeRequestsController do
end end
context 'when the file does not exist cannot be resolved in the UI' do context 'when the file does not exist cannot be resolved in the UI' do
before { conflict_for_path('files/ruby/regexp.rb') } before do
conflict_for_path('files/ruby/regexp.rb')
end
it 'returns a 404 status code' do it 'returns a 404 status code' do
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
...@@ -923,7 +950,9 @@ describe Projects::MergeRequestsController do ...@@ -923,7 +950,9 @@ describe Projects::MergeRequestsController do
context 'with an existing file' do context 'with an existing file' do
let(:path) { 'files/ruby/regex.rb' } let(:path) { 'files/ruby/regex.rb' }
before { conflict_for_path(path) } before do
conflict_for_path(path)
end
it 'returns a 200 status code' do it 'returns a 200 status code' do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
...@@ -1195,7 +1224,9 @@ describe Projects::MergeRequestsController do ...@@ -1195,7 +1224,9 @@ describe Projects::MergeRequestsController do
end end
context 'when head_pipeline does not exist' do context 'when head_pipeline does not exist' do
before { get_pipeline_status } before do
get_pipeline_status
end
it 'return empty' do it 'return empty' do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
......
...@@ -16,10 +16,14 @@ describe Projects::ProjectMembersController do ...@@ -16,10 +16,14 @@ describe Projects::ProjectMembersController do
describe 'POST create' do describe 'POST create' do
let(:project_user) { create(:user) } let(:project_user) { create(:user) }
before { sign_in(user) } before do
sign_in(user)
end
context 'when user does not have enough rights' do context 'when user does not have enough rights' do
before { project.team << [user, :developer] } before do
project.team << [user, :developer]
end
it 'returns 404' do it 'returns 404' do
post :create, namespace_id: project.namespace, post :create, namespace_id: project.namespace,
...@@ -33,7 +37,9 @@ describe Projects::ProjectMembersController do ...@@ -33,7 +37,9 @@ describe Projects::ProjectMembersController do
end end
context 'when user has enough rights' do context 'when user has enough rights' do
before { project.team << [user, :master] } before do
project.team << [user, :master]
end
it 'adds user to members' do it 'adds user to members' do
expect_any_instance_of(Members::CreateService).to receive(:execute).and_return(status: :success) expect_any_instance_of(Members::CreateService).to receive(:execute).and_return(status: :success)
...@@ -64,7 +70,9 @@ describe Projects::ProjectMembersController do ...@@ -64,7 +70,9 @@ describe Projects::ProjectMembersController do
describe 'DELETE destroy' do describe 'DELETE destroy' do
let(:member) { create(:project_member, :developer, project: project) } let(:member) { create(:project_member, :developer, project: project) }
before { sign_in(user) } before do
sign_in(user)
end
context 'when member is not found' do context 'when member is not found' do
it 'returns 404' do it 'returns 404' do
...@@ -78,7 +86,9 @@ describe Projects::ProjectMembersController do ...@@ -78,7 +86,9 @@ describe Projects::ProjectMembersController do
context 'when member is found' do context 'when member is found' do
context 'when user does not have enough rights' do context 'when user does not have enough rights' do
before { project.team << [user, :developer] } before do
project.team << [user, :developer]
end
it 'returns 404' do it 'returns 404' do
delete :destroy, namespace_id: project.namespace, delete :destroy, namespace_id: project.namespace,
...@@ -91,7 +101,9 @@ describe Projects::ProjectMembersController do ...@@ -91,7 +101,9 @@ describe Projects::ProjectMembersController do
end end
context 'when user has enough rights' do context 'when user has enough rights' do
before { project.team << [user, :master] } before do
project.team << [user, :master]
end
it '[HTML] removes user from members' do it '[HTML] removes user from members' do
delete :destroy, namespace_id: project.namespace, delete :destroy, namespace_id: project.namespace,
...@@ -117,7 +129,9 @@ describe Projects::ProjectMembersController do ...@@ -117,7 +129,9 @@ describe Projects::ProjectMembersController do
end end
describe 'DELETE leave' do describe 'DELETE leave' do
before { sign_in(user) } before do
sign_in(user)
end
context 'when member is not found' do context 'when member is not found' do
it 'returns 404' do it 'returns 404' do
...@@ -130,7 +144,9 @@ describe Projects::ProjectMembersController do ...@@ -130,7 +144,9 @@ describe Projects::ProjectMembersController do
context 'when member is found' do context 'when member is found' do
context 'and is not an owner' do context 'and is not an owner' do
before { project.team << [user, :developer] } before do
project.team << [user, :developer]
end
it 'removes user from members' do it 'removes user from members' do
delete :leave, namespace_id: project.namespace, delete :leave, namespace_id: project.namespace,
...@@ -145,7 +161,9 @@ describe Projects::ProjectMembersController do ...@@ -145,7 +161,9 @@ describe Projects::ProjectMembersController do
context 'and is an owner' do context 'and is an owner' do
let(:project) { create(:empty_project, namespace: user.namespace) } let(:project) { create(:empty_project, namespace: user.namespace) }
before { project.team << [user, :master] } before do
project.team << [user, :master]
end
it 'cannot remove himself from the project' do it 'cannot remove himself from the project' do
delete :leave, namespace_id: project.namespace, delete :leave, namespace_id: project.namespace,
...@@ -156,7 +174,9 @@ describe Projects::ProjectMembersController do ...@@ -156,7 +174,9 @@ describe Projects::ProjectMembersController do
end end
context 'and is a requester' do context 'and is a requester' do
before { project.request_access(user) } before do
project.request_access(user)
end
it 'removes user from members' do it 'removes user from members' do
delete :leave, namespace_id: project.namespace, delete :leave, namespace_id: project.namespace,
...@@ -172,7 +192,9 @@ describe Projects::ProjectMembersController do ...@@ -172,7 +192,9 @@ describe Projects::ProjectMembersController do
end end
describe 'POST request_access' do describe 'POST request_access' do
before { sign_in(user) } before do
sign_in(user)
end
it 'creates a new ProjectMember that is not a team member' do it 'creates a new ProjectMember that is not a team member' do
post :request_access, namespace_id: project.namespace, post :request_access, namespace_id: project.namespace,
...@@ -190,7 +212,9 @@ describe Projects::ProjectMembersController do ...@@ -190,7 +212,9 @@ describe Projects::ProjectMembersController do
describe 'POST approve' do describe 'POST approve' do
let(:member) { create(:project_member, :access_request, project: project) } let(:member) { create(:project_member, :access_request, project: project) }
before { sign_in(user) } before do
sign_in(user)
end
context 'when member is not found' do context 'when member is not found' do
it 'returns 404' do it 'returns 404' do
...@@ -204,7 +228,9 @@ describe Projects::ProjectMembersController do ...@@ -204,7 +228,9 @@ describe Projects::ProjectMembersController do
context 'when member is found' do context 'when member is found' do
context 'when user does not have enough rights' do context 'when user does not have enough rights' do
before { project.team << [user, :developer] } before do
project.team << [user, :developer]
end
it 'returns 404' do it 'returns 404' do
post :approve_access_request, namespace_id: project.namespace, post :approve_access_request, namespace_id: project.namespace,
...@@ -217,7 +243,9 @@ describe Projects::ProjectMembersController do ...@@ -217,7 +243,9 @@ describe Projects::ProjectMembersController do
end end
context 'when user has enough rights' do context 'when user has enough rights' do
before { project.team << [user, :master] } before do
project.team << [user, :master]
end
it 'adds user to members' do it 'adds user to members' do
post :approve_access_request, namespace_id: project.namespace, post :approve_access_request, namespace_id: project.namespace,
...@@ -252,7 +280,10 @@ describe Projects::ProjectMembersController do ...@@ -252,7 +280,10 @@ describe Projects::ProjectMembersController do
end end
context 'when user can access source project members' do context 'when user can access source project members' do
before { another_project.team << [user, :guest] } before do
another_project.team << [user, :guest]
end
include_context 'import applied' include_context 'import applied'
it 'imports source project members' do it 'imports source project members' do
......
...@@ -46,7 +46,9 @@ describe Projects::SnippetsController do ...@@ -46,7 +46,9 @@ describe Projects::SnippetsController do
end end
context 'when signed in as the author' do context 'when signed in as the author' do
before { sign_in(user) } before do
sign_in(user)
end
it 'renders the snippet' do it 'renders the snippet' do
get :index, namespace_id: project.namespace, project_id: project get :index, namespace_id: project.namespace, project_id: project
...@@ -57,7 +59,9 @@ describe Projects::SnippetsController do ...@@ -57,7 +59,9 @@ describe Projects::SnippetsController do
end end
context 'when signed in as a project member' do context 'when signed in as a project member' do
before { sign_in(user2) } before do
sign_in(user2)
end
it 'renders the snippet' do it 'renders the snippet' do
get :index, namespace_id: project.namespace, project_id: project get :index, namespace_id: project.namespace, project_id: project
...@@ -317,7 +321,9 @@ describe Projects::SnippetsController do ...@@ -317,7 +321,9 @@ describe Projects::SnippetsController do
end end
context 'when signed in as the author' do context 'when signed in as the author' do
before { sign_in(user) } before do
sign_in(user)
end
it 'renders the snippet' do it 'renders the snippet' do
get action, namespace_id: project.namespace, project_id: project, id: project_snippet.to_param get action, namespace_id: project.namespace, project_id: project, id: project_snippet.to_param
...@@ -328,7 +334,9 @@ describe Projects::SnippetsController do ...@@ -328,7 +334,9 @@ describe Projects::SnippetsController do
end end
context 'when signed in as a project member' do context 'when signed in as a project member' do
before { sign_in(user2) } before do
sign_in(user2)
end
it 'renders the snippet' do it 'renders the snippet' do
get action, namespace_id: project.namespace, project_id: project, id: project_snippet.to_param get action, namespace_id: project.namespace, project_id: project, id: project_snippet.to_param
...@@ -349,7 +357,9 @@ describe Projects::SnippetsController do ...@@ -349,7 +357,9 @@ describe Projects::SnippetsController do
end end
context 'when signed in' do context 'when signed in' do
before { sign_in(user) } before do
sign_in(user)
end
it 'responds with status 404' do it 'responds with status 404' do
get action, namespace_id: project.namespace, project_id: project, id: 42 get action, namespace_id: project.namespace, project_id: project, id: 42
......
...@@ -6,7 +6,9 @@ describe Projects::TagsController do ...@@ -6,7 +6,9 @@ describe Projects::TagsController do
let!(:invalid_release) { create(:release, project: project, tag: 'does-not-exist') } let!(:invalid_release) { create(:release, project: project, tag: 'does-not-exist') }
describe 'GET index' do describe 'GET index' do
before { get :index, namespace_id: project.namespace.to_param, project_id: project } before do
get :index, namespace_id: project.namespace.to_param, project_id: project
end
it 'returns the tags for the page' do it 'returns the tags for the page' do
expect(assigns(:tags).map(&:name)).to eq(['v1.1.0', 'v1.0.0']) expect(assigns(:tags).map(&:name)).to eq(['v1.1.0', 'v1.0.0'])
...@@ -19,7 +21,9 @@ describe Projects::TagsController do ...@@ -19,7 +21,9 @@ describe Projects::TagsController do
end end
describe 'GET show' do describe 'GET show' do
before { get :show, namespace_id: project.namespace.to_param, project_id: project, id: id } before do
get :show, namespace_id: project.namespace.to_param, project_id: project, id: id
end
context "valid tag" do context "valid tag" do
let(:id) { 'v1.0.0' } let(:id) { 'v1.0.0' }
......
...@@ -29,7 +29,9 @@ describe ProjectsController do ...@@ -29,7 +29,9 @@ describe ProjectsController do
describe "GET show" do describe "GET show" do
context "user not project member" do context "user not project member" do
before { sign_in(user) } before do
sign_in(user)
end
context "user does not have access to project" do context "user does not have access to project" do
let(:private_project) { create(:empty_project, :private) } let(:private_project) { create(:empty_project, :private) }
...@@ -108,7 +110,9 @@ describe ProjectsController do ...@@ -108,7 +110,9 @@ describe ProjectsController do
context "project with empty repo" do context "project with empty repo" do
let(:empty_project) { create(:project_empty_repo, :public) } let(:empty_project) { create(:project_empty_repo, :public) }
before { sign_in(user) } before do
sign_in(user)
end
User.project_views.keys.each do |project_view| User.project_views.keys.each do |project_view|
context "with #{project_view} view set" do context "with #{project_view} view set" do
...@@ -128,7 +132,9 @@ describe ProjectsController do ...@@ -128,7 +132,9 @@ describe ProjectsController do
context "project with broken repo" do context "project with broken repo" do
let(:empty_project) { create(:project_broken_repo, :public) } let(:empty_project) { create(:project_broken_repo, :public) }
before { sign_in(user) } before do
sign_in(user)
end
User.project_views.keys.each do |project_view| User.project_views.keys.each do |project_view|
context "with #{project_view} view set" do context "with #{project_view} view set" do
......
...@@ -18,7 +18,9 @@ describe SearchController do ...@@ -18,7 +18,9 @@ describe SearchController do
context 'on restricted projects' do context 'on restricted projects' do
context 'when signed out' do context 'when signed out' do
before { sign_out(user) } before do
sign_out(user)
end
it "doesn't expose comments on issues" do it "doesn't expose comments on issues" do
project = create(:empty_project, :public, :issues_private) project = create(:empty_project, :public, :issues_private)
......
...@@ -14,7 +14,9 @@ describe SentNotificationsController, type: :controller do ...@@ -14,7 +14,9 @@ describe SentNotificationsController, type: :controller do
describe 'GET unsubscribe' do describe 'GET unsubscribe' do
context 'when the user is not logged in' do context 'when the user is not logged in' do
context 'when the force param is passed' do context 'when the force param is passed' do
before { get(:unsubscribe, id: sent_notification.reply_key, force: true) } before do
get(:unsubscribe, id: sent_notification.reply_key, force: true)
end
it 'unsubscribes the user' do it 'unsubscribes the user' do
expect(issue.subscribed?(user, project)).to be_falsey expect(issue.subscribed?(user, project)).to be_falsey
...@@ -30,7 +32,9 @@ describe SentNotificationsController, type: :controller do ...@@ -30,7 +32,9 @@ describe SentNotificationsController, type: :controller do
end end
context 'when the force param is not passed' do context 'when the force param is not passed' do
before { get(:unsubscribe, id: sent_notification.reply_key) } before do
get(:unsubscribe, id: sent_notification.reply_key)
end
it 'does not unsubscribe the user' do it 'does not unsubscribe the user' do
expect(issue.subscribed?(user, project)).to be_truthy expect(issue.subscribed?(user, project)).to be_truthy
...@@ -47,10 +51,14 @@ describe SentNotificationsController, type: :controller do ...@@ -47,10 +51,14 @@ describe SentNotificationsController, type: :controller do
end end
context 'when the user is logged in' do context 'when the user is logged in' do
before { sign_in(user) } before do
sign_in(user)
end
context 'when the ID passed does not exist' do context 'when the ID passed does not exist' do
before { get(:unsubscribe, id: sent_notification.reply_key.reverse) } before do
get(:unsubscribe, id: sent_notification.reply_key.reverse)
end
it 'does not unsubscribe the user' do it 'does not unsubscribe the user' do
expect(issue.subscribed?(user, project)).to be_truthy expect(issue.subscribed?(user, project)).to be_truthy
...@@ -66,7 +74,9 @@ describe SentNotificationsController, type: :controller do ...@@ -66,7 +74,9 @@ describe SentNotificationsController, type: :controller do
end end
context 'when the force param is passed' do context 'when the force param is passed' do
before { get(:unsubscribe, id: sent_notification.reply_key, force: true) } before do
get(:unsubscribe, id: sent_notification.reply_key, force: true)
end
it 'unsubscribes the user' do it 'unsubscribes the user' do
expect(issue.subscribed?(user, project)).to be_falsey expect(issue.subscribed?(user, project)).to be_falsey
...@@ -89,7 +99,10 @@ describe SentNotificationsController, type: :controller do ...@@ -89,7 +99,10 @@ describe SentNotificationsController, type: :controller do
end end
end end
let(:sent_notification) { create(:sent_notification, project: project, noteable: merge_request, recipient: user) } let(:sent_notification) { create(:sent_notification, project: project, noteable: merge_request, recipient: user) }
before { get(:unsubscribe, id: sent_notification.reply_key) }
before do
get(:unsubscribe, id: sent_notification.reply_key)
end
it 'unsubscribes the user' do it 'unsubscribes the user' do
expect(merge_request.subscribed?(user, project)).to be_falsey expect(merge_request.subscribed?(user, project)).to be_falsey
......
...@@ -142,7 +142,9 @@ describe SessionsController do ...@@ -142,7 +142,9 @@ describe SessionsController do
end end
context 'when OTP is invalid' do context 'when OTP is invalid' do
before { authenticate_2fa(otp_attempt: 'invalid') } before do
authenticate_2fa(otp_attempt: 'invalid')
end
it 'does not authenticate' do it 'does not authenticate' do
expect(subject.current_user).not_to eq user expect(subject.current_user).not_to eq user
...@@ -169,7 +171,9 @@ describe SessionsController do ...@@ -169,7 +171,9 @@ describe SessionsController do
end end
context 'when OTP is invalid' do context 'when OTP is invalid' do
before { authenticate_2fa(otp_attempt: 'invalid') } before do
authenticate_2fa(otp_attempt: 'invalid')
end
it 'does not authenticate' do it 'does not authenticate' do
expect(subject.current_user).not_to eq user expect(subject.current_user).not_to eq user
......
...@@ -437,7 +437,9 @@ describe SnippetsController do ...@@ -437,7 +437,9 @@ describe SnippetsController do
end end
context 'when signed in user is the author' do context 'when signed in user is the author' do
before { get :raw, id: personal_snippet.to_param } before do
get :raw, id: personal_snippet.to_param
end
it 'responds with status 200' do it 'responds with status 200' do
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
......
...@@ -43,7 +43,9 @@ describe UsersController do ...@@ -43,7 +43,9 @@ describe UsersController do
end end
context 'when logged in' do context 'when logged in' do
before { sign_in(user) } before do
sign_in(user)
end
it 'renders show' do it 'renders show' do
get :show, username: user.username get :show, username: user.username
...@@ -62,7 +64,9 @@ describe UsersController do ...@@ -62,7 +64,9 @@ describe UsersController do
end end
context 'when logged in' do context 'when logged in' do
before { sign_in(user) } before do
sign_in(user)
end
it 'renders 404' do it 'renders 404' do
get :show, username: 'nonexistent' get :show, username: 'nonexistent'
......
...@@ -134,7 +134,10 @@ describe "Admin Runners" do ...@@ -134,7 +134,10 @@ describe "Admin Runners" do
describe 'runners registration token' do describe 'runners registration token' do
let!(:token) { current_application_settings.runners_registration_token } let!(:token) { current_application_settings.runners_registration_token }
before { visit admin_runners_path }
before do
visit admin_runners_path
end
it 'has a registration token' do it 'has a registration token' do
expect(page).to have_content("Registration token is #{token}") expect(page).to have_content("Registration token is #{token}")
......
...@@ -12,7 +12,9 @@ describe 'Admin > Users > Impersonation Tokens', feature: true, js: true do ...@@ -12,7 +12,9 @@ describe 'Admin > Users > Impersonation Tokens', feature: true, js: true do
find(".table.inactive-tokens") find(".table.inactive-tokens")
end end
before { login_as(admin) } before do
login_as(admin)
end
describe "token creation" do describe "token creation" do
it "allows creation of a token" do it "allows creation of a token" do
......
...@@ -124,7 +124,10 @@ describe "Admin::Users", feature: true do ...@@ -124,7 +124,10 @@ describe "Admin::Users", feature: true do
describe 'Impersonation' do describe 'Impersonation' do
let(:another_user) { create(:user) } let(:another_user) { create(:user) }
before { visit admin_user_path(another_user) }
before do
visit admin_user_path(another_user)
end
context 'before impersonating' do context 'before impersonating' do
it 'shows impersonate button for other users' do it 'shows impersonate button for other users' do
...@@ -149,7 +152,9 @@ describe "Admin::Users", feature: true do ...@@ -149,7 +152,9 @@ describe "Admin::Users", feature: true do
end end
context 'when impersonating' do context 'when impersonating' do
before { click_link 'Impersonate' } before do
click_link 'Impersonate'
end
it 'logs in as the user when impersonate is clicked' do it 'logs in as the user when impersonate is clicked' do
expect(page.find(:css, '.header-user .profile-link')['data-user']).to eql(another_user.username) expect(page.find(:css, '.header-user .profile-link')['data-user']).to eql(another_user.username)
......
...@@ -12,7 +12,9 @@ describe 'Dashboard Merge Requests' do ...@@ -12,7 +12,9 @@ describe 'Dashboard Merge Requests' do
end end
describe 'new merge request dropdown' do describe 'new merge request dropdown' do
before { visit merge_requests_dashboard_path } before do
visit merge_requests_dashboard_path
end
it 'shows projects only with merge requests feature enabled', js: true do it 'shows projects only with merge requests feature enabled', js: true do
find('.new-project-item-select-button').trigger('click') find('.new-project-item-select-button').trigger('click')
......
...@@ -17,19 +17,25 @@ feature 'Project member activity', feature: true, js: true do ...@@ -17,19 +17,25 @@ feature 'Project member activity', feature: true, js: true do
subject { page.find(".event-title").text } subject { page.find(".event-title").text }
context 'when a user joins the project' do context 'when a user joins the project' do
before { visit_activities_and_wait_with_event(Event::JOINED) } before do
visit_activities_and_wait_with_event(Event::JOINED)
end
it { is_expected.to eq("#{user.name} joined project") } it { is_expected.to eq("#{user.name} joined project") }
end end
context 'when a user leaves the project' do context 'when a user leaves the project' do
before { visit_activities_and_wait_with_event(Event::LEFT) } before do
visit_activities_and_wait_with_event(Event::LEFT)
end
it { is_expected.to eq("#{user.name} left project") } it { is_expected.to eq("#{user.name} left project") }
end end
context 'when a users membership expires for the project' do context 'when a users membership expires for the project' do
before { visit_activities_and_wait_with_event(Event::EXPIRED) } before do
visit_activities_and_wait_with_event(Event::EXPIRED)
end
it "presents the correct message" do it "presents the correct message" do
message = "#{user.name} removed due to membership expiration from project" message = "#{user.name} removed due to membership expiration from project"
......
...@@ -140,7 +140,9 @@ feature 'Expand and collapse diffs', js: true, feature: true do ...@@ -140,7 +140,9 @@ feature 'Expand and collapse diffs', js: true, feature: true do
end end
context 'reloading the page' do context 'reloading the page' do
before { refresh } before do
refresh
end
it 'collapses the large diff by default' do it 'collapses the large diff by default' do
expect(large_diff).not_to have_selector('.code') expect(large_diff).not_to have_selector('.code')
......
...@@ -52,9 +52,14 @@ feature 'Edit group settings', feature: true do ...@@ -52,9 +52,14 @@ feature 'Edit group settings', feature: true do
given!(:project) { create(:project, group: group, path: 'project') } given!(:project) { create(:project, group: group, path: 'project') }
given(:old_project_full_path) { "/#{group.path}/#{project.path}" } given(:old_project_full_path) { "/#{group.path}/#{project.path}" }
given(:new_project_full_path) { "/#{new_group_path}/#{project.path}" } given(:new_project_full_path) { "/#{new_group_path}/#{project.path}" }
before(:context) { TestEnv.clean_test_path } before(:context) do
after(:example) { TestEnv.clean_test_path } TestEnv.clean_test_path
end
after(:example) do
TestEnv.clean_test_path
end
scenario 'the project is accessible via the new path' do scenario 'the project is accessible via the new path' do
update_path(new_group_path) update_path(new_group_path)
......
...@@ -12,7 +12,9 @@ feature 'Group', feature: true do ...@@ -12,7 +12,9 @@ feature 'Group', feature: true do
end end
describe 'create a group' do describe 'create a group' do
before { visit new_group_path } before do
visit new_group_path
end
describe 'with space in group path' do describe 'with space in group path' do
it 'renders new group form with validation errors' do it 'renders new group form with validation errors' do
...@@ -138,7 +140,9 @@ feature 'Group', feature: true do ...@@ -138,7 +140,9 @@ feature 'Group', feature: true do
let(:path) { edit_group_path(group) } let(:path) { edit_group_path(group) }
let(:new_name) { 'new-name' } let(:new_name) { 'new-name' }
before { visit path } before do
visit path
end
it 'saves new settings' do it 'saves new settings' do
fill_in 'group_name', with: new_name fill_in 'group_name', with: new_name
......
...@@ -153,7 +153,9 @@ describe 'Projects > Issuables > Default sort order', feature: true do ...@@ -153,7 +153,9 @@ describe 'Projects > Issuables > Default sort order', feature: true do
context 'when the sort in the URL is id_desc' do context 'when the sort in the URL is id_desc' do
let(:issuable_type) { :issue } let(:issuable_type) { :issue }
before { visit_issues(project, sort: 'id_desc') } before do
visit_issues(project, sort: 'id_desc')
end
it 'shows the sort order as last created' do it 'shows the sort order as last created' do
expect(find('.issues-other-filters')).to have_content('Last created') expect(find('.issues-other-filters')).to have_content('Last created')
...@@ -165,7 +167,9 @@ describe 'Projects > Issuables > Default sort order', feature: true do ...@@ -165,7 +167,9 @@ describe 'Projects > Issuables > Default sort order', feature: true do
context 'when the sort in the URL is id_asc' do context 'when the sort in the URL is id_asc' do
let(:issuable_type) { :issue } let(:issuable_type) { :issue }
before { visit_issues(project, sort: 'id_asc') } before do
visit_issues(project, sort: 'id_asc')
end
it 'shows the sort order as oldest created' do it 'shows the sort order as oldest created' do
expect(find('.issues-other-filters')).to have_content('Oldest created') expect(find('.issues-other-filters')).to have_content('Oldest created')
......
...@@ -246,7 +246,10 @@ describe 'Issues', feature: true do ...@@ -246,7 +246,10 @@ describe 'Issues', feature: true do
context 'with a filter on labels' do context 'with a filter on labels' do
let(:label) { create(:label, project: project) } let(:label) { create(:label, project: project) }
before { create(:label_link, label: label, target: foo) }
before do
create(:label_link, label: label, target: foo)
end
it 'sorts by least recently due date by excluding nil due dates' do it 'sorts by least recently due date by excluding nil due dates' do
bar.update(due_date: nil) bar.update(due_date: nil)
......
...@@ -202,10 +202,12 @@ feature 'Login', feature: true do ...@@ -202,10 +202,12 @@ feature 'Login', feature: true do
# TODO: otp_grace_period_started_at # TODO: otp_grace_period_started_at
context 'global setting' do context 'global setting' do
before(:each) { stub_application_setting(require_two_factor_authentication: true) } before do
stub_application_setting(require_two_factor_authentication: true)
end
context 'with grace period defined' do context 'with grace period defined' do
before(:each) do before do
stub_application_setting(two_factor_grace_period: 48) stub_application_setting(two_factor_grace_period: 48)
login_with(user) login_with(user)
end end
...@@ -242,7 +244,7 @@ feature 'Login', feature: true do ...@@ -242,7 +244,7 @@ feature 'Login', feature: true do
end end
context 'without grace period defined' do context 'without grace period defined' do
before(:each) do before do
stub_application_setting(two_factor_grace_period: 0) stub_application_setting(two_factor_grace_period: 0)
login_with(user) login_with(user)
end end
...@@ -265,7 +267,7 @@ feature 'Login', feature: true do ...@@ -265,7 +267,7 @@ feature 'Login', feature: true do
end end
context 'with grace period defined' do context 'with grace period defined' do
before(:each) do before do
stub_application_setting(two_factor_grace_period: 48) stub_application_setting(two_factor_grace_period: 48)
login_with(user) login_with(user)
end end
...@@ -306,7 +308,7 @@ feature 'Login', feature: true do ...@@ -306,7 +308,7 @@ feature 'Login', feature: true do
end end
context 'without grace period defined' do context 'without grace period defined' do
before(:each) do before do
stub_application_setting(two_factor_grace_period: 0) stub_application_setting(two_factor_grace_period: 0)
login_with(user) login_with(user)
end end
......
...@@ -85,14 +85,18 @@ feature 'Merge request conflict resolution', js: true, feature: true do ...@@ -85,14 +85,18 @@ feature 'Merge request conflict resolution', js: true, feature: true do
context 'the conflicts are resolvable' do context 'the conflicts are resolvable' do
let(:merge_request) { create_merge_request('conflict-resolvable') } let(:merge_request) { create_merge_request('conflict-resolvable') }
before { visit namespace_project_merge_request_path(project.namespace, project, merge_request) } before do
visit namespace_project_merge_request_path(project.namespace, project, merge_request)
end
it 'shows a link to the conflict resolution page' do it 'shows a link to the conflict resolution page' do
expect(page).to have_link('conflicts', href: /\/conflicts\Z/) expect(page).to have_link('conflicts', href: /\/conflicts\Z/)
end end
context 'in Inline view mode' do context 'in Inline view mode' do
before { click_link('conflicts', href: /\/conflicts\Z/) } before do
click_link('conflicts', href: /\/conflicts\Z/)
end
include_examples "conflicts are resolved in Interactive mode" include_examples "conflicts are resolved in Interactive mode"
include_examples "conflicts are resolved in Edit inline mode" include_examples "conflicts are resolved in Edit inline mode"
......
...@@ -18,7 +18,9 @@ feature 'Merge immediately', :feature, :js do ...@@ -18,7 +18,9 @@ feature 'Merge immediately', :feature, :js do
sha: project.repository.commit('master').id) sha: project.repository.commit('master').id)
end end
before { project.team << [user, :master] } before do
project.team << [user, :master]
end
context 'when there is active pipeline for merge request' do context 'when there is active pipeline for merge request' do
background do background do
......
...@@ -31,8 +31,13 @@ feature 'Profile > Account', feature: true do ...@@ -31,8 +31,13 @@ feature 'Profile > Account', feature: true do
given(:new_project_path) { "/#{new_username}/#{project.path}" } given(:new_project_path) { "/#{new_username}/#{project.path}" }
given(:old_project_path) { "/#{user.username}/#{project.path}" } given(:old_project_path) { "/#{user.username}/#{project.path}" }
before(:context) { TestEnv.clean_test_path } before(:context) do
after(:example) { TestEnv.clean_test_path } TestEnv.clean_test_path
end
after(:example) do
TestEnv.clean_test_path
end
scenario 'the project is accessible via the new path' do scenario 'the project is accessible via the new path' do
update_username(new_username) update_username(new_username)
......
...@@ -47,7 +47,9 @@ describe 'Pipeline', :feature, :js do ...@@ -47,7 +47,9 @@ describe 'Pipeline', :feature, :js do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id, user: user) } let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id, user: user) }
before { visit namespace_project_pipeline_path(project.namespace, project, pipeline) } before do
visit namespace_project_pipeline_path(project.namespace, project, pipeline)
end
it 'shows the pipeline graph' do it 'shows the pipeline graph' do
expect(page).to have_selector('.pipeline-visualization') expect(page).to have_selector('.pipeline-visualization')
...@@ -164,7 +166,9 @@ describe 'Pipeline', :feature, :js do ...@@ -164,7 +166,9 @@ describe 'Pipeline', :feature, :js do
it { expect(page).not_to have_content('retried') } it { expect(page).not_to have_content('retried') }
context 'when retrying' do context 'when retrying' do
before { find('.js-retry-button').trigger('click') } before do
find('.js-retry-button').trigger('click')
end
it { expect(page).not_to have_content('Retry') } it { expect(page).not_to have_content('Retry') }
end end
...@@ -174,7 +178,9 @@ describe 'Pipeline', :feature, :js do ...@@ -174,7 +178,9 @@ describe 'Pipeline', :feature, :js do
it { expect(page).not_to have_selector('.ci-canceled') } it { expect(page).not_to have_selector('.ci-canceled') }
context 'when canceling' do context 'when canceling' do
before { click_on 'Cancel running' } before do
click_on 'Cancel running'
end
it { expect(page).not_to have_content('Cancel running') } it { expect(page).not_to have_content('Cancel running') }
end end
...@@ -226,7 +232,9 @@ describe 'Pipeline', :feature, :js do ...@@ -226,7 +232,9 @@ describe 'Pipeline', :feature, :js do
it { expect(page).not_to have_content('retried') } it { expect(page).not_to have_content('retried') }
context 'when retrying' do context 'when retrying' do
before { find('.js-retry-button').trigger('click') } before do
find('.js-retry-button').trigger('click')
end
it { expect(page).not_to have_content('Retry') } it { expect(page).not_to have_content('Retry') }
end end
...@@ -236,7 +244,9 @@ describe 'Pipeline', :feature, :js do ...@@ -236,7 +244,9 @@ describe 'Pipeline', :feature, :js do
it { expect(page).not_to have_selector('.ci-canceled') } it { expect(page).not_to have_selector('.ci-canceled') }
context 'when canceling' do context 'when canceling' do
before { click_on 'Cancel running' } before do
click_on 'Cancel running'
end
it { expect(page).not_to have_content('Cancel running') } it { expect(page).not_to have_content('Cancel running') }
end end
......
...@@ -149,7 +149,9 @@ describe 'Pipelines', :feature, :js do ...@@ -149,7 +149,9 @@ describe 'Pipelines', :feature, :js do
create(:ci_pipeline, :invalid, project: project) create(:ci_pipeline, :invalid, project: project)
end end
before { visit_project_pipelines } before do
visit_project_pipelines
end
it 'contains badge that indicates errors' do it 'contains badge that indicates errors' do
expect(page).to have_content 'yaml invalid' expect(page).to have_content 'yaml invalid'
...@@ -171,7 +173,9 @@ describe 'Pipelines', :feature, :js do ...@@ -171,7 +173,9 @@ describe 'Pipelines', :feature, :js do
commands: 'test') commands: 'test')
end end
before { visit_project_pipelines } before do
visit_project_pipelines
end
it 'has a dropdown with play button' do it 'has a dropdown with play button' do
expect(page).to have_selector('.dropdown-toggle.btn.btn-default .icon-play') expect(page).to have_selector('.dropdown-toggle.btn.btn-default .icon-play')
...@@ -204,7 +208,9 @@ describe 'Pipelines', :feature, :js do ...@@ -204,7 +208,9 @@ describe 'Pipelines', :feature, :js do
stage: 'test') stage: 'test')
end end
before { visit_project_pipelines } before do
visit_project_pipelines
end
it 'is cancelable' do it 'is cancelable' do
expect(page).to have_selector('.js-pipelines-cancel-button') expect(page).to have_selector('.js-pipelines-cancel-button')
...@@ -215,7 +221,9 @@ describe 'Pipelines', :feature, :js do ...@@ -215,7 +221,9 @@ describe 'Pipelines', :feature, :js do
end end
context 'when canceling' do context 'when canceling' do
before { find('.js-pipelines-cancel-button').trigger('click') } before do
find('.js-pipelines-cancel-button').trigger('click')
end
it 'indicates that pipeline was canceled' do it 'indicates that pipeline was canceled' do
expect(page).not_to have_selector('.js-pipelines-cancel-button') expect(page).not_to have_selector('.js-pipelines-cancel-button')
...@@ -255,7 +263,9 @@ describe 'Pipelines', :feature, :js do ...@@ -255,7 +263,9 @@ describe 'Pipelines', :feature, :js do
stage: 'test') stage: 'test')
end end
before { visit_project_pipelines } before do
visit_project_pipelines
end
it 'has artifats' do it 'has artifats' do
expect(page).to have_selector('.build-artifacts') expect(page).to have_selector('.build-artifacts')
...@@ -284,7 +294,9 @@ describe 'Pipelines', :feature, :js do ...@@ -284,7 +294,9 @@ describe 'Pipelines', :feature, :js do
stage: 'test') stage: 'test')
end end
before { visit_project_pipelines } before do
visit_project_pipelines
end
it { expect(page).not_to have_selector('.build-artifacts') } it { expect(page).not_to have_selector('.build-artifacts') }
end end
...@@ -297,7 +309,9 @@ describe 'Pipelines', :feature, :js do ...@@ -297,7 +309,9 @@ describe 'Pipelines', :feature, :js do
stage: 'test') stage: 'test')
end end
before { visit_project_pipelines } before do
visit_project_pipelines
end
it { expect(page).not_to have_selector('.build-artifacts') } it { expect(page).not_to have_selector('.build-artifacts') }
end end
...@@ -310,7 +324,9 @@ describe 'Pipelines', :feature, :js do ...@@ -310,7 +324,9 @@ describe 'Pipelines', :feature, :js do
name: 'build') name: 'build')
end end
before { visit_project_pipelines } before do
visit_project_pipelines
end
it 'should render a mini pipeline graph' do it 'should render a mini pipeline graph' do
expect(page).to have_selector('.js-mini-pipeline-graph') expect(page).to have_selector('.js-mini-pipeline-graph')
...@@ -437,7 +453,9 @@ describe 'Pipelines', :feature, :js do ...@@ -437,7 +453,9 @@ describe 'Pipelines', :feature, :js do
end end
context 'with gitlab-ci.yml' do context 'with gitlab-ci.yml' do
before { stub_ci_pipeline_to_return_yaml_file } before do
stub_ci_pipeline_to_return_yaml_file
end
it 'creates a new pipeline' do it 'creates a new pipeline' do
expect { click_on 'Create pipeline' } expect { click_on 'Create pipeline' }
...@@ -448,7 +466,9 @@ describe 'Pipelines', :feature, :js do ...@@ -448,7 +466,9 @@ describe 'Pipelines', :feature, :js do
end end
context 'without gitlab-ci.yml' do context 'without gitlab-ci.yml' do
before { click_on 'Create pipeline' } before do
click_on 'Create pipeline'
end
it { expect(page).to have_content('Missing .gitlab-ci.yml file') } it { expect(page).to have_content('Missing .gitlab-ci.yml file') }
end end
......
...@@ -58,8 +58,13 @@ describe 'Edit Project Settings', feature: true do ...@@ -58,8 +58,13 @@ describe 'Edit Project Settings', feature: true do
# Not using empty project because we need a repo to exist # Not using empty project because we need a repo to exist
let(:project) { create(:project, namespace: user.namespace, name: 'gitlabhq') } let(:project) { create(:project, namespace: user.namespace, name: 'gitlabhq') }
before(:context) { TestEnv.clean_test_path } before(:context) do
after(:example) { TestEnv.clean_test_path } TestEnv.clean_test_path
end
after(:example) do
TestEnv.clean_test_path
end
specify 'the project is accessible via the new path' do specify 'the project is accessible via the new path' do
rename_project(project, path: 'bar') rename_project(project, path: 'bar')
...@@ -96,9 +101,17 @@ describe 'Edit Project Settings', feature: true do ...@@ -96,9 +101,17 @@ describe 'Edit Project Settings', feature: true do
let!(:project) { create(:project, namespace: user.namespace, name: 'gitlabhq') } let!(:project) { create(:project, namespace: user.namespace, name: 'gitlabhq') }
let!(:group) { create(:group) } let!(:group) { create(:group) }
before(:context) { TestEnv.clean_test_path } before(:context) do
before(:example) { group.add_owner(user) } TestEnv.clean_test_path
after(:example) { TestEnv.clean_test_path } end
before(:example) do
group.add_owner(user)
end
after(:example) do
TestEnv.clean_test_path
end
specify 'the project is accessible via the new path' do specify 'the project is accessible via the new path' do
transfer_project(project, group) transfer_project(project, group)
......
...@@ -4,7 +4,9 @@ feature 'Protected Branches', feature: true, js: true do ...@@ -4,7 +4,9 @@ feature 'Protected Branches', feature: true, js: true do
let(:user) { create(:user, :admin) } let(:user) { create(:user, :admin) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
before { login_as(user) } before do
login_as(user)
end
def set_protected_branch_name(branch_name) def set_protected_branch_name(branch_name)
find(".js-protected-branch-select").trigger('click') find(".js-protected-branch-select").trigger('click')
......
...@@ -4,7 +4,9 @@ feature 'Projected Tags', feature: true, js: true do ...@@ -4,7 +4,9 @@ feature 'Projected Tags', feature: true, js: true do
let(:user) { create(:user, :admin) } let(:user) { create(:user, :admin) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
before { login_as(user) } before do
login_as(user)
end
def set_protected_tag_name(tag_name) def set_protected_tag_name(tag_name)
find(".js-protected-tag-select").click find(".js-protected-tag-select").click
......
...@@ -4,7 +4,10 @@ describe "Runners" do ...@@ -4,7 +4,10 @@ describe "Runners" do
include GitlabRoutingHelper include GitlabRoutingHelper
let(:user) { create(:user) } let(:user) { create(:user) }
before { login_as(user) }
before do
login_as(user)
end
describe "specific runners" do describe "specific runners" do
before do before do
...@@ -127,7 +130,9 @@ describe "Runners" do ...@@ -127,7 +130,9 @@ describe "Runners" do
end end
context 'when runner has tags' do context 'when runner has tags' do
before { runner.update_attribute(:tag_list, ['tag']) } before do
runner.update_attribute(:tag_list, ['tag'])
end
scenario 'user wants to prevent runner from running untagged job' do scenario 'user wants to prevent runner from running untagged job' do
visit runners_path(project) visit runners_path(project)
......
...@@ -83,7 +83,9 @@ describe "Search", feature: true do ...@@ -83,7 +83,9 @@ describe "Search", feature: true do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:note) { create(:note_on_commit, author: user, project: project, commit_id: project.repository.commit.id, note: 'Bug here') } let(:note) { create(:note_on_commit, author: user, project: project, commit_id: project.repository.commit.id, note: 'Bug here') }
before { note.update_attributes(commit_id: 12345678) } before do
note.update_attributes(commit_id: 12345678)
end
it 'finds comment' do it 'finds comment' do
visit namespace_project_path(project.namespace, project) visit namespace_project_path(project.namespace, project)
......
...@@ -337,7 +337,9 @@ describe "Internal Project Access", feature: true do ...@@ -337,7 +337,9 @@ describe "Internal Project Access", feature: true do
subject { namespace_project_jobs_path(project.namespace, project) } subject { namespace_project_jobs_path(project.namespace, project) }
context "when allowed for public and internal" do context "when allowed for public and internal" do
before { project.update(public_builds: true) } before do
project.update(public_builds: true)
end
it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:admin) }
it { is_expected.to be_allowed_for(:owner).of(project) } it { is_expected.to be_allowed_for(:owner).of(project) }
...@@ -351,7 +353,9 @@ describe "Internal Project Access", feature: true do ...@@ -351,7 +353,9 @@ describe "Internal Project Access", feature: true do
end end
context "when disallowed for public and internal" do context "when disallowed for public and internal" do
before { project.update(public_builds: false) } before do
project.update(public_builds: false)
end
it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:admin) }
it { is_expected.to be_allowed_for(:owner).of(project) } it { is_expected.to be_allowed_for(:owner).of(project) }
...@@ -371,7 +375,9 @@ describe "Internal Project Access", feature: true do ...@@ -371,7 +375,9 @@ describe "Internal Project Access", feature: true do
subject { namespace_project_job_path(project.namespace, project, build.id) } subject { namespace_project_job_path(project.namespace, project, build.id) }
context "when allowed for public and internal" do context "when allowed for public and internal" do
before { project.update(public_builds: true) } before do
project.update(public_builds: true)
end
it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:admin) }
it { is_expected.to be_allowed_for(:owner).of(project) } it { is_expected.to be_allowed_for(:owner).of(project) }
...@@ -385,7 +391,9 @@ describe "Internal Project Access", feature: true do ...@@ -385,7 +391,9 @@ describe "Internal Project Access", feature: true do
end end
context "when disallowed for public and internal" do context "when disallowed for public and internal" do
before { project.update(public_builds: false) } before do
project.update(public_builds: false)
end
it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:admin) }
it { is_expected.to be_allowed_for(:owner).of(project) } it { is_expected.to be_allowed_for(:owner).of(project) }
......
...@@ -157,7 +157,9 @@ describe "Public Project Access", feature: true do ...@@ -157,7 +157,9 @@ describe "Public Project Access", feature: true do
subject { namespace_project_jobs_path(project.namespace, project) } subject { namespace_project_jobs_path(project.namespace, project) }
context "when allowed for public" do context "when allowed for public" do
before { project.update(public_builds: true) } before do
project.update(public_builds: true)
end
it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:admin) }
it { is_expected.to be_allowed_for(:owner).of(project) } it { is_expected.to be_allowed_for(:owner).of(project) }
...@@ -171,7 +173,9 @@ describe "Public Project Access", feature: true do ...@@ -171,7 +173,9 @@ describe "Public Project Access", feature: true do
end end
context "when disallowed for public" do context "when disallowed for public" do
before { project.update(public_builds: false) } before do
project.update(public_builds: false)
end
it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:admin) }
it { is_expected.to be_allowed_for(:owner).of(project) } it { is_expected.to be_allowed_for(:owner).of(project) }
...@@ -191,7 +195,9 @@ describe "Public Project Access", feature: true do ...@@ -191,7 +195,9 @@ describe "Public Project Access", feature: true do
subject { namespace_project_job_path(project.namespace, project, build.id) } subject { namespace_project_job_path(project.namespace, project, build.id) }
context "when allowed for public" do context "when allowed for public" do
before { project.update(public_builds: true) } before do
project.update(public_builds: true)
end
it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:admin) }
it { is_expected.to be_allowed_for(:owner).of(project) } it { is_expected.to be_allowed_for(:owner).of(project) }
...@@ -205,7 +211,9 @@ describe "Public Project Access", feature: true do ...@@ -205,7 +211,9 @@ describe "Public Project Access", feature: true do
end end
context "when disallowed for public" do context "when disallowed for public" do
before { project.update(public_builds: false) } before do
project.update(public_builds: false)
end
it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:admin) }
it { is_expected.to be_allowed_for(:owner).of(project) } it { is_expected.to be_allowed_for(:owner).of(project) }
......
...@@ -3,7 +3,9 @@ require 'spec_helper' ...@@ -3,7 +3,9 @@ require 'spec_helper'
feature 'Signup', feature: true do feature 'Signup', feature: true do
describe 'signup with no errors' do describe 'signup with no errors' do
context "when sending confirmation email" do context "when sending confirmation email" do
before { stub_application_setting(send_user_confirmation_email: true) } before do
stub_application_setting(send_user_confirmation_email: true)
end
it 'creates the user account and sends a confirmation email' do it 'creates the user account and sends a confirmation email' do
user = build(:user) user = build(:user)
...@@ -23,7 +25,9 @@ feature 'Signup', feature: true do ...@@ -23,7 +25,9 @@ feature 'Signup', feature: true do
end end
context "when not sending confirmation email" do context "when not sending confirmation email" do
before { stub_application_setting(send_user_confirmation_email: false) } before do
stub_application_setting(send_user_confirmation_email: false)
end
it 'creates the user account and goes to dashboard' do it 'creates the user account and goes to dashboard' do
user = build(:user) user = build(:user)
......
...@@ -144,7 +144,9 @@ feature 'Task Lists', feature: true do ...@@ -144,7 +144,9 @@ feature 'Task Lists', feature: true do
describe 'nested tasks', js: true do describe 'nested tasks', js: true do
let(:issue) { create(:issue, description: nested_tasks_markdown, author: user, project: project) } let(:issue) { create(:issue, description: nested_tasks_markdown, author: user, project: project) }
before { visit_issue(project, issue) } before do
visit_issue(project, issue)
end
it 'renders' do it 'renders' do
expect(page).to have_selector('ul.task-list', count: 2) expect(page).to have_selector('ul.task-list', count: 2)
......
...@@ -8,7 +8,9 @@ describe "Dashboard > User sorts todos", feature: true do ...@@ -8,7 +8,9 @@ describe "Dashboard > User sorts todos", feature: true do
let(:label_2) { create(:label, title: 'label_2', project: project, priority: 2) } let(:label_2) { create(:label, title: 'label_2', project: project, priority: 2) }
let(:label_3) { create(:label, title: 'label_3', project: project, priority: 3) } let(:label_3) { create(:label, title: 'label_3', project: project, priority: 3) }
before { project.team << [user, :developer] } before do
project.team << [user, :developer]
end
context 'sort options' do context 'sort options' do
let(:issue_1) { create(:issue, title: 'issue_1', project: project) } let(:issue_1) { create(:issue, title: 'issue_1', project: project) }
......
...@@ -5,7 +5,10 @@ feature 'Triggers', feature: true, js: true do ...@@ -5,7 +5,10 @@ feature 'Triggers', feature: true, js: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:guest_user) { create(:user) } let(:guest_user) { create(:user) }
before { login_as(user) }
before do
login_as(user)
end
before do before do
@project = create(:empty_project) @project = create(:empty_project)
......
require 'spec_helper' require 'spec_helper'
feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', :js do feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', :js do
before { allow_any_instance_of(U2fHelper).to receive(:inject_u2f_api?).and_return(true) } before do
allow_any_instance_of(U2fHelper).to receive(:inject_u2f_api?).and_return(true)
end
def manage_two_factor_authentication def manage_two_factor_authentication
click_on 'Manage two-factor authentication' click_on 'Manage two-factor authentication'
...@@ -28,7 +30,9 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', :js do ...@@ -28,7 +30,9 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', :js do
end end
describe 'when 2FA via OTP is disabled' do describe 'when 2FA via OTP is disabled' do
before { user.update_attribute(:otp_required_for_login, false) } before do
user.update_attribute(:otp_required_for_login, false)
end
it 'does not allow registering a new device' do it 'does not allow registering a new device' do
visit profile_account_path visit profile_account_path
......
...@@ -56,7 +56,9 @@ describe 'Unsubscribe links', feature: true do ...@@ -56,7 +56,9 @@ describe 'Unsubscribe links', feature: true do
end end
context 'when logged in' do context 'when logged in' do
before { login_as(recipient) } before do
login_as(recipient)
end
it 'unsubscribes from the issue when visiting the link from the email body' do it 'unsubscribes from the issue when visiting the link from the email body' do
visit body_link visit body_link
......
...@@ -45,7 +45,9 @@ feature 'Users', feature: true, js: true do ...@@ -45,7 +45,9 @@ feature 'Users', feature: true, js: true do
end end
describe 'redirect alias routes' do describe 'redirect alias routes' do
before { user } before do
expect(user).to be_persisted
end
scenario '/u/user1 redirects to user page' do scenario '/u/user1 redirects to user page' do
visit '/u/user1' visit '/u/user1'
......
...@@ -148,7 +148,9 @@ describe IssuesFinder do ...@@ -148,7 +148,9 @@ describe IssuesFinder do
let(:params) { { label_name: [label.title, label2.title].join(',') } } let(:params) { { label_name: [label.title, label2.title].join(',') } }
let(:label2) { create(:label, project: project2) } let(:label2) { create(:label, project: project2) }
before { create(:label_link, label: label2, target: issue2) } before do
create(:label_link, label: label2, target: issue2)
end
it 'returns the unique issues with any of those labels' do it 'returns the unique issues with any of those labels' do
expect(issues).to contain_exactly(issue2) expect(issues).to contain_exactly(issue2)
......
...@@ -25,49 +25,65 @@ describe PersonalAccessTokensFinder do ...@@ -25,49 +25,65 @@ describe PersonalAccessTokensFinder do
end end
describe 'without impersonation' do describe 'without impersonation' do
before { params[:impersonation] = false } before do
params[:impersonation] = false
end
it { is_expected.to contain_exactly(active_personal_access_token, revoked_personal_access_token, expired_personal_access_token) } it { is_expected.to contain_exactly(active_personal_access_token, revoked_personal_access_token, expired_personal_access_token) }
describe 'with active state' do describe 'with active state' do
before { params[:state] = 'active' } before do
params[:state] = 'active'
end
it { is_expected.to contain_exactly(active_personal_access_token) } it { is_expected.to contain_exactly(active_personal_access_token) }
end end
describe 'with inactive state' do describe 'with inactive state' do
before { params[:state] = 'inactive' } before do
params[:state] = 'inactive'
end
it { is_expected.to contain_exactly(revoked_personal_access_token, expired_personal_access_token) } it { is_expected.to contain_exactly(revoked_personal_access_token, expired_personal_access_token) }
end end
end end
describe 'with impersonation' do describe 'with impersonation' do
before { params[:impersonation] = true } before do
params[:impersonation] = true
end
it { is_expected.to contain_exactly(active_impersonation_token, revoked_impersonation_token, expired_impersonation_token) } it { is_expected.to contain_exactly(active_impersonation_token, revoked_impersonation_token, expired_impersonation_token) }
describe 'with active state' do describe 'with active state' do
before { params[:state] = 'active' } before do
params[:state] = 'active'
end
it { is_expected.to contain_exactly(active_impersonation_token) } it { is_expected.to contain_exactly(active_impersonation_token) }
end end
describe 'with inactive state' do describe 'with inactive state' do
before { params[:state] = 'inactive' } before do
params[:state] = 'inactive'
end
it { is_expected.to contain_exactly(revoked_impersonation_token, expired_impersonation_token) } it { is_expected.to contain_exactly(revoked_impersonation_token, expired_impersonation_token) }
end end
end end
describe 'with active state' do describe 'with active state' do
before { params[:state] = 'active' } before do
params[:state] = 'active'
end
it { is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token) } it { is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token) }
end end
describe 'with inactive state' do describe 'with inactive state' do
before { params[:state] = 'inactive' } before do
params[:state] = 'inactive'
end
it do it do
is_expected.to contain_exactly(expired_personal_access_token, revoked_personal_access_token, is_expected.to contain_exactly(expired_personal_access_token, revoked_personal_access_token,
...@@ -81,7 +97,9 @@ describe PersonalAccessTokensFinder do ...@@ -81,7 +97,9 @@ describe PersonalAccessTokensFinder do
it { is_expected.to eq(active_personal_access_token) } it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do describe 'with impersonation' do
before { params[:impersonation] = true } before do
params[:impersonation] = true
end
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
...@@ -93,7 +111,9 @@ describe PersonalAccessTokensFinder do ...@@ -93,7 +111,9 @@ describe PersonalAccessTokensFinder do
it { is_expected.to eq(active_personal_access_token) } it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do describe 'with impersonation' do
before { params[:impersonation] = true } before do
params[:impersonation] = true
end
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
...@@ -109,7 +129,9 @@ describe PersonalAccessTokensFinder do ...@@ -109,7 +129,9 @@ describe PersonalAccessTokensFinder do
let!(:other_user_expired_impersonation_token) { create(:personal_access_token, :expired, :impersonation, user: user2) } let!(:other_user_expired_impersonation_token) { create(:personal_access_token, :expired, :impersonation, user: user2) }
let!(:other_user_revoked_impersonation_token) { create(:personal_access_token, :revoked, :impersonation, user: user2) } let!(:other_user_revoked_impersonation_token) { create(:personal_access_token, :revoked, :impersonation, user: user2) }
before { params[:user] = user } before do
params[:user] = user
end
it do it do
is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token, is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token,
...@@ -118,49 +140,65 @@ describe PersonalAccessTokensFinder do ...@@ -118,49 +140,65 @@ describe PersonalAccessTokensFinder do
end end
describe 'without impersonation' do describe 'without impersonation' do
before { params[:impersonation] = false } before do
params[:impersonation] = false
end
it { is_expected.to contain_exactly(active_personal_access_token, revoked_personal_access_token, expired_personal_access_token) } it { is_expected.to contain_exactly(active_personal_access_token, revoked_personal_access_token, expired_personal_access_token) }
describe 'with active state' do describe 'with active state' do
before { params[:state] = 'active' } before do
params[:state] = 'active'
end
it { is_expected.to contain_exactly(active_personal_access_token) } it { is_expected.to contain_exactly(active_personal_access_token) }
end end
describe 'with inactive state' do describe 'with inactive state' do
before { params[:state] = 'inactive' } before do
params[:state] = 'inactive'
end
it { is_expected.to contain_exactly(revoked_personal_access_token, expired_personal_access_token) } it { is_expected.to contain_exactly(revoked_personal_access_token, expired_personal_access_token) }
end end
end end
describe 'with impersonation' do describe 'with impersonation' do
before { params[:impersonation] = true } before do
params[:impersonation] = true
end
it { is_expected.to contain_exactly(active_impersonation_token, revoked_impersonation_token, expired_impersonation_token) } it { is_expected.to contain_exactly(active_impersonation_token, revoked_impersonation_token, expired_impersonation_token) }
describe 'with active state' do describe 'with active state' do
before { params[:state] = 'active' } before do
params[:state] = 'active'
end
it { is_expected.to contain_exactly(active_impersonation_token) } it { is_expected.to contain_exactly(active_impersonation_token) }
end end
describe 'with inactive state' do describe 'with inactive state' do
before { params[:state] = 'inactive' } before do
params[:state] = 'inactive'
end
it { is_expected.to contain_exactly(revoked_impersonation_token, expired_impersonation_token) } it { is_expected.to contain_exactly(revoked_impersonation_token, expired_impersonation_token) }
end end
end end
describe 'with active state' do describe 'with active state' do
before { params[:state] = 'active' } before do
params[:state] = 'active'
end
it { is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token) } it { is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token) }
end end
describe 'with inactive state' do describe 'with inactive state' do
before { params[:state] = 'inactive' } before do
params[:state] = 'inactive'
end
it do it do
is_expected.to contain_exactly(expired_personal_access_token, revoked_personal_access_token, is_expected.to contain_exactly(expired_personal_access_token, revoked_personal_access_token,
...@@ -174,7 +212,9 @@ describe PersonalAccessTokensFinder do ...@@ -174,7 +212,9 @@ describe PersonalAccessTokensFinder do
it { is_expected.to eq(active_personal_access_token) } it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do describe 'with impersonation' do
before { params[:impersonation] = true } before do
params[:impersonation] = true
end
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
...@@ -186,7 +226,9 @@ describe PersonalAccessTokensFinder do ...@@ -186,7 +226,9 @@ describe PersonalAccessTokensFinder do
it { is_expected.to eq(active_personal_access_token) } it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do describe 'with impersonation' do
before { params[:impersonation] = true } before do
params[:impersonation] = true
end
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
......
...@@ -32,7 +32,9 @@ describe PersonalProjectsFinder do ...@@ -32,7 +32,9 @@ describe PersonalProjectsFinder do
end end
context 'external' do context 'external' do
before { current_user.update_attributes(external: true) } before do
current_user.update_attributes(external: true)
end
it { is_expected.to eq([private_project, public_project]) } it { is_expected.to eq([private_project, public_project]) }
end end
......
...@@ -6,7 +6,9 @@ describe TodosFinder do ...@@ -6,7 +6,9 @@ describe TodosFinder do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:finder) { described_class } let(:finder) { described_class }
before { project.team << [user, :developer] } before do
project.team << [user, :developer]
end
describe '#sort' do describe '#sort' do
context 'by date' do context 'by date' do
......
...@@ -261,7 +261,10 @@ describe ApplicationHelper do ...@@ -261,7 +261,10 @@ describe ApplicationHelper do
describe '#support_url' do describe '#support_url' do
context 'when alternate support url is specified' do context 'when alternate support url is specified' do
let(:alternate_url) { 'http://company.example.com/getting-help' } let(:alternate_url) { 'http://company.example.com/getting-help' }
before { allow(current_application_settings).to receive(:help_page_support_url) { alternate_url } }
before do
allow(current_application_settings).to receive(:help_page_support_url) { alternate_url }
end
it 'returns the alternate support url' do it 'returns the alternate support url' do
expect(helper.support_url).to eq(alternate_url) expect(helper.support_url).to eq(alternate_url)
......
...@@ -250,7 +250,9 @@ describe ProjectsHelper do ...@@ -250,7 +250,9 @@ describe ProjectsHelper do
end end
context "when project is private" do context "when project is private" do
before { project.update_attributes(visibility_level: Gitlab::VisibilityLevel::PRIVATE) } before do
project.update_attributes(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
end
it "shows only allowed options" do it "shows only allowed options" do
helper.instance_variable_set(:@project, project) helper.instance_variable_set(:@project, project)
......
...@@ -82,7 +82,9 @@ describe Banzai::Filter::ExternalIssueReferenceFilter, lib: true do ...@@ -82,7 +82,9 @@ describe Banzai::Filter::ExternalIssueReferenceFilter, lib: true do
context 'with RequestStore enabled' do context 'with RequestStore enabled' do
let(:reference_filter) { HTML::Pipeline.new([described_class]) } let(:reference_filter) { HTML::Pipeline.new([described_class]) }
before { allow(RequestStore).to receive(:active?).and_return(true) } before do
allow(RequestStore).to receive(:active?).and_return(true)
end
it 'queries the collection on the first call' do it 'queries the collection on the first call' do
expect_any_instance_of(Project).to receive(:default_issues_tracker?).once.and_call_original expect_any_instance_of(Project).to receive(:default_issues_tracker?).once.and_call_original
......
...@@ -39,7 +39,9 @@ describe Banzai::Filter::RedactorFilter, lib: true do ...@@ -39,7 +39,9 @@ describe Banzai::Filter::RedactorFilter, lib: true do
end end
context 'valid projects' do context 'valid projects' do
before { allow_any_instance_of(Banzai::ReferenceParser::BaseParser).to receive(:can_read_reference?).and_return(true) } before do
allow_any_instance_of(Banzai::ReferenceParser::BaseParser).to receive(:can_read_reference?).and_return(true)
end
it 'allows permitted Project references' do it 'allows permitted Project references' do
user = create(:user) user = create(:user)
...@@ -54,7 +56,9 @@ describe Banzai::Filter::RedactorFilter, lib: true do ...@@ -54,7 +56,9 @@ describe Banzai::Filter::RedactorFilter, lib: true do
end end
context 'invalid projects' do context 'invalid projects' do
before { allow_any_instance_of(Banzai::ReferenceParser::BaseParser).to receive(:can_read_reference?).and_return(false) } before do
allow_any_instance_of(Banzai::ReferenceParser::BaseParser).to receive(:can_read_reference?).and_return(false)
end
it 'removes unpermitted references' do it 'removes unpermitted references' do
user = create(:user) user = create(:user)
......
...@@ -10,7 +10,9 @@ describe Banzai::ReferenceParser::CommitParser, lib: true do ...@@ -10,7 +10,9 @@ describe Banzai::ReferenceParser::CommitParser, lib: true do
describe '#nodes_visible_to_user' do describe '#nodes_visible_to_user' do
context 'when the link has a data-issue attribute' do context 'when the link has a data-issue attribute' do
before { link['data-commit'] = 123 } before do
link['data-commit'] = 123
end
it_behaves_like "referenced feature visibility", "repository" it_behaves_like "referenced feature visibility", "repository"
end end
......
...@@ -10,7 +10,9 @@ describe Banzai::ReferenceParser::CommitRangeParser, lib: true do ...@@ -10,7 +10,9 @@ describe Banzai::ReferenceParser::CommitRangeParser, lib: true do
describe '#nodes_visible_to_user' do describe '#nodes_visible_to_user' do
context 'when the link has a data-issue attribute' do context 'when the link has a data-issue attribute' do
before { link['data-commit-range'] = '123..456' } before do
link['data-commit-range'] = '123..456'
end
it_behaves_like "referenced feature visibility", "repository" it_behaves_like "referenced feature visibility", "repository"
end end
......
...@@ -10,7 +10,9 @@ describe Banzai::ReferenceParser::ExternalIssueParser, lib: true do ...@@ -10,7 +10,9 @@ describe Banzai::ReferenceParser::ExternalIssueParser, lib: true do
describe '#nodes_visible_to_user' do describe '#nodes_visible_to_user' do
context 'when the link has a data-issue attribute' do context 'when the link has a data-issue attribute' do
before { link['data-external-issue'] = 123 } before do
link['data-external-issue'] = 123
end
levels = [ProjectFeature::DISABLED, ProjectFeature::PRIVATE, ProjectFeature::ENABLED] levels = [ProjectFeature::DISABLED, ProjectFeature::PRIVATE, ProjectFeature::ENABLED]
......
...@@ -11,7 +11,9 @@ describe Banzai::ReferenceParser::LabelParser, lib: true do ...@@ -11,7 +11,9 @@ describe Banzai::ReferenceParser::LabelParser, lib: true do
describe '#nodes_visible_to_user' do describe '#nodes_visible_to_user' do
context 'when the link has a data-issue attribute' do context 'when the link has a data-issue attribute' do
before { link['data-label'] = label.id.to_s } before do
link['data-label'] = label.id.to_s
end
it_behaves_like "referenced feature visibility", "issues", "merge_requests" it_behaves_like "referenced feature visibility", "issues", "merge_requests"
end end
......
...@@ -11,7 +11,9 @@ describe Banzai::ReferenceParser::MilestoneParser, lib: true do ...@@ -11,7 +11,9 @@ describe Banzai::ReferenceParser::MilestoneParser, lib: true do
describe '#nodes_visible_to_user' do describe '#nodes_visible_to_user' do
context 'when the link has a data-issue attribute' do context 'when the link has a data-issue attribute' do
before { link['data-milestone'] = milestone.id.to_s } before do
link['data-milestone'] = milestone.id.to_s
end
it_behaves_like "referenced feature visibility", "issues", "merge_requests" it_behaves_like "referenced feature visibility", "issues", "merge_requests"
end end
......
...@@ -77,7 +77,10 @@ describe ExtractsPath, lib: true do ...@@ -77,7 +77,10 @@ describe ExtractsPath, lib: true do
context 'without a path' do context 'without a path' do
let(:params) { { ref: 'v1.0.0.atom' } } let(:params) { { ref: 'v1.0.0.atom' } }
before { assign_ref_vars }
before do
assign_ref_vars
end
it 'sets the un-suffixed version as @ref' do it 'sets the un-suffixed version as @ref' do
expect(@ref).to eq('v1.0.0') expect(@ref).to eq('v1.0.0')
......
...@@ -40,7 +40,9 @@ describe Gitlab::Auth::UniqueIpsLimiter, :redis, lib: true do ...@@ -40,7 +40,9 @@ describe Gitlab::Auth::UniqueIpsLimiter, :redis, lib: true do
end end
context 'allow 2 unique ips' do context 'allow 2 unique ips' do
before { current_application_settings.update!(unique_ips_limit_per_user: 2) } before do
current_application_settings.update!(unique_ips_limit_per_user: 2)
end
it 'blocks user trying to login from third ip' do it 'blocks user trying to login from third ip' do
change_ip('ip1') change_ip('ip1')
......
...@@ -29,7 +29,9 @@ describe Gitlab::Badge::Build::Status do ...@@ -29,7 +29,9 @@ describe Gitlab::Badge::Build::Status do
let!(:build) { create_build(project, sha, branch) } let!(:build) { create_build(project, sha, branch) }
context 'build success' do context 'build success' do
before { build.success! } before do
build.success!
end
describe '#status' do describe '#status' do
it 'is successful' do it 'is successful' do
...@@ -39,7 +41,9 @@ describe Gitlab::Badge::Build::Status do ...@@ -39,7 +41,9 @@ describe Gitlab::Badge::Build::Status do
end end
context 'build failed' do context 'build failed' do
before { build.drop! } before do
build.drop!
end
describe '#status' do describe '#status' do
it 'failed' do it 'failed' do
......
...@@ -4,7 +4,9 @@ describe Gitlab::ChatCommands::Presenters::IssueSearch do ...@@ -4,7 +4,9 @@ describe Gitlab::ChatCommands::Presenters::IssueSearch do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:message) { subject[:text] } let(:message) { subject[:text] }
before { create_list(:issue, 2, project: project) } before do
create_list(:issue, 2, project: project)
end
subject { described_class.new(project.issues).present } subject { described_class.new(project.issues).present }
......
...@@ -20,7 +20,9 @@ describe Gitlab::Checks::ChangeAccess, lib: true do ...@@ -20,7 +20,9 @@ describe Gitlab::Checks::ChangeAccess, lib: true do
).exec ).exec
end end
before { project.add_developer(user) } before do
project.add_developer(user)
end
context 'without failed checks' do context 'without failed checks' do
it "doesn't raise an error" do it "doesn't raise an error" do
...@@ -50,7 +52,9 @@ describe Gitlab::Checks::ChangeAccess, lib: true do ...@@ -50,7 +52,9 @@ describe Gitlab::Checks::ChangeAccess, lib: true do
let!(:protected_tag) { create(:protected_tag, project: project, name: 'v*') } let!(:protected_tag) { create(:protected_tag, project: project, name: 'v*') }
context 'as master' do context 'as master' do
before { project.add_master(user) } before do
project.add_master(user)
end
context 'deletion' do context 'deletion' do
let(:oldrev) { 'be93687618e4b132087f430a4d8fc3a609c9b77c' } let(:oldrev) { 'be93687618e4b132087f430a4d8fc3a609c9b77c' }
......
...@@ -4,7 +4,9 @@ describe Gitlab::Ci::Config::Entry::Cache do ...@@ -4,7 +4,9 @@ describe Gitlab::Ci::Config::Entry::Cache do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
before { entry.compose! } before do
entry.compose!
end
context 'when entry config value is correct' do context 'when entry config value is correct' do
let(:config) do let(:config) do
......
...@@ -3,7 +3,9 @@ require 'spec_helper' ...@@ -3,7 +3,9 @@ require 'spec_helper'
describe Gitlab::Ci::Config::Entry::Environment do describe Gitlab::Ci::Config::Entry::Environment do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
before { entry.compose! } before do
entry.compose!
end
context 'when configuration is a string' do context 'when configuration is a string' do
let(:config) { 'production' } let(:config) { 'production' }
......
...@@ -33,7 +33,9 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -33,7 +33,9 @@ describe Gitlab::Ci::Config::Entry::Global do
end end
describe '#compose!' do describe '#compose!' do
before { global.compose! } before do
global.compose!
end
it 'creates nodes hash' do it 'creates nodes hash' do
expect(global.descendants).to be_an Array expect(global.descendants).to be_an Array
...@@ -79,7 +81,9 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -79,7 +81,9 @@ describe Gitlab::Ci::Config::Entry::Global do
end end
context 'when composed' do context 'when composed' do
before { global.compose! } before do
global.compose!
end
describe '#errors' do describe '#errors' do
it 'has no errors' do it 'has no errors' do
...@@ -175,7 +179,9 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -175,7 +179,9 @@ describe Gitlab::Ci::Config::Entry::Global do
end end
context 'when most of entires not defined' do context 'when most of entires not defined' do
before { global.compose! } before do
global.compose!
end
let(:hash) do let(:hash) do
{ cache: { key: 'a' }, rspec: { script: %w[ls] } } { cache: { key: 'a' }, rspec: { script: %w[ls] } }
...@@ -218,7 +224,9 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -218,7 +224,9 @@ describe Gitlab::Ci::Config::Entry::Global do
# details. # details.
# #
context 'when entires specified but not defined' do context 'when entires specified but not defined' do
before { global.compose! } before do
global.compose!
end
let(:hash) do let(:hash) do
{ variables: nil, rspec: { script: 'rspec' } } { variables: nil, rspec: { script: 'rspec' } }
...@@ -233,7 +241,9 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -233,7 +241,9 @@ describe Gitlab::Ci::Config::Entry::Global do
end end
context 'when configuration is not valid' do context 'when configuration is not valid' do
before { global.compose! } before do
global.compose!
end
context 'when before script is not an array' do context 'when before script is not an array' do
let(:hash) do let(:hash) do
...@@ -297,7 +307,9 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -297,7 +307,9 @@ describe Gitlab::Ci::Config::Entry::Global do
end end
describe '#[]' do describe '#[]' do
before { global.compose! } before do
global.compose!
end
let(:hash) do let(:hash) do
{ cache: { key: 'a' }, rspec: { script: 'ls' } } { cache: { key: 'a' }, rspec: { script: 'ls' } }
......
...@@ -18,7 +18,9 @@ describe Gitlab::Ci::Config::Entry::Job do ...@@ -18,7 +18,9 @@ describe Gitlab::Ci::Config::Entry::Job do
end end
describe 'validations' do describe 'validations' do
before { entry.compose! } before do
entry.compose!
end
context 'when entry config value is correct' do context 'when entry config value is correct' do
let(:config) { { script: 'rspec' } } let(:config) { { script: 'rspec' } }
...@@ -97,7 +99,9 @@ describe Gitlab::Ci::Config::Entry::Job do ...@@ -97,7 +99,9 @@ describe Gitlab::Ci::Config::Entry::Job do
let(:deps) { double('deps', '[]' => unspecified) } let(:deps) { double('deps', '[]' => unspecified) }
context 'when job config overrides global config' do context 'when job config overrides global config' do
before { entry.compose!(deps) } before do
entry.compose!(deps)
end
let(:config) do let(:config) do
{ script: 'rspec', image: 'some_image', cache: { key: 'test' } } { script: 'rspec', image: 'some_image', cache: { key: 'test' } }
...@@ -125,10 +129,14 @@ describe Gitlab::Ci::Config::Entry::Job do ...@@ -125,10 +129,14 @@ describe Gitlab::Ci::Config::Entry::Job do
end end
context 'when composed' do context 'when composed' do
before { entry.compose! } before do
entry.compose!
end
describe '#value' do describe '#value' do
before { entry.compose! } before do
entry.compose!
end
context 'when entry is correct' do context 'when entry is correct' do
let(:config) do let(:config) do
......
...@@ -4,7 +4,9 @@ describe Gitlab::Ci::Config::Entry::Jobs do ...@@ -4,7 +4,9 @@ describe Gitlab::Ci::Config::Entry::Jobs do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
before { entry.compose! } before do
entry.compose!
end
context 'when entry config value is correct' do context 'when entry config value is correct' do
let(:config) { { rspec: { script: 'rspec' } } } let(:config) { { rspec: { script: 'rspec' } } }
...@@ -48,7 +50,9 @@ describe Gitlab::Ci::Config::Entry::Jobs do ...@@ -48,7 +50,9 @@ describe Gitlab::Ci::Config::Entry::Jobs do
end end
context 'when valid job entries composed' do context 'when valid job entries composed' do
before { entry.compose! } before do
entry.compose!
end
let(:config) do let(:config) do
{ rspec: { script: 'rspec' }, { rspec: { script: 'rspec' },
......
...@@ -3,7 +3,9 @@ require 'spec_helper' ...@@ -3,7 +3,9 @@ require 'spec_helper'
describe Gitlab::Ci::Config::Entry::Service do describe Gitlab::Ci::Config::Entry::Service do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
before { entry.compose! } before do
entry.compose!
end
context 'when configuration is a string' do context 'when configuration is a string' do
let(:config) { 'postgresql:9.5' } let(:config) { 'postgresql:9.5' }
......
...@@ -3,7 +3,9 @@ require 'spec_helper' ...@@ -3,7 +3,9 @@ require 'spec_helper'
describe Gitlab::Ci::Config::Entry::Services do describe Gitlab::Ci::Config::Entry::Services do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
before { entry.compose! } before do
entry.compose!
end
context 'when configuration is valid' do context 'when configuration is valid' do
let(:config) { ['postgresql:9.5', { name: 'postgresql:9.1', alias: 'postgres_old' }] } let(:config) { ['postgresql:9.5', { name: 'postgresql:9.1', alias: 'postgres_old' }] }
......
...@@ -47,7 +47,9 @@ describe Gitlab::Ci::Status::Build::Cancelable do ...@@ -47,7 +47,9 @@ describe Gitlab::Ci::Status::Build::Cancelable do
describe '#has_action?' do describe '#has_action?' do
context 'when user is allowed to update build' do context 'when user is allowed to update build' do
before { build.project.team << [user, :developer] } before do
build.project.team << [user, :developer]
end
it { is_expected.to have_action } it { is_expected.to have_action }
end end
......
...@@ -17,13 +17,17 @@ describe Gitlab::Ci::Status::Build::Common do ...@@ -17,13 +17,17 @@ describe Gitlab::Ci::Status::Build::Common do
describe '#has_details?' do describe '#has_details?' do
context 'when user has access to read build' do context 'when user has access to read build' do
before { project.team << [user, :developer] } before do
project.team << [user, :developer]
end
it { is_expected.to have_details } it { is_expected.to have_details }
end end
context 'when user does not have access to read build' do context 'when user does not have access to read build' do
before { project.update(public_builds: false) } before do
project.update(public_builds: false)
end
it { is_expected.not_to have_details } it { is_expected.not_to have_details }
end end
......
...@@ -6,7 +6,9 @@ describe Gitlab::Ci::Status::Build::Factory do ...@@ -6,7 +6,9 @@ describe Gitlab::Ci::Status::Build::Factory do
let(:status) { factory.fabricate! } let(:status) { factory.fabricate! }
let(:factory) { described_class.new(build, user) } let(:factory) { described_class.new(build, user) }
before { project.team << [user, :developer] } before do
project.team << [user, :developer]
end
context 'when build is successful' do context 'when build is successful' do
let(:build) { create(:ci_build, :success) } let(:build) { create(:ci_build, :success) }
......
...@@ -28,7 +28,9 @@ describe Gitlab::Ci::Status::Build::Play do ...@@ -28,7 +28,9 @@ describe Gitlab::Ci::Status::Build::Play do
end end
context 'when user can not push to the branch' do context 'when user can not push to the branch' do
before { build.project.add_developer(user) } before do
build.project.add_developer(user)
end
it { is_expected.not_to have_action } it { is_expected.not_to have_action }
end end
......
...@@ -47,7 +47,9 @@ describe Gitlab::Ci::Status::Build::Retryable do ...@@ -47,7 +47,9 @@ describe Gitlab::Ci::Status::Build::Retryable do
describe '#has_action?' do describe '#has_action?' do
context 'when user is allowed to update build' do context 'when user is allowed to update build' do
before { build.project.team << [user, :developer] } before do
build.project.team << [user, :developer]
end
it { is_expected.to have_action } it { is_expected.to have_action }
end end
......
...@@ -19,7 +19,9 @@ describe Gitlab::Ci::Status::Build::Stop do ...@@ -19,7 +19,9 @@ describe Gitlab::Ci::Status::Build::Stop do
describe '#has_action?' do describe '#has_action?' do
context 'when user is allowed to update build' do context 'when user is allowed to update build' do
before { build.project.team << [user, :developer] } before do
build.project.team << [user, :developer]
end
it { is_expected.to have_action } it { is_expected.to have_action }
end end
......
...@@ -28,7 +28,9 @@ describe Gitlab::Ci::Status::External::Common do ...@@ -28,7 +28,9 @@ describe Gitlab::Ci::Status::External::Common do
describe '#has_details?' do describe '#has_details?' do
context 'when user has access to read commit status' do context 'when user has access to read commit status' do
before { project.team << [user, :developer] } before do
project.team << [user, :developer]
end
it { is_expected.to have_details } it { is_expected.to have_details }
end end
......
...@@ -17,7 +17,9 @@ describe Gitlab::Ci::Status::Pipeline::Common do ...@@ -17,7 +17,9 @@ describe Gitlab::Ci::Status::Pipeline::Common do
describe '#has_details?' do describe '#has_details?' do
context 'when user has access to read pipeline' do context 'when user has access to read pipeline' do
before { project.team << [user, :developer] } before do
project.team << [user, :developer]
end
it { is_expected.to have_details } it { is_expected.to have_details }
end end
......
...@@ -53,14 +53,18 @@ describe Gitlab::Database, lib: true do ...@@ -53,14 +53,18 @@ describe Gitlab::Database, lib: true do
describe '.nulls_last_order' do describe '.nulls_last_order' do
context 'when using PostgreSQL' do context 'when using PostgreSQL' do
before { expect(described_class).to receive(:postgresql?).and_return(true) } before do
expect(described_class).to receive(:postgresql?).and_return(true)
end
it { expect(described_class.nulls_last_order('column', 'ASC')).to eq 'column ASC NULLS LAST'} it { expect(described_class.nulls_last_order('column', 'ASC')).to eq 'column ASC NULLS LAST'}
it { expect(described_class.nulls_last_order('column', 'DESC')).to eq 'column DESC NULLS LAST'} it { expect(described_class.nulls_last_order('column', 'DESC')).to eq 'column DESC NULLS LAST'}
end end
context 'when using MySQL' do context 'when using MySQL' do
before { expect(described_class).to receive(:postgresql?).and_return(false) } before do
expect(described_class).to receive(:postgresql?).and_return(false)
end
it { expect(described_class.nulls_last_order('column', 'ASC')).to eq 'column IS NULL, column ASC'} it { expect(described_class.nulls_last_order('column', 'ASC')).to eq 'column IS NULL, column ASC'}
it { expect(described_class.nulls_last_order('column', 'DESC')).to eq 'column DESC'} it { expect(described_class.nulls_last_order('column', 'DESC')).to eq 'column DESC'}
...@@ -69,14 +73,18 @@ describe Gitlab::Database, lib: true do ...@@ -69,14 +73,18 @@ describe Gitlab::Database, lib: true do
describe '.nulls_first_order' do describe '.nulls_first_order' do
context 'when using PostgreSQL' do context 'when using PostgreSQL' do
before { expect(described_class).to receive(:postgresql?).and_return(true) } before do
expect(described_class).to receive(:postgresql?).and_return(true)
end
it { expect(described_class.nulls_first_order('column', 'ASC')).to eq 'column ASC NULLS FIRST'} it { expect(described_class.nulls_first_order('column', 'ASC')).to eq 'column ASC NULLS FIRST'}
it { expect(described_class.nulls_first_order('column', 'DESC')).to eq 'column DESC NULLS FIRST'} it { expect(described_class.nulls_first_order('column', 'DESC')).to eq 'column DESC NULLS FIRST'}
end end
context 'when using MySQL' do context 'when using MySQL' do
before { expect(described_class).to receive(:postgresql?).and_return(false) } before do
expect(described_class).to receive(:postgresql?).and_return(false)
end
it { expect(described_class.nulls_first_order('column', 'ASC')).to eq 'column ASC'} it { expect(described_class.nulls_first_order('column', 'ASC')).to eq 'column ASC'}
it { expect(described_class.nulls_first_order('column', 'DESC')).to eq 'column IS NULL, column DESC'} it { expect(described_class.nulls_first_order('column', 'DESC')).to eq 'column IS NULL, column DESC'}
......
...@@ -6,7 +6,9 @@ describe Gitlab::Gfm::ReferenceRewriter do ...@@ -6,7 +6,9 @@ describe Gitlab::Gfm::ReferenceRewriter do
let(:new_project) { create(:empty_project, name: 'new-project') } let(:new_project) { create(:empty_project, name: 'new-project') }
let(:user) { create(:user) } let(:user) { create(:user) }
before { old_project.team << [user, :reporter] } before do
old_project.team << [user, :reporter]
end
describe '#rewrite' do describe '#rewrite' do
subject do subject do
......
...@@ -16,7 +16,9 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -16,7 +16,9 @@ describe Gitlab::Git::Repository, seed_helper: true do
describe '#root_ref' do describe '#root_ref' do
context 'with gitaly disabled' do context 'with gitaly disabled' do
before { allow(Gitlab::GitalyClient).to receive(:feature_enabled?).and_return(false) } before do
allow(Gitlab::GitalyClient).to receive(:feature_enabled?).and_return(false)
end
it 'calls #discover_default_branch' do it 'calls #discover_default_branch' do
expect(repository).to receive(:discover_default_branch) expect(repository).to receive(:discover_default_branch)
...@@ -25,8 +27,13 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -25,8 +27,13 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
context 'with gitaly enabled' do context 'with gitaly enabled' do
before { stub_gitaly } before do
after { Gitlab::GitalyClient.clear_stubs! } stub_gitaly
end
after do
Gitlab::GitalyClient.clear_stubs!
end
it 'gets the branch name from GitalyClient' do it 'gets the branch name from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name)
...@@ -120,8 +127,13 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -120,8 +127,13 @@ describe Gitlab::Git::Repository, seed_helper: true do
it { is_expected.not_to include("branch-from-space") } it { is_expected.not_to include("branch-from-space") }
context 'with gitaly enabled' do context 'with gitaly enabled' do
before { stub_gitaly } before do
after { Gitlab::GitalyClient.clear_stubs! } stub_gitaly
end
after do
Gitlab::GitalyClient.clear_stubs!
end
it 'gets the branch names from GitalyClient' do it 'gets the branch names from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names)
...@@ -158,8 +170,13 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -158,8 +170,13 @@ describe Gitlab::Git::Repository, seed_helper: true do
it { is_expected.not_to include("v5.0.0") } it { is_expected.not_to include("v5.0.0") }
context 'with gitaly enabled' do context 'with gitaly enabled' do
before { stub_gitaly } before do
after { Gitlab::GitalyClient.clear_stubs! } stub_gitaly
end
after do
Gitlab::GitalyClient.clear_stubs!
end
it 'gets the tag names from GitalyClient' do it 'gets the tag names from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names)
...@@ -1280,8 +1297,13 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1280,8 +1297,13 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
context 'with gitaly enabled' do context 'with gitaly enabled' do
before { stub_gitaly } before do
after { Gitlab::GitalyClient.clear_stubs! } stub_gitaly
end
after do
Gitlab::GitalyClient.clear_stubs!
end
it 'gets the branches from GitalyClient' do it 'gets the branches from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches). expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches).
......
...@@ -60,7 +60,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -60,7 +60,9 @@ describe Gitlab::GitAccess, lib: true do
let(:actor) { deploy_key } let(:actor) { deploy_key }
context 'when the DeployKey has access to the project' do context 'when the DeployKey has access to the project' do
before { deploy_key.projects << project } before do
deploy_key.projects << project
end
it 'allows pull access' do it 'allows pull access' do
expect { pull_access_check }.not_to raise_error expect { pull_access_check }.not_to raise_error
...@@ -84,7 +86,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -84,7 +86,9 @@ describe Gitlab::GitAccess, lib: true do
context 'when actor is a User' do context 'when actor is a User' do
context 'when the User can read the project' do context 'when the User can read the project' do
before { project.team << [user, :master] } before do
project.team << [user, :master]
end
it 'allows pull access' do it 'allows pull access' do
expect { pull_access_check }.not_to raise_error expect { pull_access_check }.not_to raise_error
...@@ -159,7 +163,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -159,7 +163,9 @@ describe Gitlab::GitAccess, lib: true do
end end
describe '#check_command_disabled!' do describe '#check_command_disabled!' do
before { project.team << [user, :master] } before do
project.team << [user, :master]
end
context 'over http' do context 'over http' do
let(:protocol) { 'http' } let(:protocol) { 'http' }
...@@ -196,7 +202,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -196,7 +202,9 @@ describe Gitlab::GitAccess, lib: true do
describe '#check_download_access!' do describe '#check_download_access!' do
describe 'master permissions' do describe 'master permissions' do
before { project.team << [user, :master] } before do
project.team << [user, :master]
end
context 'pull code' do context 'pull code' do
it { expect { pull_access_check }.not_to raise_error } it { expect { pull_access_check }.not_to raise_error }
...@@ -204,7 +212,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -204,7 +212,9 @@ describe Gitlab::GitAccess, lib: true do
end end
describe 'guest permissions' do describe 'guest permissions' do
before { project.team << [user, :guest] } before do
project.team << [user, :guest]
end
context 'pull code' do context 'pull code' do
it { expect { pull_access_check }.to raise_unauthorized('You are not allowed to download code from this project.') } it { expect { pull_access_check }.to raise_unauthorized('You are not allowed to download code from this project.') }
...@@ -253,7 +263,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -253,7 +263,9 @@ describe Gitlab::GitAccess, lib: true do
context 'pull code' do context 'pull code' do
context 'when project is authorized' do context 'when project is authorized' do
before { key.projects << project } before do
key.projects << project
end
it { expect { pull_access_check }.not_to raise_error } it { expect { pull_access_check }.not_to raise_error }
end end
...@@ -292,7 +304,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -292,7 +304,9 @@ describe Gitlab::GitAccess, lib: true do
end end
describe 'reporter user' do describe 'reporter user' do
before { project.team << [user, :reporter] } before do
project.team << [user, :reporter]
end
context 'pull code' do context 'pull code' do
it { expect { pull_access_check }.not_to raise_error } it { expect { pull_access_check }.not_to raise_error }
...@@ -303,7 +317,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -303,7 +317,9 @@ describe Gitlab::GitAccess, lib: true do
let(:user) { create(:admin) } let(:user) { create(:admin) }
context 'when member of the project' do context 'when member of the project' do
before { project.team << [user, :reporter] } before do
project.team << [user, :reporter]
end
context 'pull code' do context 'pull code' do
it { expect { pull_access_check }.not_to raise_error } it { expect { pull_access_check }.not_to raise_error }
...@@ -328,7 +344,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -328,7 +344,9 @@ describe Gitlab::GitAccess, lib: true do
end end
describe '#check_push_access!' do describe '#check_push_access!' do
before { merge_into_protected_branch } before do
merge_into_protected_branch
end
let(:unprotected_branch) { 'unprotected_branch' } let(:unprotected_branch) { 'unprotected_branch' }
let(:changes) do let(:changes) do
...@@ -457,19 +475,25 @@ describe Gitlab::GitAccess, lib: true do ...@@ -457,19 +475,25 @@ describe Gitlab::GitAccess, lib: true do
[%w(feature exact), ['feat*', 'wildcard']].each do |protected_branch_name, protected_branch_type| [%w(feature exact), ['feat*', 'wildcard']].each do |protected_branch_name, protected_branch_type|
context do context do
before { create(:protected_branch, name: protected_branch_name, project: project) } before do
create(:protected_branch, name: protected_branch_name, project: project)
end
run_permission_checks(permissions_matrix) run_permission_checks(permissions_matrix)
end end
context "when developers are allowed to push into the #{protected_branch_type} protected branch" do context "when developers are allowed to push into the #{protected_branch_type} protected branch" do
before { create(:protected_branch, :developers_can_push, name: protected_branch_name, project: project) } before do
create(:protected_branch, :developers_can_push, name: protected_branch_name, project: project)
end
run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: true, push_all: true, merge_into_protected_branch: true })) run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: true, push_all: true, merge_into_protected_branch: true }))
end end
context "developers are allowed to merge into the #{protected_branch_type} protected branch" do context "developers are allowed to merge into the #{protected_branch_type} protected branch" do
before { create(:protected_branch, :developers_can_merge, name: protected_branch_name, project: project) } before do
create(:protected_branch, :developers_can_merge, name: protected_branch_name, project: project)
end
context "when a merge request exists for the given source/target branch" do context "when a merge request exists for the given source/target branch" do
context "when the merge request is in progress" do context "when the merge request is in progress" do
...@@ -496,13 +520,17 @@ describe Gitlab::GitAccess, lib: true do ...@@ -496,13 +520,17 @@ describe Gitlab::GitAccess, lib: true do
end end
context "when developers are allowed to push and merge into the #{protected_branch_type} protected branch" do context "when developers are allowed to push and merge into the #{protected_branch_type} protected branch" do
before { create(:protected_branch, :developers_can_merge, :developers_can_push, name: protected_branch_name, project: project) } before do
create(:protected_branch, :developers_can_merge, :developers_can_push, name: protected_branch_name, project: project)
end
run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: true, push_all: true, merge_into_protected_branch: true })) run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: true, push_all: true, merge_into_protected_branch: true }))
end end
context "when no one is allowed to push to the #{protected_branch_name} protected branch" do context "when no one is allowed to push to the #{protected_branch_name} protected branch" do
before { create(:protected_branch, :no_one_can_push, name: protected_branch_name, project: project) } before do
create(:protected_branch, :no_one_can_push, name: protected_branch_name, project: project)
end
run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false }, run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false },
master: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false }, master: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false },
...@@ -515,7 +543,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -515,7 +543,9 @@ describe Gitlab::GitAccess, lib: true do
let(:authentication_abilities) { build_authentication_abilities } let(:authentication_abilities) { build_authentication_abilities }
context 'when project is authorized' do context 'when project is authorized' do
before { project.team << [user, :reporter] } before do
project.team << [user, :reporter]
end
it { expect { push_access_check }.to raise_unauthorized('You are not allowed to upload code for this project.') } it { expect { push_access_check }.to raise_unauthorized('You are not allowed to upload code for this project.') }
end end
...@@ -549,7 +579,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -549,7 +579,9 @@ describe Gitlab::GitAccess, lib: true do
let(:can_push) { true } let(:can_push) { true }
context 'when project is authorized' do context 'when project is authorized' do
before { key.projects << project } before do
key.projects << project
end
it { expect { push_access_check }.not_to raise_error } it { expect { push_access_check }.not_to raise_error }
end end
...@@ -579,7 +611,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -579,7 +611,9 @@ describe Gitlab::GitAccess, lib: true do
let(:can_push) { false } let(:can_push) { false }
context 'when project is authorized' do context 'when project is authorized' do
before { key.projects << project } before do
key.projects << project
end
it { expect { push_access_check }.to raise_unauthorized('This deploy key does not have write access to this project.') } it { expect { push_access_check }.to raise_unauthorized('This deploy key does not have write access to this project.') }
end end
......
...@@ -5,7 +5,9 @@ require 'spec_helper' ...@@ -5,7 +5,9 @@ require 'spec_helper'
describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do
describe '.stub' do describe '.stub' do
# Notice that this is referring to gRPC "stubs", not rspec stubs # Notice that this is referring to gRPC "stubs", not rspec stubs
before { described_class.clear_stubs! } before do
described_class.clear_stubs!
end
context 'when passed a UNIX socket address' do context 'when passed a UNIX socket address' do
it 'passes the address as-is to GRPC' do it 'passes the address as-is to GRPC' do
...@@ -41,7 +43,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do ...@@ -41,7 +43,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do
let(:real_feature_name) { "gitaly_#{feature_name}" } let(:real_feature_name) { "gitaly_#{feature_name}" }
context 'when Gitaly is disabled' do context 'when Gitaly is disabled' do
before { allow(described_class).to receive(:enabled?).and_return(false) } before do
allow(described_class).to receive(:enabled?).and_return(false)
end
it 'returns false' do it 'returns false' do
expect(described_class.feature_enabled?(feature_name)).to be(false) expect(described_class.feature_enabled?(feature_name)).to be(false)
...@@ -66,7 +70,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do ...@@ -66,7 +70,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do
end end
context "when the feature flag is set to disable" do context "when the feature flag is set to disable" do
before { Feature.get(real_feature_name).disable } before do
Feature.get(real_feature_name).disable
end
it 'returns false' do it 'returns false' do
expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false) expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false)
...@@ -74,7 +80,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do ...@@ -74,7 +80,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do
end end
context "when the feature flag is set to enable" do context "when the feature flag is set to enable" do
before { Feature.get(real_feature_name).enable } before do
Feature.get(real_feature_name).enable
end
it 'returns true' do it 'returns true' do
expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(true) expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(true)
...@@ -82,7 +90,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do ...@@ -82,7 +90,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do
end end
context "when the feature flag is set to a percentage of time" do context "when the feature flag is set to a percentage of time" do
before { Feature.get(real_feature_name).enable_percentage_of_time(70) } before do
Feature.get(real_feature_name).enable_percentage_of_time(70)
end
it 'bases the result on pseudo-random numbers' do it 'bases the result on pseudo-random numbers' do
expect(Random).to receive(:rand).and_return(0.3) expect(Random).to receive(:rand).and_return(0.3)
...@@ -104,7 +114,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do ...@@ -104,7 +114,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do
end end
context "when the feature flag is set to disable" do context "when the feature flag is set to disable" do
before { Feature.get(real_feature_name).disable } before do
Feature.get(real_feature_name).disable
end
it 'returns false' do it 'returns false' do
expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false) expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false)
......
...@@ -15,7 +15,9 @@ describe Gitlab::Highlight, lib: true do ...@@ -15,7 +15,9 @@ describe Gitlab::Highlight, lib: true do
Gitlab::Highlight.new(blob.path, blob.data, repository: repository) Gitlab::Highlight.new(blob.path, blob.data, repository: repository)
end end
before { project.change_head('gitattributes') } before do
project.change_head('gitattributes')
end
describe 'basic language selection' do describe 'basic language selection' do
let(:path) { 'custom-highlighting/test.gitlab-custom' } let(:path) { 'custom-highlighting/test.gitlab-custom' }
......
...@@ -4,7 +4,9 @@ describe Gitlab::I18n, lib: true do ...@@ -4,7 +4,9 @@ describe Gitlab::I18n, lib: true do
let(:user) { create(:user, preferred_language: 'es') } let(:user) { create(:user, preferred_language: 'es') }
describe '.locale=' do describe '.locale=' do
after { described_class.use_default_locale } after do
described_class.use_default_locale
end
it 'sets the locale based on current user preferred language' do it 'sets the locale based on current user preferred language' do
described_class.locale = user.preferred_language described_class.locale = user.preferred_language
......
...@@ -74,13 +74,17 @@ describe Gitlab::LDAP::Adapter, lib: true do ...@@ -74,13 +74,17 @@ describe Gitlab::LDAP::Adapter, lib: true do
subject { adapter.dn_matches_filter?(:dn, :filter) } subject { adapter.dn_matches_filter?(:dn, :filter) }
context "when the search result is non-empty" do context "when the search result is non-empty" do
before { allow(adapter).to receive(:ldap_search).and_return([:foo]) } before do
allow(adapter).to receive(:ldap_search).and_return([:foo])
end
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
context "when the search result is empty" do context "when the search result is empty" do
before { allow(adapter).to receive(:ldap_search).and_return([]) } before do
allow(adapter).to receive(:ldap_search).and_return([])
end
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
...@@ -91,13 +95,17 @@ describe Gitlab::LDAP::Adapter, lib: true do ...@@ -91,13 +95,17 @@ describe Gitlab::LDAP::Adapter, lib: true do
context "when the search is successful" do context "when the search is successful" do
context "and the result is non-empty" do context "and the result is non-empty" do
before { allow(ldap).to receive(:search).and_return([:foo]) } before do
allow(ldap).to receive(:search).and_return([:foo])
end
it { is_expected.to eq [:foo] } it { is_expected.to eq [:foo] }
end end
context "and the result is empty" do context "and the result is empty" do
before { allow(ldap).to receive(:search).and_return([]) } before do
allow(ldap).to receive(:search).and_return([])
end
it { is_expected.to eq [] } it { is_expected.to eq [] }
end end
......
...@@ -173,7 +173,9 @@ describe Gitlab::LDAP::User, lib: true do ...@@ -173,7 +173,9 @@ describe Gitlab::LDAP::User, lib: true do
context 'signup' do context 'signup' do
context 'dont block on create' do context 'dont block on create' do
before { configure_block(false) } before do
configure_block(false)
end
it do it do
ldap_user.save ldap_user.save
...@@ -183,7 +185,9 @@ describe Gitlab::LDAP::User, lib: true do ...@@ -183,7 +185,9 @@ describe Gitlab::LDAP::User, lib: true do
end end
context 'block on create' do context 'block on create' do
before { configure_block(true) } before do
configure_block(true)
end
it do it do
ldap_user.save ldap_user.save
...@@ -200,7 +204,9 @@ describe Gitlab::LDAP::User, lib: true do ...@@ -200,7 +204,9 @@ describe Gitlab::LDAP::User, lib: true do
end end
context 'dont block on create' do context 'dont block on create' do
before { configure_block(false) } before do
configure_block(false)
end
it do it do
ldap_user.save ldap_user.save
...@@ -210,7 +216,9 @@ describe Gitlab::LDAP::User, lib: true do ...@@ -210,7 +216,9 @@ describe Gitlab::LDAP::User, lib: true do
end end
context 'block on create' do context 'block on create' do
before { configure_block(true) } before do
configure_block(true)
end
it do it do
ldap_user.save ldap_user.save
......
...@@ -6,7 +6,9 @@ describe Gitlab::Middleware::RailsQueueDuration do ...@@ -6,7 +6,9 @@ describe Gitlab::Middleware::RailsQueueDuration do
let(:env) { {} } let(:env) { {} }
let(:transaction) { double(:transaction) } let(:transaction) { double(:transaction) }
before { expect(app).to receive(:call).with(env).and_return('yay') } before do
expect(app).to receive(:call).with(env).and_return('yay')
end
describe '#call' do describe '#call' do
it 'calls the app when metrics are disabled' do it 'calls the app when metrics are disabled' do
...@@ -15,7 +17,9 @@ describe Gitlab::Middleware::RailsQueueDuration do ...@@ -15,7 +17,9 @@ describe Gitlab::Middleware::RailsQueueDuration do
end end
context 'when metrics are enabled' do context 'when metrics are enabled' do
before { allow(Gitlab::Metrics).to receive(:current_transaction).and_return(transaction) } before do
allow(Gitlab::Metrics).to receive(:current_transaction).and_return(transaction)
end
it 'calls the app when metrics are enabled but no timing header is found' do it 'calls the app when metrics are enabled but no timing header is found' do
expect(middleware.call(env)).to eq('yay') expect(middleware.call(env)).to eq('yay')
......
...@@ -55,7 +55,9 @@ describe Gitlab::OAuth::AuthHash, lib: true do ...@@ -55,7 +55,9 @@ describe Gitlab::OAuth::AuthHash, lib: true do
end end
context 'email not provided' do context 'email not provided' do
before { info_hash.delete(:email) } before do
info_hash.delete(:email)
end
it 'generates a temp email' do it 'generates a temp email' do
expect( auth_hash.email).to start_with('temp-email-for-oauth') expect( auth_hash.email).to start_with('temp-email-for-oauth')
...@@ -63,7 +65,9 @@ describe Gitlab::OAuth::AuthHash, lib: true do ...@@ -63,7 +65,9 @@ describe Gitlab::OAuth::AuthHash, lib: true do
end end
context 'username not provided' do context 'username not provided' do
before { info_hash.delete(:nickname) } before do
info_hash.delete(:nickname)
end
it 'takes the first part of the email as username' do it 'takes the first part of the email as username' do
expect(auth_hash.username).to eql 'onur.kucuk_ABC-123' expect(auth_hash.username).to eql 'onur.kucuk_ABC-123'
...@@ -71,7 +75,9 @@ describe Gitlab::OAuth::AuthHash, lib: true do ...@@ -71,7 +75,9 @@ describe Gitlab::OAuth::AuthHash, lib: true do
end end
context 'name not provided' do context 'name not provided' do
before { info_hash.delete(:name) } before do
info_hash.delete(:name)
end
it 'concats first and lastname as the name' do it 'concats first and lastname as the name' do
expect(auth_hash.name).to eql name_utf8 expect(auth_hash.name).to eql name_utf8
......
...@@ -112,7 +112,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -112,7 +112,9 @@ describe Gitlab::OAuth::User, lib: true do
end end
context 'with new allow_single_sign_on enabled syntax' do context 'with new allow_single_sign_on enabled syntax' do
before { stub_omniauth_config(allow_single_sign_on: ['twitter']) } before do
stub_omniauth_config(allow_single_sign_on: ['twitter'])
end
it "creates a user from Omniauth" do it "creates a user from Omniauth" do
oauth_user.save oauth_user.save
...@@ -125,7 +127,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -125,7 +127,9 @@ describe Gitlab::OAuth::User, lib: true do
end end
context "with old allow_single_sign_on enabled syntax" do context "with old allow_single_sign_on enabled syntax" do
before { stub_omniauth_config(allow_single_sign_on: true) } before do
stub_omniauth_config(allow_single_sign_on: true)
end
it "creates a user from Omniauth" do it "creates a user from Omniauth" do
oauth_user.save oauth_user.save
...@@ -138,14 +142,20 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -138,14 +142,20 @@ describe Gitlab::OAuth::User, lib: true do
end end
context 'with new allow_single_sign_on disabled syntax' do context 'with new allow_single_sign_on disabled syntax' do
before { stub_omniauth_config(allow_single_sign_on: []) } before do
stub_omniauth_config(allow_single_sign_on: [])
end
it 'throws an error' do it 'throws an error' do
expect{ oauth_user.save }.to raise_error StandardError expect{ oauth_user.save }.to raise_error StandardError
end end
end end
context 'with old allow_single_sign_on disabled (Default)' do context 'with old allow_single_sign_on disabled (Default)' do
before { stub_omniauth_config(allow_single_sign_on: false) } before do
stub_omniauth_config(allow_single_sign_on: false)
end
it 'throws an error' do it 'throws an error' do
expect{ oauth_user.save }.to raise_error StandardError expect{ oauth_user.save }.to raise_error StandardError
end end
...@@ -153,21 +163,30 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -153,21 +163,30 @@ describe Gitlab::OAuth::User, lib: true do
end end
context "with auto_link_ldap_user disabled (default)" do context "with auto_link_ldap_user disabled (default)" do
before { stub_omniauth_config(auto_link_ldap_user: false) } before do
stub_omniauth_config(auto_link_ldap_user: false)
end
include_examples "to verify compliance with allow_single_sign_on" include_examples "to verify compliance with allow_single_sign_on"
end end
context "with auto_link_ldap_user enabled" do context "with auto_link_ldap_user enabled" do
before { stub_omniauth_config(auto_link_ldap_user: true) } before do
stub_omniauth_config(auto_link_ldap_user: true)
end
context "and no LDAP provider defined" do context "and no LDAP provider defined" do
before { stub_ldap_config(providers: []) } before do
stub_ldap_config(providers: [])
end
include_examples "to verify compliance with allow_single_sign_on" include_examples "to verify compliance with allow_single_sign_on"
end end
context "and at least one LDAP provider is defined" do context "and at least one LDAP provider is defined" do
before { stub_ldap_config(providers: %w(ldapmain)) } before do
stub_ldap_config(providers: %w(ldapmain))
end
context "and a corresponding LDAP person" do context "and a corresponding LDAP person" do
before do before do
...@@ -238,7 +257,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -238,7 +257,9 @@ describe Gitlab::OAuth::User, lib: true do
end end
context "and no corresponding LDAP person" do context "and no corresponding LDAP person" do
before { allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(nil) } before do
allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(nil)
end
include_examples "to verify compliance with allow_single_sign_on" include_examples "to verify compliance with allow_single_sign_on"
end end
...@@ -248,11 +269,16 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -248,11 +269,16 @@ describe Gitlab::OAuth::User, lib: true do
describe 'blocking' do describe 'blocking' do
let(:provider) { 'twitter' } let(:provider) { 'twitter' }
before { stub_omniauth_config(allow_single_sign_on: ['twitter']) }
before do
stub_omniauth_config(allow_single_sign_on: ['twitter'])
end
context 'signup with omniauth only' do context 'signup with omniauth only' do
context 'dont block on create' do context 'dont block on create' do
before { stub_omniauth_config(block_auto_created_users: false) } before do
stub_omniauth_config(block_auto_created_users: false)
end
it do it do
oauth_user.save oauth_user.save
...@@ -262,7 +288,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -262,7 +288,9 @@ describe Gitlab::OAuth::User, lib: true do
end end
context 'block on create' do context 'block on create' do
before { stub_omniauth_config(block_auto_created_users: true) } before do
stub_omniauth_config(block_auto_created_users: true)
end
it do it do
oauth_user.save oauth_user.save
...@@ -284,7 +312,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -284,7 +312,9 @@ describe Gitlab::OAuth::User, lib: true do
context "and no account for the LDAP user" do context "and no account for the LDAP user" do
context 'dont block on create (LDAP)' do context 'dont block on create (LDAP)' do
before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false) } before do
allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false)
end
it do it do
oauth_user.save oauth_user.save
...@@ -294,7 +324,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -294,7 +324,9 @@ describe Gitlab::OAuth::User, lib: true do
end end
context 'block on create (LDAP)' do context 'block on create (LDAP)' do
before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true) } before do
allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true)
end
it do it do
oauth_user.save oauth_user.save
...@@ -308,7 +340,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -308,7 +340,9 @@ describe Gitlab::OAuth::User, lib: true do
let!(:existing_user) { create(:omniauth_user, email: 'john@example.com', extern_uid: 'uid=user1,ou=People,dc=example', provider: 'ldapmain', username: 'john') } let!(:existing_user) { create(:omniauth_user, email: 'john@example.com', extern_uid: 'uid=user1,ou=People,dc=example', provider: 'ldapmain', username: 'john') }
context 'dont block on create (LDAP)' do context 'dont block on create (LDAP)' do
before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false) } before do
allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false)
end
it do it do
oauth_user.save oauth_user.save
...@@ -318,7 +352,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -318,7 +352,9 @@ describe Gitlab::OAuth::User, lib: true do
end end
context 'block on create (LDAP)' do context 'block on create (LDAP)' do
before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true) } before do
allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true)
end
it do it do
oauth_user.save oauth_user.save
...@@ -336,7 +372,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -336,7 +372,9 @@ describe Gitlab::OAuth::User, lib: true do
end end
context 'dont block on create' do context 'dont block on create' do
before { stub_omniauth_config(block_auto_created_users: false) } before do
stub_omniauth_config(block_auto_created_users: false)
end
it do it do
oauth_user.save oauth_user.save
...@@ -346,7 +384,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -346,7 +384,9 @@ describe Gitlab::OAuth::User, lib: true do
end end
context 'block on create' do context 'block on create' do
before { stub_omniauth_config(block_auto_created_users: true) } before do
stub_omniauth_config(block_auto_created_users: true)
end
it do it do
oauth_user.save oauth_user.save
...@@ -356,7 +396,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -356,7 +396,9 @@ describe Gitlab::OAuth::User, lib: true do
end end
context 'dont block on create (LDAP)' do context 'dont block on create (LDAP)' do
before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false) } before do
allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false)
end
it do it do
oauth_user.save oauth_user.save
...@@ -366,7 +408,9 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -366,7 +408,9 @@ describe Gitlab::OAuth::User, lib: true do
end end
context 'block on create (LDAP)' do context 'block on create (LDAP)' do
before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true) } before do
allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true)
end
it do it do
oauth_user.save oauth_user.save
......
...@@ -108,11 +108,18 @@ describe Gitlab::Redis do ...@@ -108,11 +108,18 @@ describe Gitlab::Redis do
end end
describe '.with' do describe '.with' do
before { clear_pool } before do
after { clear_pool } clear_pool
end
after do
clear_pool
end
context 'when running not on sidekiq workers' do context 'when running not on sidekiq workers' do
before { allow(Sidekiq).to receive(:server?).and_return(false) } before do
allow(Sidekiq).to receive(:server?).and_return(false)
end
it 'instantiates a connection pool with size 5' do it 'instantiates a connection pool with size 5' do
expect(ConnectionPool).to receive(:new).with(size: 5).and_call_original expect(ConnectionPool).to receive(:new).with(size: 5).and_call_original
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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