Commit b44a2c80 authored by blackst0ne's avatar blackst0ne

Update specs to rails5 format

Updates specs to use new rails5 format.

The old format:
`get :show, { some: params }, { some: headers }`

The new format:
`get :show, params: { some: params }, headers: { some: headers }`
parent 5d68c237
...@@ -8,7 +8,7 @@ require: ...@@ -8,7 +8,7 @@ require:
- rubocop-rspec - rubocop-rspec
AllCops: AllCops:
TargetRailsVersion: 4.2 TargetRailsVersion: 5.0
Exclude: Exclude:
- 'vendor/**/*' - 'vendor/**/*'
- 'node_modules/**/*' - '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 ...@@ -19,7 +19,7 @@ describe AbuseReportsController do
user_id = user.id user_id = user.id
user.destroy user.destroy
get :new, { user_id: user_id } get :new, params: { user_id: user_id }
expect(response).to redirect_to root_path expect(response).to redirect_to root_path
expect(flash[:alert]).to eq('Cannot create the abuse report. The user has been deleted.') expect(flash[:alert]).to eq('Cannot create the abuse report. The user has been deleted.')
...@@ -30,7 +30,7 @@ describe AbuseReportsController do ...@@ -30,7 +30,7 @@ describe AbuseReportsController do
it 'redirects the reporter to the user\'s profile' do it 'redirects the reporter to the user\'s profile' do
user.block user.block
get :new, { user_id: user.id } get :new, params: { user_id: user.id }
expect(response).to redirect_to user expect(response).to redirect_to user
expect(flash[:alert]).to eq('Cannot create the abuse report. This user has been blocked.') expect(flash[:alert]).to eq('Cannot create the abuse report. This user has been blocked.')
...@@ -42,18 +42,18 @@ describe AbuseReportsController do ...@@ -42,18 +42,18 @@ describe AbuseReportsController do
context 'with valid attributes' do context 'with valid attributes' do
it 'saves the abuse report' do it 'saves the abuse report' do
expect do expect do
post :create, abuse_report: attrs post :create, params: { abuse_report: attrs }
end.to change { AbuseReport.count }.by(1) end.to change { AbuseReport.count }.by(1)
end end
it 'calls notify' do it 'calls notify' do
expect_any_instance_of(AbuseReport).to receive(:notify) expect_any_instance_of(AbuseReport).to receive(:notify)
post :create, abuse_report: attrs post :create, params: { abuse_report: attrs }
end end
it 'redirects back to the reported user' do 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 expect(response).to redirect_to user
end end
...@@ -62,7 +62,7 @@ describe AbuseReportsController do ...@@ -62,7 +62,7 @@ describe AbuseReportsController do
context 'with invalid attributes' do context 'with invalid attributes' do
it 'renders new' do it 'renders new' do
attrs.delete(:user_id) attrs.delete(:user_id)
post :create, abuse_report: attrs post :create, params: { abuse_report: attrs }
expect(response).to render_template(:new) expect(response).to render_template(:new)
end end
......
...@@ -52,35 +52,35 @@ describe Admin::ApplicationSettingsController do ...@@ -52,35 +52,35 @@ describe Admin::ApplicationSettingsController do
end end
it 'updates the password_authentication_enabled_for_git setting' do 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(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.password_authentication_enabled_for_git).to eq(false) expect(ApplicationSetting.current.password_authentication_enabled_for_git).to eq(false)
end end
it 'updates the default_project_visibility for string value' do 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(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.default_project_visibility).to eq(Gitlab::VisibilityLevel::PUBLIC) expect(ApplicationSetting.current.default_project_visibility).to eq(Gitlab::VisibilityLevel::PUBLIC)
end end
it 'update the restricted levels for string values' do 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(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.restricted_visibility_levels).to eq([10, 20]) expect(ApplicationSetting.current.restricted_visibility_levels).to eq([10, 20])
end end
it 'updates the restricted_visibility_levels when empty array is passed' do 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(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.restricted_visibility_levels).to be_empty expect(ApplicationSetting.current.restricted_visibility_levels).to be_empty
end end
it 'updates the receive_max_input_size setting' do 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(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.receive_max_input_size).to eq(1024) expect(ApplicationSetting.current.receive_max_input_size).to eq(1024)
......
...@@ -19,7 +19,7 @@ describe Admin::ApplicationsController do ...@@ -19,7 +19,7 @@ describe Admin::ApplicationsController do
describe 'GET #edit' do describe 'GET #edit' do
it 'renders the application form' 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(response).to render_template :edit
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes) expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
...@@ -31,7 +31,7 @@ describe Admin::ApplicationsController do ...@@ -31,7 +31,7 @@ describe Admin::ApplicationsController do
create_params = attributes_for(:application, trusted: true) create_params = attributes_for(:application, trusted: true)
expect do expect do
post :create, doorkeeper_application: create_params post :create, params: { doorkeeper_application: create_params }
end.to change { Doorkeeper::Application.count }.by(1) end.to change { Doorkeeper::Application.count }.by(1)
application = Doorkeeper::Application.last application = Doorkeeper::Application.last
...@@ -42,7 +42,7 @@ describe Admin::ApplicationsController do ...@@ -42,7 +42,7 @@ describe Admin::ApplicationsController do
it 'renders the application form on errors' do it 'renders the application form on errors' do
expect 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 } end.not_to change { Doorkeeper::Application.count }
expect(response).to render_template :new expect(response).to render_template :new
...@@ -52,7 +52,7 @@ describe Admin::ApplicationsController do ...@@ -52,7 +52,7 @@ describe Admin::ApplicationsController do
describe 'PATCH #update' do describe 'PATCH #update' do
it 'updates the application' 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 application.reload
...@@ -61,7 +61,7 @@ describe Admin::ApplicationsController do ...@@ -61,7 +61,7 @@ describe Admin::ApplicationsController do
end end
it 'renders the application form on errors' do 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(response).to render_template :edit
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes) expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
......
...@@ -12,12 +12,12 @@ describe Admin::GroupsController do ...@@ -12,12 +12,12 @@ describe Admin::GroupsController do
describe 'DELETE #destroy' do describe 'DELETE #destroy' do
it 'schedules a group destroy' do it 'schedules a group destroy' do
Sidekiq::Testing.fake! 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
end end
it 'redirects to the admin group path' do 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) expect(response).to redirect_to(admin_groups_path)
end end
...@@ -27,9 +27,11 @@ describe Admin::GroupsController do ...@@ -27,9 +27,11 @@ describe Admin::GroupsController do
let(:group_user) { create(:user) } let(:group_user) { create(:user) }
it 'adds user to members' do it 'adds user to members' do
put :members_update, id: group, put :members_update, params: {
user_ids: group_user.id, id: group,
access_level: Gitlab::Access::GUEST user_ids: group_user.id,
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'Users were successfully added.' expect(response).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(admin_group_path(group)) expect(response).to redirect_to(admin_group_path(group))
...@@ -37,18 +39,22 @@ describe Admin::GroupsController do ...@@ -37,18 +39,22 @@ describe Admin::GroupsController do
end end
it 'can add unlimited members' do it 'can add unlimited members' do
put :members_update, id: group, put :members_update, params: {
user_ids: 1.upto(1000).to_a.join(','), id: group,
access_level: Gitlab::Access::GUEST 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 set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(admin_group_path(group)) expect(response).to redirect_to(admin_group_path(group))
end end
it 'adds no user to members' do it 'adds no user to members' do
put :members_update, id: group, put :members_update, params: {
user_ids: '', id: group,
access_level: Gitlab::Access::GUEST user_ids: '',
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'No users specified.' expect(response).to set_flash.to 'No users specified.'
expect(response).to redirect_to(admin_group_path(group)) expect(response).to redirect_to(admin_group_path(group))
......
...@@ -20,7 +20,7 @@ describe Admin::HooksController do ...@@ -20,7 +20,7 @@ describe Admin::HooksController do
merge_requests_events: true merge_requests_events: true
} }
post :create, hook: hook_params post :create, params: { hook: hook_params }
expect(response).to have_gitlab_http_status(302) expect(response).to have_gitlab_http_status(302)
expect(SystemHook.all.size).to eq(1) expect(SystemHook.all.size).to eq(1)
......
...@@ -13,7 +13,7 @@ describe Admin::IdentitiesController do ...@@ -13,7 +13,7 @@ describe Admin::IdentitiesController do
it 'repairs ldap blocks' do it 'repairs ldap blocks' do
expect_any_instance_of(RepairLdapBlockedUserService).to receive(:execute) 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
end end
...@@ -23,7 +23,7 @@ describe Admin::IdentitiesController do ...@@ -23,7 +23,7 @@ describe Admin::IdentitiesController do
it 'repairs ldap blocks' do it 'repairs ldap blocks' do
expect_any_instance_of(RepairLdapBlockedUserService).to receive(:execute) 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 end
end end
...@@ -11,13 +11,13 @@ describe Admin::ProjectsController do ...@@ -11,13 +11,13 @@ describe Admin::ProjectsController do
render_views render_views
it 'retrieves the project for the given visibility level' do 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) expect(response.body).to match(project.name)
end end
it 'does not retrieve the project' do 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) expect(response.body).not_to match(project.name)
end end
...@@ -47,7 +47,7 @@ describe Admin::ProjectsController do ...@@ -47,7 +47,7 @@ describe Admin::ProjectsController do
render_views render_views
it 'renders show page' do 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).to have_gitlab_http_status(200)
expect(response.body).to match(project.name) expect(response.body).to match(project.name)
......
...@@ -17,13 +17,13 @@ describe Admin::RunnersController do ...@@ -17,13 +17,13 @@ describe Admin::RunnersController do
describe '#show' do describe '#show' do
it 'shows a particular runner' 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) expect(response).to have_gitlab_http_status(200)
end end
it 'shows 404 for unknown runner' do it 'shows 404 for unknown runner' do
get :show, id: 0 get :show, params: { id: 0 }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
...@@ -34,7 +34,7 @@ describe Admin::RunnersController do ...@@ -34,7 +34,7 @@ describe Admin::RunnersController do
new_desc = runner.description.swapcase new_desc = runner.description.swapcase
expect do 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 } end.to change { runner.ensure_runner_queue_value }
runner.reload runner.reload
...@@ -46,7 +46,7 @@ describe Admin::RunnersController do ...@@ -46,7 +46,7 @@ describe Admin::RunnersController do
describe '#destroy' do describe '#destroy' do
it 'destroys the runner' 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(response).to have_gitlab_http_status(302)
expect(Ci::Runner.find_by(id: runner.id)).to be_nil expect(Ci::Runner.find_by(id: runner.id)).to be_nil
...@@ -58,7 +58,7 @@ describe Admin::RunnersController do ...@@ -58,7 +58,7 @@ describe Admin::RunnersController do
runner.update(active: false) runner.update(active: false)
expect do expect do
post :resume, id: runner.id post :resume, params: { id: runner.id }
end.to change { runner.ensure_runner_queue_value } end.to change { runner.ensure_runner_queue_value }
runner.reload runner.reload
...@@ -73,7 +73,7 @@ describe Admin::RunnersController do ...@@ -73,7 +73,7 @@ describe Admin::RunnersController do
runner.update(active: true) runner.update(active: true)
expect do expect do
post :pause, id: runner.id post :pause, params: { id: runner.id }
end.to change { runner.ensure_runner_queue_value } end.to change { runner.ensure_runner_queue_value }
runner.reload runner.reload
......
...@@ -18,7 +18,7 @@ describe Admin::ServicesController do ...@@ -18,7 +18,7 @@ describe Admin::ServicesController do
end end
it 'successfully displays the template' do 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) expect(response).to have_gitlab_http_status(200)
end end
...@@ -44,7 +44,7 @@ describe Admin::ServicesController do ...@@ -44,7 +44,7 @@ describe Admin::ServicesController do
it 'calls the propagation worker when service is active' do it 'calls the propagation worker when service is active' do
expect(PropagateServiceTemplateWorker).to receive(:perform_async).with(service.id) 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) expect(response).to have_gitlab_http_status(302)
end end
...@@ -52,7 +52,7 @@ describe Admin::ServicesController do ...@@ -52,7 +52,7 @@ describe Admin::ServicesController do
it 'does not call the propagation worker when service is not active' do it 'does not call the propagation worker when service is not active' do
expect(PropagateServiceTemplateWorker).not_to receive(:perform_async) 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) expect(response).to have_gitlab_http_status(302)
end end
......
...@@ -20,13 +20,13 @@ describe Admin::SpamLogsController do ...@@ -20,13 +20,13 @@ describe Admin::SpamLogsController do
describe '#destroy' do describe '#destroy' do
it 'removes only the spam log when removing log' 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(User.find(user.id)).to be_truthy
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
end end
it 'removes user and his spam logs when removing the user' do 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(flash[:notice]).to eq "User #{user.username} was successfully removed."
expect(response).to have_gitlab_http_status(302) expect(response).to have_gitlab_http_status(302)
...@@ -40,7 +40,7 @@ describe Admin::SpamLogsController do ...@@ -40,7 +40,7 @@ describe Admin::SpamLogsController do
allow_any_instance_of(AkismetService).to receive(:submit_ham).and_return(true) allow_any_instance_of(AkismetService).to receive(:submit_ham).and_return(true)
end end
it 'submits the log as ham' do 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(response).to have_gitlab_http_status(302)
expect(SpamLog.find(first_spam.id).submitted_as_ham).to be_truthy expect(SpamLog.find(first_spam.id).submitted_as_ham).to be_truthy
......
...@@ -17,7 +17,7 @@ describe Admin::UsersController do ...@@ -17,7 +17,7 @@ describe Admin::UsersController do
end end
it 'deletes user and ghosts their contributions' do 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(response).to have_gitlab_http_status(200)
expect(User.exists?(user.id)).to be_falsy expect(User.exists?(user.id)).to be_falsy
...@@ -25,7 +25,7 @@ describe Admin::UsersController do ...@@ -25,7 +25,7 @@ describe Admin::UsersController do
end end
it 'deletes the user and their contributions when hard delete is specified' do 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(response).to have_gitlab_http_status(200)
expect(User.exists?(user.id)).to be_falsy expect(User.exists?(user.id)).to be_falsy
...@@ -35,7 +35,7 @@ describe Admin::UsersController do ...@@ -35,7 +35,7 @@ describe Admin::UsersController do
describe 'PUT block/:id' do describe 'PUT block/:id' do
it 'blocks user' do it 'blocks user' do
put :block, id: user.username put :block, params: { id: user.username }
user.reload user.reload
expect(user.blocked?).to be_truthy expect(user.blocked?).to be_truthy