Commit c0e52768 authored by Robert Speicher's avatar Robert Speicher

Correct RSpec/SingleLineHook cop offenses

parent 2a9ac54b
......@@ -2,7 +2,10 @@ require 'spec_helper'
describe Admin::IdentitiesController do
let(:admin) { create(:admin) }
before { sign_in(admin) }
before do
sign_in(admin)
end
describe 'UPDATE identity' do
let(:user) { create(:omniauth_user, provider: 'ldapmain', extern_uid: 'uid=myuser,ou=people,dc=example,dc=com') }
......
......@@ -2,7 +2,10 @@ require 'spec_helper'
describe Admin::LicensesController do
let(:admin) { create(:admin) }
before { sign_in(admin) }
before do
sign_in(admin)
end
describe 'Upload license' do
it 'redirects back when no license is entered/uploaded' do
......
......@@ -3,7 +3,9 @@ require 'spec_helper'
describe Admin::ServicesController do
let(:admin) { create(:admin) }
before { sign_in(admin) }
before do
sign_in(admin)
end
describe 'GET #edit' do
let!(:project) { create(:empty_project) }
......
......@@ -240,7 +240,9 @@ describe AutocompleteController do
end
context 'skip_users parameter included' do
before { sign_in(user) }
before do
sign_in(user)
end
it 'skips the user IDs passed' do
get(:users, skip_users: [user, user2].map(&:id))
......
......@@ -16,10 +16,14 @@ describe Groups::GroupMembersController do
describe 'POST create' do
let(:group_user) { create(:user) }
before { sign_in(user) }
before do
sign_in(user)
end
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
post :create, group_id: group,
......@@ -32,7 +36,9 @@ describe Groups::GroupMembersController do
end
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
post :create, group_id: group,
......@@ -59,7 +65,9 @@ describe Groups::GroupMembersController do
describe 'DELETE destroy' do
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
it 'returns 403' do
......@@ -71,7 +79,9 @@ describe Groups::GroupMembersController do
context 'when member is found' 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
delete :destroy, group_id: group, id: member
......@@ -82,7 +92,9 @@ describe Groups::GroupMembersController do
end
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
delete :destroy, group_id: group, id: member
......@@ -103,7 +115,9 @@ describe Groups::GroupMembersController do
end
describe 'DELETE leave' do
before { sign_in(user) }
before do
sign_in(user)
end
context 'when member is not found' do
it 'returns 404' do
......@@ -115,7 +129,9 @@ describe Groups::GroupMembersController do
context 'when member is found' 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
delete :leave, group_id: group
......@@ -127,7 +143,9 @@ describe Groups::GroupMembersController do
end
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
delete :leave, group_id: group
......@@ -137,7 +155,9 @@ describe Groups::GroupMembersController do
end
context 'and is a requester' do
before { group.request_access(user) }
before do
group.request_access(user)
end
it 'removes user from members' do
delete :leave, group_id: group
......@@ -152,7 +172,9 @@ describe Groups::GroupMembersController do
end
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
post :request_access, group_id: group
......@@ -167,7 +189,9 @@ describe Groups::GroupMembersController do
describe 'POST approve_access_request' do
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
it 'returns 403' do
......@@ -179,7 +203,9 @@ describe Groups::GroupMembersController do
context 'when member is found' 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
post :approve_access_request, group_id: group, id: member
......@@ -190,7 +216,9 @@ describe Groups::GroupMembersController do
end
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
post :approve_access_request, group_id: group, id: member
......
......@@ -94,7 +94,10 @@ describe NotificationSettingsController do
context 'not authorized' do
let(:private_project) { create(:empty_project, :private) }
before { sign_in(user) }
before do
sign_in(user)
end
it 'returns 404' do
post :create,
......@@ -120,7 +123,9 @@ describe NotificationSettingsController do
end
context 'when authorized' do
before{ sign_in(user) }
before do
sign_in(user)
end
it 'returns success' do
put :update,
......@@ -152,7 +157,9 @@ describe NotificationSettingsController do
context 'not authorized' do
let(:other_user) { create(:user) }
before { sign_in(other_user) }
before do
sign_in(other_user)
end
it 'returns 404' do
put :update,
......
......@@ -4,7 +4,9 @@ describe Profiles::PersonalAccessTokensController do
let(:user) { create(:user) }
let(:token_attributes) { attributes_for(:personal_access_token) }
before { sign_in(user) }
before do
sign_in(user)
end
describe '#create' do
def created_token
......@@ -38,7 +40,9 @@ describe Profiles::PersonalAccessTokensController do
let!(:inactive_personal_access_token) { create(:personal_access_token, :revoked, 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
expect(assigns(:active_personal_access_tokens)).to include(active_personal_access_token)
......
......@@ -281,7 +281,9 @@ describe Projects::CommitController do
end
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
expect(response).to have_http_status(404)
......@@ -302,7 +304,9 @@ describe Projects::CommitController do
end
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
expect(response).to have_http_status(404)
......
......@@ -128,7 +128,9 @@ describe Projects::CompareController do
end
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
expect(response).to have_http_status(404)
......@@ -149,7 +151,9 @@ describe Projects::CompareController do
end
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
expect(response).to have_http_status(404)
......@@ -157,7 +161,9 @@ describe Projects::CompareController do
end
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
expect(response).to have_http_status(404)
......
......@@ -14,7 +14,9 @@ describe Projects::ForksController do
end
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
get_forks
......@@ -35,7 +37,9 @@ describe Projects::ForksController do
end
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
it 'does not see the Project listed' do
......@@ -46,7 +50,9 @@ describe Projects::ForksController do
end
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
get_forks
......@@ -56,7 +62,9 @@ describe Projects::ForksController do
end
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
get_forks
......
......@@ -22,7 +22,10 @@ describe Projects::GroupLinksController do
end
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'
it 'links project with selected group' do
......
......@@ -212,7 +212,9 @@ describe Projects::IssuesController do
let(:another_project) { create(:empty_project, :private) }
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
move_issue
......@@ -250,14 +252,18 @@ describe Projects::IssuesController do
end
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
def update_spam_issue
update_issue(title: 'Spam Title', description: 'Spam lives here')
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
expect { update_spam_issue }.not_to change{ issue.reload.title }
......@@ -619,14 +625,18 @@ describe Projects::IssuesController do
end
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
def post_spam_issue
post_new_issue(title: 'Spam Title', description: 'Spam lives here')
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
expect { post_spam_issue }.not_to change(Issue, :count)
......@@ -738,7 +748,10 @@ describe Projects::IssuesController do
describe "DELETE #destroy" 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
delete :destroy, namespace_id: project.namespace, project_id: project, id: issue.iid
expect(response).to have_http_status(404)
......@@ -750,7 +763,9 @@ describe Projects::IssuesController do
let(:namespace) { create(:namespace, owner: owner) }
let(:project) { create(:empty_project, namespace: namespace) }
before { sign_in(owner) }
before do
sign_in(owner)
end
it "deletes the issue" do
delete :destroy, namespace_id: project.namespace, project_id: project, id: issue.iid
......
......@@ -16,10 +16,14 @@ describe Projects::ProjectMembersController do
describe 'POST create' do
let(:project_user) { create(:user) }
before { sign_in(user) }
before do
sign_in(user)
end
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
post :create, namespace_id: project.namespace,
......@@ -33,7 +37,9 @@ describe Projects::ProjectMembersController do
end
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
expect_any_instance_of(Members::CreateService).to receive(:execute).and_return(status: :success)
......@@ -64,7 +70,9 @@ describe Projects::ProjectMembersController do
describe 'DELETE destroy' do
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
it 'returns 404' do
......@@ -78,7 +86,9 @@ describe Projects::ProjectMembersController do
context 'when member is found' 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
delete :destroy, namespace_id: project.namespace,
......@@ -91,7 +101,9 @@ describe Projects::ProjectMembersController do
end
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
delete :destroy, namespace_id: project.namespace,
......@@ -117,7 +129,9 @@ describe Projects::ProjectMembersController do
end
describe 'DELETE leave' do
before { sign_in(user) }
before do
sign_in(user)
end
context 'when member is not found' do
it 'returns 404' do
......@@ -130,7 +144,9 @@ describe Projects::ProjectMembersController do
context 'when member is found' 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
delete :leave, namespace_id: project.namespace,
......@@ -145,7 +161,9 @@ describe Projects::ProjectMembersController do
context 'and is an owner' do
let(:project) { create(:empty_project, namespace: user.namespace) }
before { project.team << [user, :master] }
before do
project.team << [user, :master]
end
it 'does not remove himself from the project' do
delete :leave, namespace_id: project.namespace,
......@@ -156,7 +174,9 @@ describe Projects::ProjectMembersController do
end
context 'and is a requester' do
before { project.request_access(user) }
before do
project.request_access(user)
end
it 'removes user from members' do
delete :leave, namespace_id: project.namespace,
......@@ -172,7 +192,9 @@ describe Projects::ProjectMembersController do
end
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
post :request_access, namespace_id: project.namespace,
......@@ -190,7 +212,9 @@ describe Projects::ProjectMembersController do
describe 'POST approve' do
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
it 'returns 404' do
......@@ -204,7 +228,9 @@ describe Projects::ProjectMembersController do
context 'when member is found' 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
post :approve_access_request, namespace_id: project.namespace,
......@@ -217,7 +243,9 @@ describe Projects::ProjectMembersController do
end
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
post :approve_access_request, namespace_id: project.namespace,
......@@ -252,7 +280,10 @@ describe Projects::ProjectMembersController do
end
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'
it 'imports source project members' do
......
......@@ -46,7 +46,9 @@ describe Projects::SnippetsController do
end
context 'when signed in as the author' do
before { sign_in(user) }
before do
sign_in(user)
end
it 'renders the snippet' do
get :index, namespace_id: project.namespace, project_id: project
......@@ -57,7 +59,9 @@ describe Projects::SnippetsController do
end
context 'when signed in as a project member' do
before { sign_in(user2) }
before do
sign_in(user2)
end
it 'renders the snippet' do
get :index, namespace_id: project.namespace, project_id: project
......@@ -317,7 +321,9 @@ describe Projects::SnippetsController do
end
context 'when signed in as the author' do
before { sign_in(user) }
before do
sign_in(user)
end
it 'renders the snippet' do
get action, namespace_id: project.namespace, project_id: project, id: project_snippet.to_param
......@@ -328,7 +334,9 @@ describe Projects::SnippetsController do
end
context 'when signed in as a project member' do
before { sign_in(user2) }
before do
sign_in(user2)
end
it 'renders the snippet' do
get action, namespace_id: project.namespace, project_id: project, id: project_snippet.to_param
......@@ -349,7 +357,9 @@ describe Projects::SnippetsController do
end
context 'when signed in' do
before { sign_in(user) }
before do
sign_in(user)
end
it 'responds with status 404' do
get action, namespace_id: project.namespace, project_id: project, id: 42
......
......@@ -6,7 +6,9 @@ describe Projects::TagsController do
let!(:invalid_release) { create(:release, project: project, tag: 'does-not-exist') }
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
expect(assigns(:tags).map(&:name)).to eq(['v1.1.0', 'v1.0.0'])
......@@ -19,7 +21,9 @@ describe Projects::TagsController do
end
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
let(:id) { 'v1.0.0' }
......
......@@ -29,7 +29,9 @@ describe ProjectsController do
describe "GET show" 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
let(:private_project) { create(:empty_project, :private) }
......@@ -108,7 +110,9 @@ describe ProjectsController do
context "project with empty repo" do
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|
context "with #{project_view} view set" do
......@@ -128,7 +132,9 @@ describe ProjectsController do
context "project with broken repo" do
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|
context "with #{project_view} view set" do
......
......@@ -18,7 +18,9 @@ describe SearchController do
context 'on restricted projects' do
context 'when signed out' do
before { sign_out(user) }
before do
sign_out(user)
end
it "doesn't expose comments on issues" do
project = create(:empty_project, :public, :issues_private)
......
......@@ -14,7 +14,9 @@ describe SentNotificationsController, type: :controller do
describe 'GET unsubscribe' do
context 'when the user is not logged in' 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
expect(issue.subscribed?(user, project)).to be_falsey
......@@ -30,7 +32,9 @@ describe SentNotificationsController, type: :controller do
end
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
expect(issue.subscribed?(user, project)).to be_truthy
......@@ -47,10 +51,14 @@ describe SentNotificationsController, type: :controller do
end
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
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
expect(issue.subscribed?(user, project)).to be_truthy
......@@ -66,7 +74,9 @@ describe SentNotificationsController, type: :controller do
end
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
expect(issue.subscribed?(user, project)).to be_falsey
......@@ -89,7 +99,10 @@ describe SentNotificationsController, type: :controller do
end
end
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
expect(merge_request.subscribed?(user, project)).to be_falsey
......
......@@ -142,7 +142,9 @@ describe SessionsController do
end
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
expect(subject.current_user).not_to eq user
......@@ -169,7 +171,9 @@ describe SessionsController do
end
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
expect(subject.current_user).not_to eq user
......
......@@ -437,7 +437,9 @@ describe SnippetsController do
end
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
expect(assigns(:snippet)).to eq(personal_snippet)
......
......@@ -43,7 +43,9 @@ describe UsersController do
end
context 'when logged in' do
before { sign_in(user) }
before do
sign_in(user)
end
it 'renders show' do
get :show, username: user.username
......@@ -62,7 +64,9 @@ describe UsersController do
end
context 'when logged in' do
before { sign_in(user) }
before do
sign_in(user)
end
it 'renders 404' do
get :show, username: 'nonexistent'
......
......@@ -134,7 +134,10 @@ describe "Admin Runners" do
describe 'runners registration token' do
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
expect(page).to have_content("Registration token is #{token}")
......
......@@ -12,7 +12,9 @@ describe 'Admin > Users > Impersonation Tokens', feature: true, js: true do
find(".table.inactive-tokens")
end
before { login_as(admin) }
before do
login_as(admin)
end
describe "token creation" do
it "allows creation of a token" do
......
......@@ -124,7 +124,10 @@ describe "Admin::Users", feature: true do
describe 'Impersonation' do
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
it 'shows impersonate button for other users' do
......@@ -149,7 +152,9 @@ describe "Admin::Users", feature: true do
end
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
expect(page.find(:css, '.header-user .profile-link')['data-user']).to eql(another_user.username)
......
......@@ -12,7 +12,9 @@ describe 'Dashboard Merge Requests' do
end
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
find('.new-project-item-select-button').trigger('click')
......
......@@ -17,19 +17,25 @@ feature 'Project member activity', feature: true, js: true do
subject { page.find(".event-title").text }
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") }
end
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") }
end
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
message = "#{user.name} removed due to membership expiration from project"
......
......@@ -140,7 +140,9 @@ feature 'Expand and collapse diffs', js: true, feature: true do
end
context 'reloading the page' do
before { refresh }
before do
refresh
end
it 'collapses the large diff by default' do
expect(large_diff).not_to have_selector('.code')
......
......@@ -53,8 +53,13 @@ feature 'Edit group settings', feature: true do
given(:old_project_full_path) { "/#{group.path}/#{project.path}" }
given(:new_project_full_path) { "/#{new_group_path}/#{project.path}" }
before(:context) { TestEnv.clean_test_path }
after(:example) { TestEnv.clean_test_path }
before(:context) do
TestEnv.clean_test_path
end
after(:example) do
TestEnv.clean_test_path
end
scenario 'the project is accessible via the new path' do
update_path(new_group_path)
......
......@@ -12,7 +12,9 @@ feature 'Group', feature: true do
end
describe 'create a group' do
before { visit new_group_path }
before do
visit new_group_path
end
describe 'with space in group path' do
it 'renders new group form with validation errors' do
......@@ -138,7 +140,9 @@ feature 'Group', feature: true do
let(:path) { edit_group_path(group) }
let(:new_name) { 'new-name' }
before { visit path }
before do
visit path
end
it 'saves new settings' do
fill_in 'group_name', with: new_name
......
......@@ -153,7 +153,9 @@ describe 'Projects > Issuables > Default sort order', feature: true do
context 'when the sort in the URL is id_desc' do
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
expect(find('.issues-other-filters')).to have_content('Last created')
......@@ -165,7 +167,9 @@ describe 'Projects > Issuables > Default sort order', feature: true do
context 'when the sort in the URL is id_asc' do
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
expect(find('.issues-other-filters')).to have_content('Oldest created')
......
......@@ -8,7 +8,9 @@ describe 'Issues csv', feature: true do
let(:feature_label) { create(:label, project: project, title: 'Feature') }
let!(:issue) { create(:issue, project: project, author: user) }
before { login_as(user) }
before do
login_as(user)
end
def request_csv(params = {})
visit namespace_project_issues_path(project.namespace, project, params)
......
......@@ -257,7 +257,10 @@ describe 'Issues', feature: true do
context 'with a filter on labels' do
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
bar.update(due_date: nil)
......
......@@ -202,10 +202,12 @@ feature 'Login', feature: true do
# TODO: otp_grace_period_started_at
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
before(:each) do
before do
stub_application_setting(two_factor_grace_period: 48)
login_with(user)
end
......@@ -242,7 +244,7 @@ feature 'Login', feature: true do
end
context 'without grace period defined' do
before(:each) do
before do
stub_application_setting(two_factor_grace_period: 0)
login_with(user)
end
......@@ -265,7 +267,7 @@ feature 'Login', feature: true do
end
context 'with grace period defined' do
before(:each) do
before do
stub_application_setting(two_factor_grace_period: 48)
login_with(user)
end
......@@ -306,7 +308,7 @@ feature 'Login', feature: true do
end
context 'without grace period defined' do
before(:each) do
before do
stub_application_setting(two_factor_grace_period: 0)
login_with(user)
end
......
......@@ -85,14 +85,18 @@ feature 'Merge request conflict resolution', js: true, feature: true do
context 'the conflicts are resolvable' do
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
expect(page).to have_link('conflicts', href: /\/conflicts\Z/)
end
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 Edit inline mode"
......
......@@ -18,7 +18,9 @@ feature 'Merge immediately', :feature, :js do
sha: project.repository.commit('master').id)
end
before { project.team << [user, :master] }
before do
project.team << [user, :master]
end
context 'when there is active pipeline for merge request' do
background do
......
......@@ -31,8 +31,13 @@ feature 'Profile > Account', feature: true do
given(:new_project_path) { "/#{new_username}/#{project.path}" }
given(:old_project_path) { "/#{user.username}/#{project.path}" }
before(:context) { TestEnv.clean_test_path }
after(:example) { TestEnv.clean_test_path }
before(:context) do
TestEnv.clean_test_path
end
after(:example) do
TestEnv.clean_test_path
end
scenario 'the project is accessible via the new path' do
update_username(new_username)
......
......@@ -47,7 +47,9 @@ describe 'Pipeline', :feature, :js do
let(:project) { create(:project) }
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
expect(page).to have_selector('.pipeline-visualization')
......@@ -164,7 +166,9 @@ describe 'Pipeline', :feature, :js do
it { expect(page).not_to have_content('retried') }
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') }
end
......@@ -174,7 +178,9 @@ describe 'Pipeline', :feature, :js do
it { expect(page).not_to have_selector('.ci-canceled') }
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') }
end
......@@ -226,7 +232,9 @@ describe 'Pipeline', :feature, :js do
it { expect(page).not_to have_content('retried') }
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') }
end
......@@ -236,7 +244,9 @@ describe 'Pipeline', :feature, :js do
it { expect(page).not_to have_selector('.ci-canceled') }
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') }
end
......
......@@ -149,7 +149,9 @@ describe 'Pipelines', :feature, :js do
create(:ci_pipeline, :invalid, project: project)
end
before { visit_project_pipelines }
before do
visit_project_pipelines
end
it 'contains badge that indicates errors' do
expect(page).to have_content 'yaml invalid'
......@@ -171,7 +173,9 @@ describe 'Pipelines', :feature, :js do
commands: 'test')
end
before { visit_project_pipelines }
before do
visit_project_pipelines
end
it 'has a dropdown with play button' do
expect(page).to have_selector('.dropdown-toggle.btn.btn-default .icon-play')
......@@ -204,7 +208,9 @@ describe 'Pipelines', :feature, :js do
stage: 'test')
end
before { visit_project_pipelines }
before do
visit_project_pipelines
end
it 'is cancelable' do
expect(page).to have_selector('.js-pipelines-cancel-button')
......@@ -215,7 +221,9 @@ describe 'Pipelines', :feature, :js do
end
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
expect(page).not_to have_selector('.js-pipelines-cancel-button')
......@@ -255,7 +263,9 @@ describe 'Pipelines', :feature, :js do
stage: 'test')
end
before { visit_project_pipelines }
before do
visit_project_pipelines
end
it 'has artifats' do
expect(page).to have_selector('.build-artifacts')
......@@ -284,7 +294,9 @@ describe 'Pipelines', :feature, :js do
stage: 'test')
end
before { visit_project_pipelines }
before do
visit_project_pipelines
end
it { expect(page).not_to have_selector('.build-artifacts') }
end
......@@ -297,7 +309,9 @@ describe 'Pipelines', :feature, :js do
stage: 'test')
end
before { visit_project_pipelines }
before do
visit_project_pipelines
end
it { expect(page).not_to have_selector('.build-artifacts') }
end
......@@ -310,7 +324,9 @@ describe 'Pipelines', :feature, :js do
name: 'build')
end
before { visit_project_pipelines }
before do
visit_project_pipelines
end
it 'should render a mini pipeline graph' do
expect(page).to have_selector('.js-mini-pipeline-graph')
......@@ -437,7 +453,9 @@ describe 'Pipelines', :feature, :js do
end
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
expect { click_on 'Create pipeline' }
......@@ -448,7 +466,9 @@ describe 'Pipelines', :feature, :js do
end
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') }
end
......
......@@ -58,8 +58,13 @@ describe 'Edit Project Settings', feature: true do
# Not using empty project because we need a repo to exist
let(:project) { create(:project, namespace: user.namespace, name: 'gitlabhq') }
before(:context) { TestEnv.clean_test_path }
after(:example) { TestEnv.clean_test_path }
before(:context) do
TestEnv.clean_test_path
end
after(:example) do
TestEnv.clean_test_path
end
specify 'the project is accessible via the new path' do
rename_project(project, path: 'bar')
......@@ -96,9 +101,17 @@ describe 'Edit Project Settings', feature: true do
let!(:project) { create(:project, namespace: user.namespace, name: 'gitlabhq') }
let!(:group) { create(:group) }
before(:context) { TestEnv.clean_test_path }
before(:example) { group.add_owner(user) }
after(:example) { TestEnv.clean_test_path }
before(:context) do
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
transfer_project(project, group)
......
......@@ -6,7 +6,9 @@ feature 'Protected Branches', feature: true, js: true do
let(:user) { create(:user, :admin) }
let(:project) { create(:project, :repository) }
before { login_as(user) }
before do
login_as(user)
end
describe "explicit protected branches" do
it "allows creating explicit protected branches" do
......
......@@ -4,7 +4,9 @@ feature 'Projected Tags', feature: true, js: true do
let(:user) { create(:user, :admin) }
let(:project) { create(:project, :repository) }
before { login_as(user) }
before do
login_as(user)
end
def set_allowed_to(operation, option = 'Masters', form: '.new-protected-tag')
within form do
......
......@@ -4,7 +4,10 @@ describe "Runners" do
include GitlabRoutingHelper
let(:user) { create(:user) }
before { login_as(user) }
before do
login_as(user)
end
describe "specific runners" do
before do
......@@ -127,7 +130,9 @@ describe "Runners" do
end
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
visit runners_path(project)
......
......@@ -83,7 +83,9 @@ describe "Search", feature: true do
let(:project) { create(:project, :repository) }
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
visit namespace_project_path(project.namespace, project)
......
......@@ -358,7 +358,9 @@ describe "Internal Project Access", feature: true do
subject { namespace_project_jobs_path(project.namespace, project) }
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(:auditor) }
......@@ -373,7 +375,9 @@ describe "Internal Project Access", feature: true do
end
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(:auditor) }
......@@ -394,7 +398,9 @@ describe "Internal Project Access", feature: true do
subject { namespace_project_job_path(project.namespace, project, build.id) }
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(:auditor) }
......@@ -409,7 +415,9 @@ describe "Internal Project Access", feature: true do
end
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(:auditor) }
......
......@@ -165,7 +165,9 @@ describe "Public Project Access", feature: true do
subject { namespace_project_jobs_path(project.namespace, project) }
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(:auditor) }
......@@ -180,7 +182,9 @@ describe "Public Project Access", feature: true do
end
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(:auditor) }
......@@ -201,7 +205,9 @@ describe "Public Project Access", feature: true do
subject { namespace_project_job_path(project.namespace, project, build.id) }
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(:auditor) }
......@@ -216,7 +222,9 @@ describe "Public Project Access", feature: true do
end
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(:auditor) }
......
......@@ -3,7 +3,9 @@ require 'spec_helper'
feature 'Signup', feature: true do
describe 'signup with no errors' 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
user = build(:user)
......@@ -23,7 +25,9 @@ feature 'Signup', feature: true do
end
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
user = build(:user)
......
......@@ -144,7 +144,9 @@ feature 'Task Lists', feature: true do
describe 'nested tasks', js: true do
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
expect(page).to have_selector('ul.task-list', count: 2)
......
......@@ -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_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
let(:issue_1) { create(:issue, title: 'issue_1', project: project) }
......
......@@ -5,7 +5,10 @@ feature 'Triggers', feature: true, js: true do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:guest_user) { create(:user) }
before { login_as(user) }
before do
login_as(user)
end
before do
@project = create(:empty_project)
......
require 'spec_helper'
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
click_on 'Manage two-factor authentication'
......@@ -28,7 +30,9 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', :js do
end
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
visit profile_account_path
......
......@@ -56,7 +56,9 @@ describe 'Unsubscribe links', feature: true do
end
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
visit body_link
......
......@@ -45,7 +45,9 @@ feature 'Users', feature: true, js: true do
end
describe 'redirect alias routes' do
before { user }
before do
expect(user).to be_persisted
end
scenario '/u/user1 redirects to user page' do
visit '/u/user1'
......
......@@ -164,7 +164,9 @@ describe IssuesFinder do
let(:params) { { label_name: [label.title, label2.title].join(',') } }
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
expect(issues).to contain_exactly(issue2)
......
......@@ -25,49 +25,65 @@ describe PersonalAccessTokensFinder do
end
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) }
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) }
end
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) }
end
end
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) }
describe 'with active state' do
before { params[:state] = 'active' }
before do
params[:state] = 'active'
end
it { is_expected.to contain_exactly(active_impersonation_token) }
end
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) }
end
end
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) }
end
describe 'with inactive state' do
before { params[:state] = 'inactive' }
before do
params[:state] = 'inactive'
end
it do
is_expected.to contain_exactly(expired_personal_access_token, revoked_personal_access_token,
......@@ -81,7 +97,9 @@ describe PersonalAccessTokensFinder do
it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do
before { params[:impersonation] = true }
before do
params[:impersonation] = true
end
it { is_expected.to be_nil }
end
......@@ -93,7 +111,9 @@ describe PersonalAccessTokensFinder do
it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do
before { params[:impersonation] = true }
before do
params[:impersonation] = true
end
it { is_expected.to be_nil }
end
......@@ -109,7 +129,9 @@ describe PersonalAccessTokensFinder do
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) }
before { params[:user] = user }
before do
params[:user] = user
end
it do
is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token,
......@@ -118,49 +140,65 @@ describe PersonalAccessTokensFinder do
end
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) }
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) }
end
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) }
end
end
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) }
describe 'with active state' do
before { params[:state] = 'active' }
before do
params[:state] = 'active'
end
it { is_expected.to contain_exactly(active_impersonation_token) }
end
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) }
end
end
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) }
end
describe 'with inactive state' do
before { params[:state] = 'inactive' }
before do
params[:state] = 'inactive'
end
it do
is_expected.to contain_exactly(expired_personal_access_token, revoked_personal_access_token,
......@@ -174,7 +212,9 @@ describe PersonalAccessTokensFinder do
it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do
before { params[:impersonation] = true }
before do
params[:impersonation] = true
end
it { is_expected.to be_nil }
end
......@@ -186,7 +226,9 @@ describe PersonalAccessTokensFinder do
it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do
before { params[:impersonation] = true }
before do
params[:impersonation] = true
end
it { is_expected.to be_nil }
end
......
......@@ -32,7 +32,9 @@ describe PersonalProjectsFinder do
end
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]) }
end
......
......@@ -6,7 +6,9 @@ describe TodosFinder do
let(:project) { create(:empty_project) }
let(:finder) { described_class }
before { project.team << [user, :developer] }
before do
project.team << [user, :developer]
end
describe '#sort' do
context 'by date' do
......
......@@ -259,7 +259,9 @@ describe ProjectsHelper do
end
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
helper.instance_variable_set(:@project, project)
......
......@@ -82,7 +82,9 @@ describe Banzai::Filter::ExternalIssueReferenceFilter, lib: true do
context 'with RequestStore enabled' do
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
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
end
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
user = create(:user)
......@@ -54,7 +56,9 @@ describe Banzai::Filter::RedactorFilter, lib: true do
end
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
user = create(:user)
......
......@@ -10,7 +10,9 @@ describe Banzai::ReferenceParser::CommitParser, lib: true do
describe '#nodes_visible_to_user' 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"
end
......
......@@ -10,7 +10,9 @@ describe Banzai::ReferenceParser::CommitRangeParser, lib: true do
describe '#nodes_visible_to_user' 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"
end
......
......@@ -10,7 +10,9 @@ describe Banzai::ReferenceParser::ExternalIssueParser, lib: true do
describe '#nodes_visible_to_user' 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]
......
......@@ -11,7 +11,9 @@ describe Banzai::ReferenceParser::LabelParser, lib: true do
describe '#nodes_visible_to_user' 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"
end
......
......@@ -11,7 +11,9 @@ describe Banzai::ReferenceParser::MilestoneParser, lib: true do
describe '#nodes_visible_to_user' 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"
end
......
......@@ -12,7 +12,9 @@ describe EE::Gitlab::LDAP::AccessLevels, lib: true do
subject { access_levels }
context 'when access_levels is empty' do
before { access_levels.set(dns, to: Gitlab::Access::DEVELOPER) }
before do
access_levels.set(dns, to: Gitlab::Access::DEVELOPER)
end
it do
is_expected
......
......@@ -15,10 +15,14 @@ describe EE::Gitlab::LDAP::Sync::Groups, lib: true do
2.times { create(:group_with_ldap_group_link) }
end
after { group_sync.update_permissions }
after do
group_sync.update_permissions
end
context 'when group_base is not present' do
before { stub_ldap_config(group_base: nil) }
before do
stub_ldap_config(group_base: nil)
end
it 'does not call EE::Gitlab::LDAP::Sync::Group#execute' do
expect(EE::Gitlab::LDAP::Sync::Group).not_to receive(:execute)
......@@ -35,7 +39,9 @@ describe EE::Gitlab::LDAP::Sync::Groups, lib: true do
context 'when group_base is present' do
context 'and admin_group and external_groups are not present' do
before { stub_ldap_config(group_base: 'dc=example,dc=com') }
before do
stub_ldap_config(group_base: 'dc=example,dc=com')
end
it 'calls EE::Gitlab::LDAP::Sync::Group#execute' do
expect(EE::Gitlab::LDAP::Sync::Group).to receive(:execute).twice
......
......@@ -172,7 +172,9 @@ describe EE::Gitlab::LDAP::Sync::Proxy, lib: true do
)
end
after { sync_proxy.dn_for_uid(user.username) }
after do
sync_proxy.dn_for_uid(user.username)
end
it 'does not query LDAP' do
expect(::Gitlab::LDAP::Person).not_to receive(:find_by_uid)
......
......@@ -77,7 +77,10 @@ describe ExtractsPath, lib: true do
context 'without a path' do
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
expect(@ref).to eq('v1.0.0')
......
......@@ -40,7 +40,9 @@ describe Gitlab::Auth::UniqueIpsLimiter, :redis, lib: true do
end
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
change_ip('ip1')
......
......@@ -29,7 +29,9 @@ describe Gitlab::Badge::Build::Status do
let!(:build) { create_build(project, sha, branch) }
context 'build success' do
before { build.success! }
before do
build.success!
end
describe '#status' do
it 'is successful' do
......@@ -39,7 +41,9 @@ describe Gitlab::Badge::Build::Status do
end
context 'build failed' do
before { build.drop! }
before do
build.drop!
end
describe '#status' do
it 'failed' do
......
......@@ -4,7 +4,9 @@ describe Gitlab::ChatCommands::Presenters::IssueSearch do
let(:project) { create(:empty_project) }
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 }
......
......@@ -20,7 +20,9 @@ describe Gitlab::Checks::ChangeAccess, lib: true do
).exec
end
before { project.add_developer(user) }
before do
project.add_developer(user)
end
context 'without failed checks' do
it "doesn't raise an error" do
......@@ -50,7 +52,9 @@ describe Gitlab::Checks::ChangeAccess, lib: true do
let!(:protected_tag) { create(:protected_tag, project: project, name: 'v*') }
context 'as master' do
before { project.add_master(user) }
before do
project.add_master(user)
end
context 'deletion' do
let(:oldrev) { 'be93687618e4b132087f430a4d8fc3a609c9b77c' }
......@@ -175,7 +179,9 @@ describe Gitlab::Checks::ChangeAccess, lib: true do
let(:newrev) { '0000000000000000000000000000000000000000' }
let(:ref) { 'refs/tags/v1.0.0' }
before { project.add_master(user) }
before do
project.add_master(user)
end
it 'returns an error if the rule denies tag deletion' do
expect { subject }.to raise_error(Gitlab::GitAccess::UnauthorizedError, 'You cannot delete a tag')
......@@ -295,7 +301,9 @@ describe Gitlab::Checks::ChangeAccess, lib: true do
context 'max file size rules' do
let(:push_rule) { create(:push_rule, max_file_size: 1) }
before { allow_any_instance_of(Blob).to receive(:size).and_return(2.megabytes) }
before do
allow_any_instance_of(Blob).to receive(:size).and_return(2.megabytes)
end
it 'returns an error if file exceeds the maximum file size' do
expect { subject }.to raise_error(Gitlab::GitAccess::UnauthorizedError, "File \"README\" is larger than the allowed size of 1 MB")
......
......@@ -4,7 +4,9 @@ describe Gitlab::Ci::Config::Entry::Cache do
let(:entry) { described_class.new(config) }
describe 'validations' do
before { entry.compose! }
before do
entry.compose!
end
context 'when entry config value is correct' do
let(:config) do
......
......@@ -3,7 +3,9 @@ require 'spec_helper'
describe Gitlab::Ci::Config::Entry::Environment do
let(:entry) { described_class.new(config) }
before { entry.compose! }
before do
entry.compose!
end
context 'when configuration is a string' do
let(:config) { 'production' }
......
......@@ -33,7 +33,9 @@ describe Gitlab::Ci::Config::Entry::Global do
end
describe '#compose!' do
before { global.compose! }
before do
global.compose!
end
it 'creates nodes hash' do
expect(global.descendants).to be_an Array
......@@ -79,7 +81,9 @@ describe Gitlab::Ci::Config::Entry::Global do
end
context 'when composed' do
before { global.compose! }
before do
global.compose!
end
describe '#errors' do
it 'has no errors' do
......@@ -175,7 +179,9 @@ describe Gitlab::Ci::Config::Entry::Global do
end
context 'when most of entires not defined' do
before { global.compose! }
before do
global.compose!
end
let(:hash) do
{ cache: { key: 'a' }, rspec: { script: %w[ls] } }
......@@ -218,7 +224,9 @@ describe Gitlab::Ci::Config::Entry::Global do
# details.
#
context 'when entires specified but not defined' do
before { global.compose! }
before do
global.compose!
end
let(:hash) do
{ variables: nil, rspec: { script: 'rspec' } }
......@@ -233,7 +241,9 @@ describe Gitlab::Ci::Config::Entry::Global do
end
context 'when configuration is not valid' do
before { global.compose! }
before do
global.compose!
end
context 'when before script is not an array' do
let(:hash) do
......@@ -297,7 +307,9 @@ describe Gitlab::Ci::Config::Entry::Global do
end
describe '#[]' do
before { global.compose! }
before do
global.compose!
end
let(:hash) do
{ cache: { key: 'a' }, rspec: { script: 'ls' } }
......
......@@ -18,7 +18,9 @@ describe Gitlab::Ci::Config::Entry::Job do
end
describe 'validations' do
before { entry.compose! }
before do
entry.compose!
end
context 'when entry config value is correct' do
let(:config) { { script: 'rspec' } }
......@@ -97,7 +99,9 @@ describe Gitlab::Ci::Config::Entry::Job do
let(:deps) { double('deps', '[]' => unspecified) }
context 'when job config overrides global config' do
before { entry.compose!(deps) }
before do
entry.compose!(deps)
end
let(:config) do
{ script: 'rspec', image: 'some_image', cache: { key: 'test' } }
......@@ -125,10 +129,14 @@ describe Gitlab::Ci::Config::Entry::Job do
end
context 'when composed' do
before { entry.compose! }
before do
entry.compose!
end
describe '#value' do
before { entry.compose! }
before do
entry.compose!
end
context 'when entry is correct' do
let(:config) do
......
......@@ -4,7 +4,9 @@ describe Gitlab::Ci::Config::Entry::Jobs do
let(:entry) { described_class.new(config) }
describe 'validations' do
before { entry.compose! }
before do
entry.compose!
end
context 'when entry config value is correct' do
let(:config) { { rspec: { script: 'rspec' } } }
......@@ -48,7 +50,9 @@ describe Gitlab::Ci::Config::Entry::Jobs do
end
context 'when valid job entries composed' do
before { entry.compose! }
before do
entry.compose!
end
let(:config) do
{ rspec: { script: 'rspec' },
......
......@@ -47,7 +47,9 @@ describe Gitlab::Ci::Status::Build::Cancelable do
describe '#has_action?' 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 }
end
......
......@@ -17,13 +17,17 @@ describe Gitlab::Ci::Status::Build::Common do
describe '#has_details?' 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 }
end
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 }
end
......
......@@ -6,7 +6,9 @@ describe Gitlab::Ci::Status::Build::Factory do
let(:status) { factory.fabricate! }
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
let(:build) { create(:ci_build, :success) }
......
......@@ -28,7 +28,9 @@ describe Gitlab::Ci::Status::Build::Play do
end
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 }
end
......
......@@ -47,7 +47,9 @@ describe Gitlab::Ci::Status::Build::Retryable do
describe '#has_action?' 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 }
end
......
......@@ -19,7 +19,9 @@ describe Gitlab::Ci::Status::Build::Stop do
describe '#has_action?' 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 }
end
......
......@@ -21,7 +21,9 @@ describe Gitlab::Ci::Status::External::Common do
describe '#has_details?' 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 }
end
......
......@@ -17,7 +17,9 @@ describe Gitlab::Ci::Status::Pipeline::Common do
describe '#has_details?' 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 }
end
......
......@@ -7,7 +7,9 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
)
end
before { allow(model).to receive(:puts) }
before do
allow(model).to receive(:puts)
end
describe '#add_concurrent_index' do
context 'outside a transaction' do
......
......@@ -53,14 +53,18 @@ describe Gitlab::Database, lib: true do
describe '.nulls_last_order' 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', 'DESC')).to eq 'column DESC NULLS LAST'}
end
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', 'DESC')).to eq 'column DESC'}
......@@ -69,14 +73,18 @@ describe Gitlab::Database, lib: true do
describe '.nulls_first_order' 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', 'DESC')).to eq 'column DESC NULLS FIRST'}
end
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', 'DESC')).to eq 'column IS NULL, column DESC'}
......
......@@ -114,7 +114,10 @@ describe Gitlab::Geo::OauthSession do
describe '#authenticate_with_gitlab' do
let(:response) { double }
before(:each) { allow_any_instance_of(OAuth2::AccessToken).to receive(:get) { response } }
before do
allow_any_instance_of(OAuth2::AccessToken).to receive(:get) { response }
end
context 'on success' do
it 'returns hashed user data' do
......
......@@ -6,10 +6,14 @@ describe Gitlab::Geo::UpdateQueue do
let(:dummy_data2) { { 'id' => 99, 'clone_url' => 'git@localhost:other_repo/path.git' } }
let(:multiple_dummy_data) { [dummy_data, dummy_data2] * 10 }
before(:each) { subject.empty! }
before do
subject.empty!
end
describe '#store' do
before(:each) { subject.store(dummy_data) }
before do
subject.store(dummy_data)
end
it 'stores data to the queue' do
expect(subject).not_to be_empty
......@@ -36,7 +40,9 @@ describe Gitlab::Geo::UpdateQueue do
end
describe '#fetch_batched_data' do
before(:each) { subject.store_batched_data(multiple_dummy_data) }
before do
subject.store_batched_data(multiple_dummy_data)
end
it 'returns same stored data' do
expect(subject.fetch_batched_data).to eq(multiple_dummy_data)
......@@ -59,7 +65,9 @@ describe Gitlab::Geo::UpdateQueue do
end
describe '#batch_size' do
before(:each) { allow(subject).to receive(:queue_size) { queue_size } }
before do
allow(subject).to receive(:queue_size) { queue_size }
end
context 'when queue size is smaller than BATCH_SIZE' do
let(:queue_size) { described_class::BATCH_SIZE - 20 }
......
......@@ -5,7 +5,9 @@ describe Gitlab::Geo, lib: true do
let(:secondary_node) { FactoryGirl.create(:geo_node) }
describe 'current_node' do
before(:each) { primary_node }
before do
primary_node
end
it 'returns a GeoNode instance' do
expect(described_class.current_node).to eq(primary_node)
......@@ -25,7 +27,9 @@ describe Gitlab::Geo, lib: true do
describe 'enabled?' do
context 'when any GeoNode exists' do
before(:each) { secondary_node }
before do
secondary_node
end
it 'returns true' do
expect(described_class.enabled?).to be_truthy
......@@ -58,7 +62,9 @@ describe Gitlab::Geo, lib: true do
describe 'readonly?' do
context 'when current node is secondary' do
before(:each) { secondary_node }
before do
secondary_node
end
it 'returns true' do
allow(described_class).to receive(:current_node) { secondary_node }
......@@ -67,7 +73,9 @@ describe Gitlab::Geo, lib: true do
end
context 'current node is primary' do
before(:each) { primary_node }
before do
primary_node
end
it 'returns false when ' do
allow(described_class).to receive(:current_node) { primary_node }
......
......@@ -6,7 +6,9 @@ describe Gitlab::Gfm::ReferenceRewriter do
let(:new_project) { create(:empty_project, name: 'new-project') }
let(:user) { create(:user) }
before { old_project.team << [user, :reporter] }
before do
old_project.team << [user, :reporter]
end
describe '#rewrite' do
subject do
......
......@@ -16,7 +16,9 @@ describe Gitlab::Git::Repository, seed_helper: true do
describe '#root_ref' 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
expect(repository).to receive(:discover_default_branch)
......@@ -25,8 +27,13 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
context 'with gitaly enabled' do
before { stub_gitaly }
after { Gitlab::GitalyClient.clear_stubs! }
before do
stub_gitaly
end
after do
Gitlab::GitalyClient.clear_stubs!
end
it 'gets the branch name from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name)
......@@ -120,8 +127,13 @@ describe Gitlab::Git::Repository, seed_helper: true do
it { is_expected.not_to include("branch-from-space") }
context 'with gitaly enabled' do
before { stub_gitaly }
after { Gitlab::GitalyClient.clear_stubs! }
before do
stub_gitaly
end
after do
Gitlab::GitalyClient.clear_stubs!
end
it 'gets the branch names from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names)
......@@ -158,8 +170,13 @@ describe Gitlab::Git::Repository, seed_helper: true do
it { is_expected.not_to include("v5.0.0") }
context 'with gitaly enabled' do
before { stub_gitaly }
after { Gitlab::GitalyClient.clear_stubs! }
before do
stub_gitaly
end
after do
Gitlab::GitalyClient.clear_stubs!
end
it 'gets the tag names from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names)
......@@ -1321,8 +1338,13 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
context 'with gitaly enabled' do
before { stub_gitaly }
after { Gitlab::GitalyClient.clear_stubs! }
before do
stub_gitaly
end
after do
Gitlab::GitalyClient.clear_stubs!
end
it 'gets the branches from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches).
......
......@@ -61,7 +61,9 @@ describe Gitlab::GitAccess, lib: true do
let(:actor) { deploy_key }
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
expect { pull_access_check }.not_to raise_error
......@@ -85,7 +87,9 @@ describe Gitlab::GitAccess, lib: true do
context 'when actor is a User' 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
expect { pull_access_check }.not_to raise_error
......@@ -160,7 +164,9 @@ describe Gitlab::GitAccess, lib: true do
end
describe '#check_command_disabled!' do
before { project.team << [user, :master] }
before do
project.team << [user, :master]
end
context 'over http' do
let(:protocol) { 'http' }
......@@ -197,7 +203,9 @@ describe Gitlab::GitAccess, lib: true do
describe '#check_download_access!' do
describe 'master permissions' do
before { project.team << [user, :master] }
before do
project.team << [user, :master]
end
context 'pull code' do
it { expect { pull_access_check }.not_to raise_error }
......@@ -205,7 +213,9 @@ describe Gitlab::GitAccess, lib: true do
end
describe 'guest permissions' do
before { project.team << [user, :guest] }
before do
project.team << [user, :guest]
end
context 'pull code' do
it { expect { pull_access_check }.to raise_unauthorized('You are not allowed to download code from this project.') }
......@@ -254,7 +264,9 @@ describe Gitlab::GitAccess, lib: true do
context 'pull code' 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 }
end
......@@ -304,7 +316,9 @@ describe Gitlab::GitAccess, lib: true do
end
describe 'reporter user' do
before { project.team << [user, :reporter] }
before do
project.team << [user, :reporter]
end
context 'pull code' do
it { expect { pull_access_check }.not_to raise_error }
......@@ -315,7 +329,9 @@ describe Gitlab::GitAccess, lib: true do
let(:user) { create(:admin) }
context 'when member of the project' do
before { project.team << [user, :reporter] }
before do
project.team << [user, :reporter]
end
context 'pull code' do
it { expect { pull_access_check }.not_to raise_error }
......@@ -340,9 +356,12 @@ describe Gitlab::GitAccess, lib: true do
end
describe '#check_push_access!' do
before { merge_into_protected_branch }
let(:unprotected_branch) { 'unprotected_branch' }
before do
merge_into_protected_branch
end
let(:changes) do
{ push_new_branch: "#{Gitlab::Git::BLANK_SHA} 570e7b2ab refs/heads/wow",
push_master: '6f6d7e7ed 570e7b2ab refs/heads/master',
......@@ -496,19 +515,25 @@ describe Gitlab::GitAccess, lib: true do
[%w(feature exact), ['feat*', 'wildcard']].each do |protected_branch_name, protected_branch_type|
context do
before { create(:protected_branch, :remove_default_access_levels, :masters_can_push, name: protected_branch_name, project: project) }
before do
create(:protected_branch, :remove_default_access_levels, :masters_can_push, name: protected_branch_name, project: project)
end
run_permission_checks(permissions_matrix)
end
context "when developers are allowed to push into the #{protected_branch_type} protected branch" do
before { create(:protected_branch, :remove_default_access_levels, :masters_can_push, :developers_can_push, name: protected_branch_name, project: project) }
before do
create(:protected_branch, :remove_default_access_levels, :masters_can_push, :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 }))
end
context "developers are allowed to merge into the #{protected_branch_type} protected branch" do
before { create(:protected_branch, :remove_default_access_levels, :masters_can_push, :developers_can_merge, name: protected_branch_name, project: project) }
before do
create(:protected_branch, :remove_default_access_levels, :masters_can_push, :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 the merge request is in progress" do
......@@ -535,7 +560,9 @@ describe Gitlab::GitAccess, lib: true do
end
context "when developers are allowed to push and merge into the #{protected_branch_type} protected branch" do
before { create(:protected_branch, :remove_default_access_levels, :masters_can_push, :developers_can_merge, :developers_can_push, name: protected_branch_name, project: project) }
before do
create(:protected_branch, :remove_default_access_levels, :masters_can_push, :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 }))
end
......@@ -636,7 +663,9 @@ describe Gitlab::GitAccess, lib: true do
end
context "when no one is allowed to push to the #{protected_branch_name} protected branch" do
before { create(:protected_branch, :remove_default_access_levels, :no_one_can_push, name: protected_branch_name, project: project) }
before do
create(:protected_branch, :remove_default_access_levels, :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 },
master: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false },
......@@ -830,7 +859,9 @@ describe Gitlab::GitAccess, lib: true do
let(:authentication_abilities) { build_authentication_abilities }
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.') }
end
......@@ -874,7 +905,9 @@ describe Gitlab::GitAccess, lib: true do
let(:can_push) { true }
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 }
end
......@@ -904,7 +937,9 @@ describe Gitlab::GitAccess, lib: true do
let(:can_push) { false }
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.') }
end
......
......@@ -5,7 +5,9 @@ require 'spec_helper'
describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do
describe '.stub' do
# 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
it 'passes the address as-is to GRPC' do
......@@ -41,7 +43,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do
let(:real_feature_name) { "gitaly_#{feature_name}" }
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
expect(described_class.feature_enabled?(feature_name)).to be(false)
......@@ -66,7 +70,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do
end
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
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
end
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
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
end
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
expect(Random).to receive(:rand).and_return(0.3)
......@@ -104,7 +114,9 @@ describe Gitlab::GitalyClient, lib: true, skip_gitaly_mock: true do
end
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
expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false)
......
......@@ -39,7 +39,9 @@ describe Gitlab::Highlight, lib: true do
Gitlab::Highlight.new(blob.path, blob.data, repository: repository)
end
before { project.change_head('gitattributes') }
before do
project.change_head('gitattributes')
end
describe 'basic language selection' do
let(:path) { 'custom-highlighting/test.gitlab-custom' }
......
......@@ -4,7 +4,9 @@ describe Gitlab::I18n, lib: true do
let(:user) { create(:user, preferred_language: 'es') }
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
described_class.locale = user.preferred_language
......
......@@ -291,7 +291,9 @@ describe Gitlab::LDAP::Access, lib: true do
end
context 'user has at least one LDAPKey' do
before { user.keys.ldap.create key: ssh_key, title: 'to be removed' }
before do
user.keys.ldap.create key: ssh_key, title: 'to be removed'
end
it "removes a SSH key if it is no longer in LDAP" do
entry = Net::LDAP::Entry.from_single_ldif_string("dn: cn=foo, dc=bar, dc=com\n#{ssh_key_attribute_name}:\n")
......
......@@ -79,13 +79,17 @@ describe Gitlab::LDAP::Adapter, lib: true do
subject { adapter.dn_matches_filter?(:dn, :filter) }
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 }
end
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 }
end
......@@ -96,13 +100,17 @@ describe Gitlab::LDAP::Adapter, lib: true do
context "when the search is successful" 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] }
end
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 [] }
end
......
......@@ -173,7 +173,9 @@ describe Gitlab::LDAP::User, lib: true do
context 'signup' do
context 'dont block on create' do
before { configure_block(false) }
before do
configure_block(false)
end
it do
ldap_user.save
......@@ -183,7 +185,9 @@ describe Gitlab::LDAP::User, lib: true do
end
context 'block on create' do
before { configure_block(true) }
before do
configure_block(true)
end
it do
ldap_user.save
......@@ -200,7 +204,9 @@ describe Gitlab::LDAP::User, lib: true do
end
context 'dont block on create' do
before { configure_block(false) }
before do
configure_block(false)
end
it do
ldap_user.save
......@@ -210,7 +216,9 @@ describe Gitlab::LDAP::User, lib: true do
end
context 'block on create' do
before { configure_block(true) }
before do
configure_block(true)
end
it do
ldap_user.save
......
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.
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