Use keyword arguments in tests

Raisl 5.1 removes support for non-keyword arguments in `#process`,
`#get`, `#post`, `#patch`, `#put`, `#delete`, and `#head` for the
`ActionDispatch::IntegrationTest` and `ActionController::TestCase`
classes. This means we have to add `params` everywhere in the controller
tests.
This commit is contained in:
Ana María Martínez Gómez 2019-05-13 17:42:09 +02:00
parent b8013661a2
commit d1180e2767
No known key found for this signature in database
GPG key ID: EACB9B4BC80C0347
35 changed files with 975 additions and 364 deletions

View file

@ -18,22 +18,22 @@ describe Admin::ConferencesController do
describe 'PATCH #update' do
context 'valid attributes' do
it 'locates the requested conference' do
patch :update, id: conference.short_title, conference: attributes_for(:conference, title: 'Example Con')
patch :update, params: { id: conference.short_title, conference: attributes_for(:conference, title: 'Example Con') }
expect(assigns(:conference)).to eq(conference)
end
it 'changes conference attributes' do
patch :update, id: conference.short_title, conference:
patch :update, params: { id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: 'ExCon')
short_title: 'ExCon') }
conference.reload
expect(conference.title).to eq('Example Con')
expect(conference.short_title).to eq('ExCon')
end
it 'redirects to the updated conference' do
patch :update, id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con')
patch :update, params: { id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con') }
conference.reload
expect(response).to redirect_to edit_admin_conference_path(
conference.short_title)
@ -43,7 +43,7 @@ describe Admin::ConferencesController do
mailer = double
allow(mailer).to receive(:deliver)
conference.email_settings = create(:email_settings)
patch :update, id: conference.short_title, conference: attributes_for(:conference, start_date: Time.zone.today + 2.days, end_date: Time.zone.today + 4.days)
patch :update, params: { id: conference.short_title, conference: attributes_for(:conference, start_date: Time.zone.today + 2.days, end_date: Time.zone.today + 4.days) }
conference.reload
allow(Mailbot).to receive(:conference_date_update_mail).and_return(mailer)
end
@ -51,9 +51,9 @@ describe Admin::ConferencesController do
context 'invalid attributes' do
it 'does not change conference attributes' do
patch :update, id: conference.short_title, conference:
patch :update, params: { id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: nil)
short_title: nil) }
conference.reload
expect(flash[:error])
@ -63,9 +63,9 @@ describe Admin::ConferencesController do
end
it 're-renders the #show template' do
patch :update, id: conference.short_title, conference:
patch :update, params: { id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: nil)
short_title: nil) }
expect(flash[:error])
.to eq("Updating conference failed. Short title can't be blank.")
@ -77,24 +77,24 @@ describe Admin::ConferencesController do
describe 'GET #edit' do
it 'assigns the requested conference to conference' do
get :edit, id: conference.short_title
get :edit, params: { id: conference.short_title }
expect(assigns(:conference)).to eq conference
end
it 'renders the show template' do
get :edit, id: conference.short_title
get :edit, params: { id: conference.short_title }
expect(response).to render_template :edit
end
end
describe 'GET #show' do
it 'assigns the requested conference to conference' do
get :show, id: conference.short_title
get :show, params: { id: conference.short_title }
expect(assigns(:conference)).to eq conference
end
it 'renders the show template' do
get :show, id: conference.short_title
get :show, params: { id: conference.short_title }
expect(response).to render_template :show
end
@ -103,11 +103,11 @@ describe Admin::ConferencesController do
create(:event, program: conference.program)
workshop = create(:event_type, title: 'Workshop', color: '#000000', program: conference.program)
lecture = create(:event_type, title: 'Lecture', color: '#ffffff', program: conference.program)
get :show, id: conference.short_title
get :show, params: { id: conference.short_title }
expect(assigns(:event_type_distribution_withdrawn)).to be_empty
create(:event, program: conference.program, state: 'withdrawn', event_type: lecture)
create(:event, program: conference.program, state: 'withdrawn', event_type: workshop)
get :show, id: conference.short_title
get :show, params: { id: conference.short_title }
expect(assigns(:event_type_distribution_withdrawn)).not_to be_empty
result = {}
result['Workshop'] = {
@ -124,13 +124,13 @@ describe Admin::ConferencesController do
it 'assigns conference withdrawn difficulty level distribution to difficulty_levels_distribution_withdrawn' do
conference
create(:event, program: conference.program)
get :show, id: conference.short_title
get :show, params: { id: conference.short_title }
expect(assigns(:difficulty_levels_distribution_withdrawn)).to be_empty
easy = create(:difficulty_level, title: 'Easy', color: '#000000')
hard = create(:difficulty_level, title: 'Hard', color: '#ffffff')
create(:event, program: conference.program, state: 'withdrawn', difficulty_level: easy)
create(:event, program: conference.program, state: 'withdrawn', difficulty_level: hard)
get :show, id: conference.short_title
get :show, params: { id: conference.short_title }
expect(assigns(:difficulty_levels_distribution_withdrawn)).not_to be_empty
result = {}
result['Easy'] = {
@ -147,13 +147,13 @@ describe Admin::ConferencesController do
it 'assigns conference withdrawn track distribution to tracks_distribution_withdrawn' do
conference
create(:event, program: conference.program)
get :show, id: conference.short_title
get :show, params: { id: conference.short_title }
expect(assigns(:tracks_distribution_withdrawn)).to be_empty
track_one = create(:track, name: 'Track One', color: '#000000', program: conference.program)
track_two = create(:track, name: 'Track Two', color: '#FFFFFF', program: conference.program)
create(:event, program: conference.program, state: 'withdrawn', track: track_one)
create(:event, program: conference.program, state: 'withdrawn', track: track_two)
get :show, id: conference.short_title
get :show, params: { id: conference.short_title }
expect(assigns(:tracks_distribution_withdrawn)).not_to be_empty
result = {}
result['Track One'] = {
@ -202,15 +202,15 @@ describe Admin::ConferencesController do
context 'with valid attributes' do
it 'saves the conference to the database' do
expected = expect do
post :create, conference:
attributes_for(:conference, short_title: 'dps15', organization_id: organization.id)
post :create, params: { conference:
attributes_for(:conference, short_title: 'dps15', organization_id: organization.id) }
end
expected.to change { Conference.count }.by 1
end
it 'redirects to conference#show' do
post :create, conference:
attributes_for(:conference, short_title: 'dps15', organization_id: organization.id)
post :create, params: { conference:
attributes_for(:conference, short_title: 'dps15', organization_id: organization.id) }
expect(response).to redirect_to admin_conference_path(
assigns[:conference].short_title)
@ -221,8 +221,8 @@ describe Admin::ConferencesController do
info_desk_role = Role.find_by(name: 'info_desk', resource: conference)
volunteers_coordinator_role = Role.find_by(name: 'volunteers_coordinator', resource: conference)
post :create, conference:
attributes_for(:conference, short_title: 'dps15')
post :create, params: { conference:
attributes_for(:conference, short_title: 'dps15') }
expect(conference.roles.count).to eq 4
@ -233,15 +233,15 @@ describe Admin::ConferencesController do
context 'with invalid attributes' do
it 'does not save the conference to the database' do
expected = expect do
post :create, conference:
attributes_for(:conference, short_title: nil, organization_id: organization.id)
post :create, params: { conference:
attributes_for(:conference, short_title: nil, organization_id: organization.id) }
end
expected.to_not change { Conference.count }
end
it 're-renders the new template' do
post :create, conference:
attributes_for(:conference, short_title: nil, organization_id: organization.id)
post :create, params: { conference:
attributes_for(:conference, short_title: nil, organization_id: organization.id) }
expect(response).to be_success
end
end
@ -250,15 +250,15 @@ describe Admin::ConferencesController do
it 'does not save the conference to the database' do
conference
expected = expect do
post :create, conference:
attributes_for(:conference, short_title: conference.short_title, organization_id: organization.id)
post :create, params: { conference:
attributes_for(:conference, short_title: conference.short_title, organization_id: organization.id) }
end
expected.to_not change { Conference.count }
end
it 're-renders the new template' do
conference
post :create, conference: attributes_for(:conference, short_title: conference.short_title, organization_id: organization.id)
post :create, params: { conference: attributes_for(:conference, short_title: conference.short_title, organization_id: organization.id) }
expect(response).to be_success
end
end
@ -299,8 +299,8 @@ describe Admin::ConferencesController do
describe 'POST #create' do
it 'requires organizer privileges' do
post :create, conference: attributes_for(:conference,
short_title: 'ExCon', organization_id: organization.id)
post :create, params: { conference: attributes_for(:conference,
short_title: 'ExCon', organization_id: organization.id) }
expect(response).to redirect_to(send(path))
if message
expect(flash[:alert]).to match(/#{message}/)
@ -321,7 +321,7 @@ describe Admin::ConferencesController do
shared_examples 'access as participant or guest' do |path, message|
describe 'GET #show' do
it 'requires organizer privileges' do
get :show, id: conference.short_title
get :show, params: { id: conference.short_title }
expect(response).to redirect_to(send(path))
if message
expect(flash[:alert]).to match(/#{message}/)
@ -341,9 +341,9 @@ describe Admin::ConferencesController do
describe 'PATCH #update' do
it 'requires organizer privileges' do
patch :update, id: conference.short_title,
conference: attributes_for(:conference,
short_title: 'ExCon')
patch :update, params: { id: conference.short_title,
conference: attributes_for(:conference,
short_title: 'ExCon') }
expect(response).to redirect_to(send(path))
if message
expect(flash[:alert]).to match(/#{message}/)