Skip to content
Snippets Groups Projects
Commit 77b85029 authored by blackst0ne's avatar blackst0ne
Browse files

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 2188cd1c
No related branches found
No related tags found
No related merge requests found
Showing
with 86 additions and 71 deletions
Loading
Loading
@@ -8,7 +8,7 @@ require:
- rubocop-rspec
 
AllCops:
TargetRailsVersion: 4.2
TargetRailsVersion: 5.0
Exclude:
- 'vendor/**/*'
- 'node_modules/**/*'
Loading
Loading
---
title: "[Rails5.1] Update functional specs to use new keyword format"
merge_request: 23095
author: "@blackst0ne"
type: other
Loading
Loading
@@ -23,7 +23,7 @@
it 'creates appearance with footer and header message' do
stub_licensed_features(system_header_footer: true)
 
post :create, appearance: create_params
post :create, params: { appearance: create_params }
 
expect(Appearance.current).to have_attributes(
header_message: header_message,
Loading
Loading
@@ -36,7 +36,7 @@
it 'does not create appearance with footer and header message' do
stub_licensed_features(system_header_footer: false)
 
post :create, appearance: create_params
post :create, params: { appearance: create_params }
 
expect(Appearance.current).to have_attributes(
header_message: nil,
Loading
Loading
@@ -64,7 +64,7 @@
it 'updates appearance with footer and header message' do
stub_licensed_features(system_header_footer: true)
 
put :update, appearance: update_params
put :update, params: { appearance: update_params }
 
expect(Appearance.current).to have_attributes(
header_message: header_message,
Loading
Loading
@@ -77,7 +77,7 @@
it 'does not update appearance with footer and header message' do
stub_licensed_features(system_header_footer: false)
 
post :create, appearance: update_params
post :create, params: { appearance: update_params }
 
expect(Appearance.current).to have_attributes(
header_message: nil,
Loading
Loading
Loading
Loading
@@ -37,7 +37,7 @@
allow_group_owners_to_manage_ldap: false
}
 
put :update, application_setting: settings
put :update, params: { application_setting: settings }
 
expect(response).to redirect_to(admin_application_settings_path)
settings.except(:elasticsearch_url, :repository_size_limit).each do |setting, value|
Loading
Loading
@@ -52,14 +52,14 @@
stub_licensed_features(feature => false)
attribute_names = settings.keys.map(&:to_s)
 
expect { put :update, application_setting: settings }
expect { put :update, params: { application_setting: settings } }
.not_to change { ApplicationSetting.current.reload.attributes.slice(*attribute_names) }
end
 
it 'updates settings when the feature is available' do
stub_licensed_features(feature => true)
 
put :update, application_setting: settings
put :update, params: { application_setting: settings }
 
settings.each do |attribute, value|
expect(ApplicationSetting.current.public_send(attribute)).to eq(value)
Loading
Loading
@@ -114,35 +114,35 @@
 
it 'updates the default_project_creation for string value' do
stub_licensed_features(project_creation_level: true)
put :update, application_setting: { default_project_creation: ::EE::Gitlab::Access::MAINTAINER_PROJECT_ACCESS }
put :update, params: { application_setting: { default_project_creation: ::EE::Gitlab::Access::MAINTAINER_PROJECT_ACCESS } }
 
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.default_project_creation).to eq(::EE::Gitlab::Access::MAINTAINER_PROJECT_ACCESS)
end
 
it 'updates repository_size_limit' do
put :update, application_setting: { repository_size_limit: '100' }
put :update, params: { application_setting: { repository_size_limit: '100' } }
 
expect(response).to redirect_to(admin_application_settings_path)
expect(response).to set_flash[:notice].to('Application settings saved successfully')
end
 
it 'does not accept negative repository_size_limit' do
put :update, application_setting: { repository_size_limit: '-100' }
put :update, params: { application_setting: { repository_size_limit: '-100' } }
 
expect(response).to render_template(:show)
expect(assigns(:application_setting).errors[:repository_size_limit]).to be_present
end
 
it 'does not accept invalid repository_size_limit' do
put :update, application_setting: { repository_size_limit: 'one thousand' }
put :update, params: { application_setting: { repository_size_limit: 'one thousand' } }
 
expect(response).to render_template(:show)
expect(assigns(:application_setting).errors[:repository_size_limit]).to be_present
end
 
it 'does not accept empty repository_size_limit' do
put :update, application_setting: { repository_size_limit: '' }
put :update, params: { application_setting: { repository_size_limit: '' } }
 
expect(response).to render_template(:show)
expect(assigns(:application_setting).errors[:repository_size_limit]).to be_present
Loading
Loading
Loading
Loading
@@ -60,7 +60,7 @@ def go
let(:geo_node_attributes) { { url: 'http://example.com' } }
 
def go
post :create, geo_node: geo_node_attributes
post :create, params: { geo_node: geo_node_attributes }
end
 
context 'without add-on license' do
Loading
Loading
@@ -91,7 +91,7 @@ def go
let(:geo_node) { create(:geo_node) }
 
def go
post :update, id: geo_node, geo_node: geo_node_attributes
post :update, params: { id: geo_node, geo_node: geo_node_attributes }
end
 
context 'without add-on license' do
Loading
Loading
Loading
Loading
@@ -47,7 +47,7 @@
end
 
context 'with sync_status=pending' do
subject { get :index, sync_status: 'pending' }
subject { get :index, params: { sync_status: 'pending' } }
 
it 'renders pending template' do
expect(subject).to have_gitlab_http_status(200)
Loading
Loading
@@ -57,7 +57,7 @@
end
 
context 'with sync_status=failed' do
subject { get :index, sync_status: 'failed' }
subject { get :index, params: { sync_status: 'failed' } }
 
it 'renders failed template' do
expect(subject).to have_gitlab_http_status(200)
Loading
Loading
@@ -67,7 +67,7 @@
end
 
context 'with sync_status=never' do
subject { get :index, sync_status: 'never' }
subject { get :index, params: { sync_status: 'never' } }
 
it 'renders failed template' do
expect(subject).to have_gitlab_http_status(200)
Loading
Loading
@@ -77,7 +77,7 @@
end
 
context 'with sync_status=synced' do
subject { get :index, sync_status: 'synced' }
subject { get :index, params: { sync_status: 'synced' } }
 
it 'renders synced template' do
expect(subject).to have_gitlab_http_status(200)
Loading
Loading
@@ -89,7 +89,7 @@
end
 
describe '#destroy' do
subject { delete :destroy, id: synced_registry }
subject { delete :destroy, params: { id: synced_registry } }
 
it_behaves_like 'license required'
 
Loading
Loading
@@ -119,7 +119,7 @@
end
 
describe '#recheck' do
subject { post :recheck, id: synced_registry }
subject { post :recheck, params: { id: synced_registry } }
 
it_behaves_like 'license required'
 
Loading
Loading
@@ -137,7 +137,7 @@
end
 
describe '#resync' do
subject { post :resync, id: synced_registry }
subject { post :resync, params: { id: synced_registry } }
 
it_behaves_like 'license required'
 
Loading
Loading
@@ -205,7 +205,7 @@
end
 
describe '#force_redownload' do
subject { post :force_redownload, id: synced_registry }
subject { post :force_redownload, params: { id: synced_registry } }
 
it_behaves_like 'license required'
 
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@
end
 
describe 'POST #reset_runner_minutes' do
subject { post :reset_runners_minutes, id: group }
subject { post :reset_runners_minutes, params: { id: group } }
 
before do
allow_any_instance_of(ClearNamespaceSharedRunnersMinutesService)
Loading
Loading
@@ -45,7 +45,7 @@
stub_licensed_features(project_creation_level: false)
 
expect do
post :update, id: group.to_param, group: { project_creation_level: ::EE::Gitlab::Access::NO_ONE_PROJECT_ACCESS }
post :update, params: { id: group.to_param, group: { project_creation_level: ::EE::Gitlab::Access::NO_ONE_PROJECT_ACCESS } }
end.not_to change { group.reload.project_creation_level }
end
end
Loading
Loading
@@ -55,7 +55,7 @@
stub_licensed_features(project_creation_level: true)
 
expect do
post :update, id: group.to_param, group: { project_creation_level: ::EE::Gitlab::Access::NO_ONE_PROJECT_ACCESS }
post :update, params: { id: group.to_param, group: { project_creation_level: ::EE::Gitlab::Access::NO_ONE_PROJECT_ACCESS } }
end.to change { group.reload.project_creation_level }.to(::EE::Gitlab::Access::NO_ONE_PROJECT_ACCESS)
end
end
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@
 
describe 'Upload license' do
it 'redirects back when no license is entered/uploaded' do
post :create, license: { data: '' }
post :create, params: { license: { data: '' } }
 
expect(response).to redirect_to new_admin_license_path
expect(flash[:alert]).to include 'Please enter or upload a license.'
Loading
Loading
Loading
Loading
@@ -13,7 +13,7 @@
end
 
describe 'GET /projects/:id' do
subject { get :show, namespace_id: project.namespace.path, id: project.path }
subject { get :show, params: { namespace_id: project.namespace.path, id: project.path } }
 
render_views
 
Loading
Loading
Loading
Loading
@@ -19,7 +19,7 @@
it 'updates sample push rule' do
expect_any_instance_of(PushRule).to receive(:update).with(ActionController::Parameters.new(params).permit!)
 
patch :update, push_rule: params
patch :update, params: { push_rule: params }
 
expect(response).to redirect_to(admin_push_rule_path)
end
Loading
Loading
@@ -30,7 +30,7 @@
end
 
it 'returns 404' do
patch :update, push_rule: params
patch :update, params: { push_rule: params }
 
expect(response).to have_gitlab_http_status(404)
end
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@
end
 
describe 'POST #reset_runner_minutes' do
subject { post :reset_runners_minutes, id: user }
subject { post :reset_runners_minutes, params: { id: user } }
 
before do
allow_any_instance_of(ClearNamespaceSharedRunnersMinutesService)
Loading
Loading
Loading
Loading
@@ -16,7 +16,7 @@
 
describe "GET #users that can push to protected branches" do
before do
get(:users, project_id: project.id, push_code_to_protected_branches: 'true')
get(:users, params: { project_id: project.id, push_code_to_protected_branches: 'true' })
end
 
it 'returns authorized users', :aggregate_failures do
Loading
Loading
@@ -31,7 +31,7 @@
 
before do
project.add_reporter(reporter_user)
get(:users, project_id: project.id, push_code: 'true')
get(:users, params: { project_id: project.id, push_code: 'true' })
end
 
it 'returns authorized users', :aggregate_failures do
Loading
Loading
@@ -43,7 +43,7 @@
 
describe "GET #users that can push to protected branches, including the current user" do
before do
get(:users, project_id: project.id, push_code_to_protected_branches: true, current_user: true)
get(:users, params: { project_id: project.id, push_code_to_protected_branches: true, current_user: true })
end
 
it 'returns authorized users', :aggregate_failures do
Loading
Loading
@@ -67,7 +67,7 @@
context "while fetching all groups belonging to a project" do
before do
sign_in(user)
get(:project_groups, project_id: project.id)
get(:project_groups, params: { project_id: project.id })
end
 
it 'returns a single group', :aggregate_failures do
Loading
Loading
@@ -80,7 +80,7 @@
context "while fetching all groups belonging to a project the current user cannot access" do
before do
sign_in(user2)
get(:project_groups, project_id: project.id)
get(:project_groups, params: { project_id: project.id })
end
 
it { expect(response).to be_not_found }
Loading
Loading
@@ -89,7 +89,7 @@
context "while fetching all groups belonging to an invalid project ID" do
before do
sign_in(user)
get(:project_groups, project_id: 'invalid')
get(:project_groups, params: { project_id: 'invalid' })
end
 
it { expect(response).to be_not_found }
Loading
Loading
Loading
Loading
@@ -97,7 +97,7 @@
end
 
it 'returns a 403 for group boards' do
get :index, board_id: board
get :index, params: { board_id: board }
 
expect(response).to have_gitlab_http_status(403)
end
Loading
Loading
@@ -118,7 +118,7 @@ def list_issues(user:, board:, list: nil)
list_id: list.try(:to_param)
}
 
get :index, params.compact
get :index, params: params.compact
end
end
 
Loading
Loading
@@ -184,9 +184,11 @@ def list_issues(user:, board:, list: nil)
def create_issue(user:, board:, list:, title:)
sign_in(user)
 
post :create, board_id: board.to_param,
list_id: list.to_param,
issue: { title: title, project_id: project_1.id },
post :create, params: {
board_id: board.to_param,
list_id: list.to_param,
issue: { title: title, project_id: project_1.id }
},
format: :json
end
end
Loading
Loading
@@ -245,10 +247,12 @@ def create_issue(user:, board:, list:, title:)
def move(user:, board:, issue:, from_list_id:, to_list_id:)
sign_in(user)
 
patch :update, board_id: board.to_param,
id: issue.id,
from_list_id: from_list_id,
to_list_id: to_list_id,
patch :update, params: {
board_id: board.to_param,
id: issue.id,
from_list_id: from_list_id,
to_list_id: to_list_id
},
format: :json
end
end
Loading
Loading
Loading
Loading
@@ -45,7 +45,7 @@
def read_board_list(user:, board:)
sign_in(user)
 
get :index, board_id: board.to_param, format: :json
get :index, params: { board_id: board.to_param }, format: :json
end
end
 
Loading
Loading
@@ -99,8 +99,10 @@ def read_board_list(user:, board:)
def create_board_list(user:, board:, label_id:)
sign_in(user)
 
post :create, board_id: board.to_param,
list: { label_id: label_id },
post :create, params: {
board_id: board.to_param,
list: { label_id: label_id }
},
format: :json
end
end
Loading
Loading
@@ -194,8 +196,10 @@ def move(user:, board:, list:, position:)
def remove_board_list(user:, board:, list:)
sign_in(user)
 
delete :destroy, board_id: board.to_param,
id: list.to_param,
delete :destroy, params: {
board_id: board.to_param,
id: list.to_param
},
format: :json
end
end
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@
end
 
it 'returns a list of all milestones of board parent' do
get :index, board_id: board.to_param, format: :json
get :index, params: { board_id: board.to_param }, format: :json
 
parsed_response = JSON.parse(response.body)
 
Loading
Loading
@@ -33,7 +33,7 @@
 
shared_examples 'unauthorized board milestone listing' do
it 'returns a forbidden 403 response' do
get :index, board_id: board.to_param, format: :json
get :index, params: { board_id: board.to_param }, format: :json
 
expect(response).to have_gitlab_http_status(403)
end
Loading
Loading
Loading
Loading
@@ -16,8 +16,10 @@
end
 
it 'returns a list of all members of board parent' do
get :index, namespace_id: group.to_param,
board_id: board.to_param,
get :index, params: {
namespace_id: group.to_param,
board_id: board.to_param
},
format: :json
 
parsed_response = JSON.parse(response.body)
Loading
Loading
@@ -36,7 +38,7 @@
 
shared_examples 'unauthorized board user listing' do
it 'returns a forbidden 403 response' do
get :index, board_id: board.to_param, format: :json
get :index, params: { board_id: board.to_param }, format: :json
 
expect(response).to have_gitlab_http_status(403)
end
Loading
Loading
Loading
Loading
@@ -26,7 +26,7 @@ def show
it 'renders a 200 when the service allows access to the project' do
external_service_allow_access(user, project)
 
get :show, namespace_id: project.namespace.to_param, id: project.to_param
get :show, params: { namespace_id: project.namespace.to_param, id: project.to_param }
 
expect(response).to have_gitlab_http_status(200)
end
Loading
Loading
@@ -34,7 +34,7 @@ def show
it 'renders a 403 when the service denies access to the project' do
external_service_deny_access(user, project)
 
get :show, namespace_id: project.namespace.to_param, id: project.to_param
get :show, params: { namespace_id: project.namespace.to_param, id: project.to_param }
 
expect(response).to have_gitlab_http_status(403)
expect(response.body).to match("External authorization denied access to this project")
Loading
Loading
@@ -43,7 +43,7 @@ def show
it 'renders a 404 when the user cannot see the project at all' do
other_project = create(:project, :private)
 
get :show, namespace_id: other_project.namespace.to_param, id: other_project.to_param
get :show, params: { namespace_id: other_project.namespace.to_param, id: other_project.to_param }
 
expect(response).to have_gitlab_http_status(404)
end
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@
 
context 'when epics feture is disabled' do
it 'returns 404 status' do
get :epics, namespace_id: project.namespace, project_id: project
get :epics, params: { namespace_id: project.namespace, project_id: project }
 
expect(response).to have_gitlab_http_status(404)
end
Loading
Loading
@@ -28,7 +28,7 @@
 
context '#epics' do
it 'returns the correct response' do
get :epics, namespace_id: project.namespace, project_id: project
get :epics, params: { namespace_id: project.namespace, project_id: project }
 
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an(Array)
Loading
Loading
Loading
Loading
@@ -13,7 +13,7 @@
 
before do
sign_in(user)
get(:unsubscribe, id: sent_notification.reply_key)
get(:unsubscribe, params: { id: sent_notification.reply_key })
end
 
it 'unsubscribes the user' do
Loading
Loading
Loading
Loading
@@ -41,7 +41,7 @@ def create_push_event(author, project)
it 'returns 404 when feature is not available and we dont show promotions' do
stub_licensed_features(contribution_analytics: false)
 
get :show, group_id: group.path
get :show, params: { group_id: group.path }
 
expect(response).to have_gitlab_http_status(404)
end
Loading
Loading
@@ -56,14 +56,14 @@ def create_push_event(author, project)
it 'returns page when feature is not available and we show promotions' do
stub_licensed_features(contribution_analytics: false)
 
get :show, group_id: group.path
get :show, params: { group_id: group.path }
 
expect(response).to have_gitlab_http_status(200)
end
end
 
it 'sets instance variables properly', :aggregate_failures do
get :show, group_id: group.path
get :show, params: { group_id: group.path }
 
expect(response).to have_gitlab_http_status(200)
 
Loading
Loading
@@ -78,7 +78,7 @@ def create_push_event(author, project)
end
 
it "returns member contributions JSON when format is JSON" do
get :show, group_id: group.path, format: :json
get :show, params: { group_id: group.path }, format: :json
 
expect(json_response.length).to eq(3)
 
Loading
Loading
@@ -96,14 +96,14 @@ def create_push_event(author, project)
 
it 'does not cause N+1 queries when the format is JSON' do
control_count = ActiveRecord::QueryRecorder.new do
get :show, group_id: group.path, format: :json
get :show, params: { group_id: group.path }, format: :json
end
 
controller.instance_variable_set(:@group, nil)
user4 = create(:user)
group.add_user(user4, GroupMember::DEVELOPER)
 
expect { get :show, group_id: group.path, format: :json }
expect { get :show, params: { group_id: group.path }, format: :json }
.not_to exceed_query_limit(control_count)
end
 
Loading
Loading
@@ -111,19 +111,19 @@ def create_push_event(author, project)
render_views
 
it 'avoids a N+1 query in #show' do
control_count = ActiveRecord::QueryRecorder.new { get :show, group_id: group.path }.count
control_count = ActiveRecord::QueryRecorder.new { get :show, params: { group_id: group.path } }.count
 
# Clear out controller state to force a refresh of the group
controller.instance_variable_set(:@group, nil)
user4 = create(:user)
group.add_user(user4, GroupMember::DEVELOPER)
 
expect { get :show, group_id: group.path }.not_to exceed_query_limit(control_count)
expect { get :show, params: { group_id: group.path } }.not_to exceed_query_limit(control_count)
end
end
 
describe 'GET #index' do
subject { get :show, group_id: group.to_param }
subject { get :show, params: { group_id: group.to_param } }
 
it_behaves_like 'disabled when using an external authorization service'
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment