Commit a6ec5121 authored by Robert Speicher's avatar Robert Speicher

Correct RSpec/SingleLineHook cop offenses

parent 69ad827e
......@@ -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') }
......
......@@ -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) }
......
......@@ -200,7 +200,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
......@@ -134,7 +150,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
......@@ -144,7 +162,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
......@@ -159,7 +179,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
......@@ -174,7 +196,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
......@@ -186,7 +210,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
......@@ -197,7 +223,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(Gitlab::Recaptcha).to receive(:load_configurations!).and_return(true)
......@@ -620,14 +626,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)
......@@ -739,7 +749,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)
......@@ -751,7 +764,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
......
......@@ -19,7 +19,10 @@ describe Projects::MergeRequestsController do
render_views
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
it 'renders new merge request widget template' do
......@@ -328,7 +331,9 @@ describe Projects::MergeRequestsController do
end
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
expect(json_response).to eq('status' => 'sha_mismatch')
......@@ -473,7 +478,9 @@ describe Projects::MergeRequestsController do
let(:namespace) { create(:namespace, owner: owner) }
let(:project) { create(:project, namespace: namespace) }
before { sign_in owner }
before do
sign_in owner
end
it "deletes the merge request" do
delete :destroy, namespace_id: project.namespace, project_id: project, id: merge_request.iid
......@@ -505,7 +512,9 @@ describe Projects::MergeRequestsController do
context 'with default params' do
context 'as html' do
before { go(format: 'html') }
before do
go(format: 'html')
end
it 'renders the diff template' do
expect(response).to render_template('diffs')
......@@ -513,7 +522,9 @@ describe Projects::MergeRequestsController do
end
context 'as json' do
before { go(format: 'json') }
before do
go(format: 'json')
end
it 'renders the diffs template to a string' do
expect(response).to render_template('projects/merge_requests/show/_diffs')
......@@ -544,7 +555,9 @@ describe Projects::MergeRequestsController do
context 'with ignore_whitespace_change' 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
expect(response).to render_template('diffs')
......@@ -552,7 +565,9 @@ describe Projects::MergeRequestsController do
end
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
expect(response).to render_template('projects/merge_requests/show/_diffs')
......@@ -562,7 +577,9 @@ describe Projects::MergeRequestsController do
end
context 'with view' do
before { go(view: 'parallel') }
before do
go(view: 'parallel')
end
it 'saves the preferred diff view in a cookie' do
expect(response.cookies['diff_view']).to eq('parallel')
......@@ -605,7 +622,9 @@ describe Projects::MergeRequestsController do
end
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
expect(response).to have_http_status(404)
......@@ -626,7 +645,9 @@ describe Projects::MergeRequestsController do
end
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
expect(response).to have_http_status(404)
......@@ -670,7 +691,9 @@ describe Projects::MergeRequestsController do
context 'when the source branch is in a different project to the target' do
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
it 'disables diff notes' do
......@@ -690,7 +713,9 @@ describe Projects::MergeRequestsController do
end
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
expect(response).to have_http_status(404)
......@@ -913,7 +938,9 @@ describe Projects::MergeRequestsController do
end
context 'when the file does not exist cannot be resolved in the UI' do