Commit b1b7fa78 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'blackst0ne-convert-specs-rails5-style' into 'master'

[Rails5.1] Update functional specs to use new keyword format

Closes #54062

See merge request gitlab-org/gitlab-ce!23095
parents fca9e0f3 b44a2c80
Pipeline #40667297 passed with stages
in 34 minutes and 8 seconds
......@@ -8,7 +8,7 @@ require:
- rubocop-rspec
AllCops:
TargetRailsVersion: 4.2
TargetRailsVersion: 5.0
Exclude:
- 'vendor/**/*'
- 'node_modules/**/*'
......
---
title: "[Rails5.1] Update functional specs to use new keyword format"
merge_request: 23095
author: "@blackst0ne"
type: other
......@@ -19,7 +19,7 @@ describe AbuseReportsController do
user_id = user.id
user.destroy
get :new, { user_id: user_id }
get :new, params: { user_id: user_id }
expect(response).to redirect_to root_path
expect(flash[:alert]).to eq('Cannot create the abuse report. The user has been deleted.')
......@@ -30,7 +30,7 @@ describe AbuseReportsController do
it 'redirects the reporter to the user\'s profile' do
user.block
get :new, { user_id: user.id }
get :new, params: { user_id: user.id }
expect(response).to redirect_to user
expect(flash[:alert]).to eq('Cannot create the abuse report. This user has been blocked.')
......@@ -42,18 +42,18 @@ describe AbuseReportsController do
context 'with valid attributes' do
it 'saves the abuse report' do
expect do
post :create, abuse_report: attrs
post :create, params: { abuse_report: attrs }
end.to change { AbuseReport.count }.by(1)
end
it 'calls notify' do
expect_any_instance_of(AbuseReport).to receive(:notify)
post :create, abuse_report: attrs
post :create, params: { abuse_report: attrs }
end
it 'redirects back to the reported user' do
post :create, abuse_report: attrs
post :create, params: { abuse_report: attrs }
expect(response).to redirect_to user
end
......@@ -62,7 +62,7 @@ describe AbuseReportsController do
context 'with invalid attributes' do
it 'renders new' do
attrs.delete(:user_id)
post :create, abuse_report: attrs
post :create, params: { abuse_report: attrs }
expect(response).to render_template(:new)
end
......
......@@ -52,35 +52,35 @@ describe Admin::ApplicationSettingsController do
end
it 'updates the password_authentication_enabled_for_git setting' do
put :update, application_setting: { password_authentication_enabled_for_git: "0" }
put :update, params: { application_setting: { password_authentication_enabled_for_git: "0" } }
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.password_authentication_enabled_for_git).to eq(false)
end
it 'updates the default_project_visibility for string value' do
put :update, application_setting: { default_project_visibility: "20" }
put :update, params: { application_setting: { default_project_visibility: "20" } }
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.default_project_visibility).to eq(Gitlab::VisibilityLevel::PUBLIC)
end
it 'update the restricted levels for string values' do
put :update, application_setting: { restricted_visibility_levels: %w[10 20] }
put :update, params: { application_setting: { restricted_visibility_levels: %w[10 20] } }
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.restricted_visibility_levels).to eq([10, 20])
end
it 'updates the restricted_visibility_levels when empty array is passed' do
put :update, application_setting: { restricted_visibility_levels: [""] }
put :update, params: { application_setting: { restricted_visibility_levels: [""] } }
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.restricted_visibility_levels).to be_empty
end
it 'updates the receive_max_input_size setting' do
put :update, application_setting: { receive_max_input_size: "1024" }
put :update, params: { application_setting: { receive_max_input_size: "1024" } }
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.receive_max_input_size).to eq(1024)
......
......@@ -19,7 +19,7 @@ describe Admin::ApplicationsController do
describe 'GET #edit' do
it 'renders the application form' do
get :edit, id: application.id
get :edit, params: { id: application.id }
expect(response).to render_template :edit
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
......@@ -31,7 +31,7 @@ describe Admin::ApplicationsController do
create_params = attributes_for(:application, trusted: true)
expect do
post :create, doorkeeper_application: create_params
post :create, params: { doorkeeper_application: create_params }
end.to change { Doorkeeper::Application.count }.by(1)
application = Doorkeeper::Application.last
......@@ -42,7 +42,7 @@ describe Admin::ApplicationsController do
it 'renders the application form on errors' do
expect do
post :create, doorkeeper_application: attributes_for(:application).merge(redirect_uri: nil)
post :create, params: { doorkeeper_application: attributes_for(:application).merge(redirect_uri: nil) }
end.not_to change { Doorkeeper::Application.count }
expect(response).to render_template :new
......@@ -52,7 +52,7 @@ describe Admin::ApplicationsController do
describe 'PATCH #update' do
it 'updates the application' do
patch :update, id: application.id, doorkeeper_application: { redirect_uri: 'http://example.com/', trusted: true }
patch :update, params: { id: application.id, doorkeeper_application: { redirect_uri: 'http://example.com/', trusted: true } }
application.reload
......@@ -61,7 +61,7 @@ describe Admin::ApplicationsController do
end
it 'renders the application form on errors' do
patch :update, id: application.id, doorkeeper_application: { redirect_uri: nil }
patch :update, params: { id: application.id, doorkeeper_application: { redirect_uri: nil } }
expect(response).to render_template :edit
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
......
......@@ -12,12 +12,12 @@ describe Admin::GroupsController do
describe 'DELETE #destroy' do
it 'schedules a group destroy' do
Sidekiq::Testing.fake! do
expect { delete :destroy, id: project.group.path }.to change(GroupDestroyWorker.jobs, :size).by(1)
expect { delete :destroy, params: { id: project.group.path } }.to change(GroupDestroyWorker.jobs, :size).by(1)
end
end
it 'redirects to the admin group path' do
delete :destroy, id: project.group.path
delete :destroy, params: { id: project.group.path }
expect(response).to redirect_to(admin_groups_path)
end
......@@ -27,9 +27,11 @@ describe Admin::GroupsController do
let(:group_user) { create(:user) }
it 'adds user to members' do
put :members_update, id: group,
user_ids: group_user.id,
access_level: Gitlab::Access::GUEST
put :members_update, params: {
id: group,
user_ids: group_user.id,
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(admin_group_path(group))
......@@ -37,18 +39,22 @@ describe Admin::GroupsController do
end
it 'can add unlimited members' do
put :members_update, id: group,
user_ids: 1.upto(1000).to_a.join(','),
access_level: Gitlab::Access::GUEST
put :members_update, params: {
id: group,
user_ids: 1.upto(1000).to_a.join(','),
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(admin_group_path(group))
end
it 'adds no user to members' do
put :members_update, id: group,
user_ids: '',
access_level: Gitlab::Access::GUEST
put :members_update, params: {
id: group,
user_ids: '',
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'No users specified.'
expect(response).to redirect_to(admin_group_path(group))
......
......@@ -20,7 +20,7 @@ describe Admin::HooksController do
merge_requests_events: true
}
post :create, hook: hook_params
post :create, params: { hook: hook_params }
expect(response).to have_gitlab_http_status(302)
expect(SystemHook.all.size).to eq(1)
......
......@@ -13,7 +13,7 @@ describe Admin::IdentitiesController do
it 'repairs ldap blocks' do
expect_any_instance_of(RepairLdapBlockedUserService).to receive(:execute)
put :update, user_id: user.username, id: user.ldap_identity.id, identity: { provider: 'twitter' }
put :update, params: { user_id: user.username, id: user.ldap_identity.id, identity: { provider: 'twitter' } }
end
end
......@@ -23,7 +23,7 @@ describe Admin::IdentitiesController do
it 'repairs ldap blocks' do
expect_any_instance_of(RepairLdapBlockedUserService).to receive(:execute)
delete :destroy, user_id: user.username, id: user.ldap_identity.id
delete :destroy, params: { user_id: user.username, id: user.ldap_identity.id }
end
end
end
......@@ -11,13 +11,13 @@ describe Admin::ProjectsController do
render_views
it 'retrieves the project for the given visibility level' do
get :index, visibility_level: [Gitlab::VisibilityLevel::PUBLIC]
get :index, params: { visibility_level: [Gitlab::VisibilityLevel::PUBLIC] }
expect(response.body).to match(project.name)
end
it 'does not retrieve the project' do
get :index, visibility_level: [Gitlab::VisibilityLevel::INTERNAL]
get :index, params: { visibility_level: [Gitlab::VisibilityLevel::INTERNAL] }
expect(response.body).not_to match(project.name)
end
......@@ -47,7 +47,7 @@ describe Admin::ProjectsController do
render_views
it 'renders show page' do
get :show, namespace_id: project.namespace.path, id: project.path
get :show, params: { namespace_id: project.namespace.path, id: project.path }
expect(response).to have_gitlab_http_status(200)
expect(response.body).to match(project.name)
......
......@@ -17,13 +17,13 @@ describe Admin::RunnersController do
describe '#show' do
it 'shows a particular runner' do
get :show, id: runner.id
get :show, params: { id: runner.id }
expect(response).to have_gitlab_http_status(200)
end
it 'shows 404 for unknown runner' do
get :show, id: 0
get :show, params: { id: 0 }
expect(response).to have_gitlab_http_status(404)
end
......@@ -34,7 +34,7 @@ describe Admin::RunnersController do
new_desc = runner.description.swapcase
expect do
post :update, id: runner.id, runner: { description: new_desc }
post :update, params: { id: runner.id, runner: { description: new_desc } }
end.to change { runner.ensure_runner_queue_value }
runner.reload
......@@ -46,7 +46,7 @@ describe Admin::RunnersController do
describe '#destroy' do
it 'destroys the runner' do
delete :destroy, id: runner.id
delete :destroy, params: { id: runner.id }
expect(response).to have_gitlab_http_status(302)
expect(Ci::Runner.find_by(id: runner.id)).to be_nil
......@@ -58,7 +58,7 @@ describe Admin::RunnersController do
runner.update(active: false)
expect do
post :resume, id: runner.id
post :resume, params: { id: runner.id }
end.to change { runner.ensure_runner_queue_value }
runner.reload
......@@ -73,7 +73,7 @@ describe Admin::RunnersController do
runner.update(active: true)
expect do
post :pause, id: runner.id
post :pause, params: { id: runner.id }
end.to change { runner.ensure_runner_queue_value }
runner.reload
......
......@@ -18,7 +18,7 @@ describe Admin::ServicesController do
end
it 'successfully displays the template' do
get :edit, id: service.id
get :edit, params: { id: service.id }
expect(response).to have_gitlab_http_status(200)
end
......@@ -44,7 +44,7 @@ describe Admin::ServicesController do
it 'calls the propagation worker when service is active' do
expect(PropagateServiceTemplateWorker).to receive(:perform_async).with(service.id)
put :update, id: service.id, service: { active: true }
put :update, params: { id: service.id, service: { active: true } }
expect(response).to have_gitlab_http_status(302)
end
......@@ -52,7 +52,7 @@ describe Admin::ServicesController do
it 'does not call the propagation worker when service is not active' do
expect(PropagateServiceTemplateWorker).not_to receive(:perform_async)
put :update, id: service.id, service: { properties: {} }
put :update, params: { id: service.id, service: { properties: {} } }
expect(response).to have_gitlab_http_status(302)
end
......
......@@ -20,13 +20,13 @@ describe Admin::SpamLogsController do
describe '#destroy' do
it 'removes only the spam log when removing log' do
expect { delete :destroy, id: first_spam.id }.to change { SpamLog.count }.by(-1)
expect { delete :destroy, params: { id: first_spam.id } }.to change { SpamLog.count }.by(-1)
expect(User.find(user.id)).to be_truthy
expect(response).to have_gitlab_http_status(200)
end
it 'removes user and his spam logs when removing the user' do
delete :destroy, id: first_spam.id, remove_user: true
delete :destroy, params: { id: first_spam.id, remove_user: true }
expect(flash[:notice]).to eq "User #{user.username} was successfully removed."
expect(response).to have_gitlab_http_status(302)
......@@ -40,7 +40,7 @@ describe Admin::SpamLogsController do
allow_any_instance_of(AkismetService).to receive(:submit_ham).and_return(true)
end
it 'submits the log as ham' do
post :mark_as_ham, id: first_spam.id
post :mark_as_ham, params: { id: first_spam.id }
expect(response).to have_gitlab_http_status(302)
expect(SpamLog.find(first_spam.id).submitted_as_ham).to be_truthy
......
......@@ -17,7 +17,7 @@ describe Admin::UsersController do
end
it 'deletes user and ghosts their contributions' do
delete :destroy, id: user.username, format: :json
delete :destroy, params: { id: user.username }, format: :json
expect(response).to have_gitlab_http_status(200)
expect(User.exists?(user.id)).to be_falsy
......@@ -25,7 +25,7 @@ describe Admin::UsersController do
end
it 'deletes the user and their contributions when hard delete is specified' do
delete :destroy, id: user.username, hard_delete: true, format: :json
delete :destroy, params: { id: user.username, hard_delete: true }, format: :json
expect(response).to have_gitlab_http_status(200)
expect(User.exists?(user.id)).to be_falsy
......@@ -35,7 +35,7 @@ describe Admin::UsersController do
describe 'PUT block/:id' do
it 'blocks user' do
put :block, id: user.username
put :block, params: { id: user.username }
user.reload
expect(user.blocked?).to be_truthy
expect(flash[:notice]).to eq 'Successfully blocked'
......@@ -51,7 +51,7 @@ describe Admin::UsersController do
end
it 'does not unblock user' do
put :unblock, id: user.username
put :unblock, params: { id: user.username }
user.reload
expect(user.blocked?).to be_truthy
expect(flash[:alert]).to eq 'This user cannot be unlocked manually from GitLab'
......@@ -64,7 +64,7 @@ describe Admin::UsersController do
end
it 'unblocks user' do
put :unblock, id: user.username
put :unblock, params: { id: user.username }
user.reload
expect(user.blocked?).to be_falsey
expect(flash[:notice]).to eq 'Successfully unblocked'
......@@ -79,7 +79,7 @@ describe Admin::UsersController do
end
it 'unlocks user' do
put :unlock, id: user.username
put :unlock, params: { id: user.username }
user.reload
expect(user.access_locked?).to be_falsey
end
......@@ -93,7 +93,7 @@ describe Admin::UsersController do
end
it 'confirms user' do
put :confirm, id: user.username
put :confirm, params: { id: user.username }
user.reload
expect(user.confirmed?).to be_truthy
end
......@@ -121,17 +121,17 @@ describe Admin::UsersController do
end
def go
patch :disable_two_factor, id: user.to_param
patch :disable_two_factor, params: { id: user.to_param }
end
end
describe 'POST create' do
it 'creates the user' do
expect { post :create, user: attributes_for(:user) }.to change { User.count }.by(1)
expect { post :create, params: { user: attributes_for(:user) } }.to change { User.count }.by(1)
end
it 'shows only one error message for an invalid email' do
post :create, user: attributes_for(:user, email: 'bogus')
post :create, params: { user: attributes_for(:user, email: 'bogus') }
expect(assigns[:user].errors).to contain_exactly("Email is invalid")
end
end
......@@ -147,7 +147,7 @@ describe Admin::UsersController do
}
}
post :update, params
post :update, params: params
end
context 'when the admin changes his own password' do
......@@ -227,13 +227,13 @@ describe Admin::UsersController do
end
it "shows a notice" do
post :impersonate, id: user.username
post :impersonate, params: { id: user.username }
expect(flash[:alert]).to eq("You cannot impersonate a blocked user")
end
it "doesn't sign us in as the user" do
post :impersonate, id: user.username
post :impersonate, params: { id: user.username }
expect(warden.user).to eq(admin)
end
......@@ -241,25 +241,25 @@ describe Admin::UsersController do
context "when the user is not blocked" do
it "stores the impersonator in the session" do
post :impersonate, id: user.username
post :impersonate, params: { id: user.username }
expect(session[:impersonator_id]).to eq(admin.id)
end
it "signs us in as the user" do
post :impersonate, id: user.username
post :impersonate, params: { id: user.username }
expect(warden.user).to eq(user)
end
it "redirects to root" do
post :impersonate, id: user.username
post :impersonate, params: { id: user.username }
expect(response).to redirect_to(root_path)
end
it "shows a notice" do
post :impersonate, id: user.username
post :impersonate, params: { id: user.username }
expect(flash[:alert]).to eq("You are now impersonating #{user.username}")
end
......@@ -271,7 +271,7 @@ describe Admin::UsersController do
end
it "shows error page" do
post :impersonate, id: user.username
post :impersonate, params: { id: user.username }
expect(response).to have_gitlab_http_status(404)
end
......
......@@ -522,13 +522,13 @@ describe ApplicationController do
end
it 'renders a 403 when a message is passed to access denied' do
get :index, message: 'None shall pass'
get :index, params: { message: 'None shall pass' }
expect(response).to have_gitlab_http_status(403)
end
it 'renders a status passed to access denied' do
get :index, status: 401
get :index, params: { status: 401 }
expect(response).to have_gitlab_http_status(401)
end
......@@ -548,7 +548,7 @@ describe ApplicationController do
end
context 'html' do
subject { get :index, text: "hi \255" }
subject { get :index, params: { text: "hi \255" } }
it 'renders 412' do
expect { subject }.to raise_error(ActionController::BadRequest)
......@@ -556,7 +556,7 @@ describe ApplicationController do
end
context 'js' do
subject { get :index, text: "hi \255", format: :js }
subject { get :index, format: :js, params: { text: "hi \255" } }
it 'renders 412' do
expect { subject }.to raise_error(ActionController::BadRequest)
......
......@@ -15,7 +15,7 @@ describe AutocompleteController do
describe 'GET #users with project ID' do
before do
get(:users, project_id: project.id)
get(:users, params: { project_id: project.id })
end
it 'returns the project members' do
......@@ -27,7 +27,7 @@ describe AutocompleteController do
describe 'GET #users with unknown project' do
before do
get(:users, project_id: 'unknown')
get(:users, params: { project_id: 'unknown' })
end
it { expect(response).to have_gitlab_http_status(404) }
......@@ -44,7 +44,7 @@ describe AutocompleteController do
describe 'GET #users with group ID' do
before do
get(:users, group_id: group.id)
get(:users, params: { group_id: group.id })
end
it 'returns the group members' do
......@@ -56,7 +56,7 @@ describe AutocompleteController do
describe 'GET #users with unknown group ID' do
before do
get(:users, group_id: 'unknown')
get(:users, params: { group_id: 'unknown' })
end
it { expect(response).to have_gitlab_http_status(404) }
......@@ -72,7 +72,7 @@ describe AutocompleteController do
describe 'GET #users with project ID' do
before do
get(:users, project_id: project.id, current_user: true)
get(:users, params: { project_id: project.id, current_user: true })