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

@ -13,7 +13,7 @@ describe ProposalsController do
before do
# We allow new proposal only if program has open cfp
create(:cfp, program: conference.program)
get :new, conference_id: conference.short_title
get :new, params: { conference_id: conference.short_title }
end
it 'assigns user and url variables' do
@ -31,9 +31,9 @@ describe ProposalsController do
before { create(:cfp, program: conference.program) }
it 'assigns url variables' do
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user)
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user) }
expect(assigns(:url)).to eq '/conferences/lama101/program/proposals'
end
@ -41,9 +41,9 @@ describe ProposalsController do
describe 'user related actions' do
before do
@new_user = attributes_for(:user)
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: @new_user
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: @new_user }
end
it 'creates new user' do
@ -58,9 +58,9 @@ describe ProposalsController do
context 'creates proposal successfully' do
before(:each, run: true) do
@new_user = attributes_for(:user)
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: @new_user
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: @new_user }
end
it 'assigns event variable', run: true do
@ -86,9 +86,9 @@ describe ProposalsController do
it 'creates new event' do
expect do
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user)
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user) }
end.to change{ Event.count }.by 1
end
end
@ -96,9 +96,9 @@ describe ProposalsController do
context 'proposal save fails' do
before(:each, run: true) do
allow_any_instance_of(Event).to receive(:save).and_return(false)
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user)
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user) }
end
it 'renders new template', run: true do
@ -112,9 +112,9 @@ describe ProposalsController do
it 'does not create new proposal' do
allow_any_instance_of(Event).to receive(:save).and_return(false)
expect do
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user)
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user) }
end.not_to change{ Event.count }
end
end
@ -125,25 +125,25 @@ describe ProposalsController do
it 'does not create new user' do
expect do
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user)
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user) }
end.not_to change { User.count }
end
it 'does not create new event' do
expect do
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user)
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user) }
end.not_to change { Event.count }
end
describe 'response' do
before do
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user)
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title,
user: attributes_for(:user) }
end
it 'renders new template' do
@ -164,7 +164,7 @@ describe ProposalsController do
end
describe 'GET #index' do
before { get :index, conference_id: conference.short_title }
before { get :index, params: { conference_id: conference.short_title } }
it 'assigns conference, program and events variables' do
expect(assigns(:conference)).to eq conference
@ -179,7 +179,7 @@ describe ProposalsController do
describe 'GET #show' do
before do
get :show, conference_id: conference.short_title, id: event.id
get :show, params: { conference_id: conference.short_title, id: event.id }
end
it 'assigns event variable' do
@ -195,7 +195,7 @@ describe ProposalsController do
before do
# We allow new proposal only if program has open cfp
create(:cfp, program: conference.program)
get :new, conference_id: conference.short_title
get :new, params: { conference_id: conference.short_title }
end
it 'assigns user and url variables' do
@ -210,7 +210,7 @@ describe ProposalsController do
describe 'GET #edit' do
before do
get :edit, conference_id: conference.short_title, id: event.id
get :edit, params: { conference_id: conference.short_title, id: event.id }
end
it 'assigns event and url variables' do
@ -228,15 +228,15 @@ describe ProposalsController do
before { create(:cfp, program: conference.program) }
it 'assigns url variables' do
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title }
expect(assigns(:url)).to eq '/conferences/lama101/program/proposals'
end
context 'creates proposal successfully' do
before(:each, run: true) do
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title }
end
it 'assigns event variable', run: true do
@ -262,8 +262,8 @@ describe ProposalsController do
it 'creates new event' do
expect do
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title }
end.to change{ Event.count }.by 1
end
end
@ -271,8 +271,8 @@ describe ProposalsController do
context 'proposal save fails' do
before(:each, run: true) do
allow_any_instance_of(Event).to receive(:save).and_return(false)
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title }
end
it 'renders new template', run: true do
@ -286,8 +286,8 @@ describe ProposalsController do
it 'does not create new proposal' do
allow_any_instance_of(Event).to receive(:save).and_return(false)
expect do
post :create, event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title
post :create, params: { event: attributes_for(:event, event_type_id: event_type.id),
conference_id: conference.short_title }
end.not_to change{ Event.count }
end
end
@ -296,17 +296,17 @@ describe ProposalsController do
describe 'PATCH #update' do
it 'assigns url variable' do
patch :update, event: attributes_for(:event, title: 'some title', event_type_id: event_type.id),
conference_id: conference.short_title,
id: event.id
patch :update, params: { event: attributes_for(:event, title: 'some title', event_type_id: event_type.id),
conference_id: conference.short_title,
id: event.id }
expect(assigns(:url)).to eq "/conferences/lama101/program/proposals/#{event.id}"
end
context 'updates successfully' do
before do
patch :update, event: attributes_for(:event, title: 'some title', event_type_id: event_type.id),
conference_id: conference.short_title,
id: event.id
patch :update, params: { event: attributes_for(:event, title: 'some title', event_type_id: event_type.id),
conference_id: conference.short_title,
id: event.id }
end
it 'updates the proposal' do
@ -326,9 +326,9 @@ describe ProposalsController do
context 'update fails' do
before do
allow_any_instance_of(Event).to receive(:save).and_return(false)
patch :update, event: attributes_for(:event, title: 'some title', event_type_id: event_type.id),
conference_id: conference.short_title,
id: event.id
patch :update, params: { event: attributes_for(:event, title: 'some title', event_type_id: event_type.id),
conference_id: conference.short_title,
id: event.id }
end
it 'does not update the proposal' do
@ -349,13 +349,13 @@ describe ProposalsController do
describe 'PATCH #withdraw' do
it 'assigns url variable' do
patch :withdraw, conference_id: conference.short_title, id: event.id
patch :withdraw, params: { conference_id: conference.short_title, id: event.id }
expect(assigns(:url)).to eq "/conferences/lama101/program/proposals/#{event.id}"
end
context 'withdraws successfully' do
before do
patch :withdraw, conference_id: conference.short_title, id: event.id
patch :withdraw, params: { conference_id: conference.short_title, id: event.id }
end
it 'changes state of event to withdrawn' do
@ -376,7 +376,7 @@ describe ProposalsController do
before do
request.env['HTTP_REFERER'] = '/'
allow_any_instance_of(Event).to receive(:withdraw).and_raise(Transitions::InvalidTransition)
patch :withdraw, conference_id: conference.short_title, id: event.id
patch :withdraw, params: { conference_id: conference.short_title, id: event.id }
end
it 'does not withdraw event' do
@ -396,7 +396,7 @@ describe ProposalsController do
context 'event save fails' do
before do
allow_any_instance_of(Event).to receive(:save).and_return(false)
patch :withdraw, conference_id: conference.short_title, id: event.id
patch :withdraw, params: { conference_id: conference.short_title, id: event.id }
end
it 'does not withdraw event' do
@ -423,7 +423,7 @@ describe ProposalsController do
event.require_registration = true
event.max_attendees = nil
event.save!
patch :confirm, conference_id: conference.short_title, id: event.id
patch :confirm, params: { conference_id: conference.short_title, id: event.id }
end
it 'assigns url variable' do
@ -437,7 +437,7 @@ describe ProposalsController do
end
describe 'general actions' do
before { patch :confirm, conference_id: conference.short_title, id: event.id }
before { patch :confirm, params: { conference_id: conference.short_title, id: event.id } }
it 'assigns url variable' do
expect(assigns(:url)).to eq "/conferences/lama101/program/proposals/#{event.id}"
@ -452,7 +452,7 @@ describe ProposalsController do
context 'user has registered for the conference' do
before do
create(:registration, conference: conference, user: event.submitter)
patch :confirm, conference_id: conference.short_title, id: event.id
patch :confirm, params: { conference_id: conference.short_title, id: event.id }
end
it 'redirects to proposal index path' do
@ -466,7 +466,7 @@ describe ProposalsController do
context 'user has not registered for the conference' do
before do
patch :confirm, conference_id: conference.short_title, id: event.id
patch :confirm, params: { conference_id: conference.short_title, id: event.id }
end
it 'redirects to new registration path' do
@ -483,7 +483,7 @@ describe ProposalsController do
before do
request.env['HTTP_REFERER'] = '/'
allow_any_instance_of(Event).to receive(:confirm).and_raise(Transitions::InvalidTransition)
patch :confirm, conference_id: conference.short_title, id: event.id
patch :confirm, params: { conference_id: conference.short_title, id: event.id }
end
it 'does not confirm event' do
@ -503,7 +503,7 @@ describe ProposalsController do
before do
event.update_attributes(state: 'unconfirmed')
allow_any_instance_of(Event).to receive(:save).and_return(false)
patch :confirm, conference_id: conference.short_title, id: event.id
patch :confirm, params: { conference_id: conference.short_title, id: event.id }
end
it 'does not confirm event' do
@ -524,13 +524,13 @@ describe ProposalsController do
before { event.update_attributes(state: 'withdrawn') }
it 'assigns url variable' do
patch :restart, conference_id: conference.short_title, id: event.id
patch :restart, params: { conference_id: conference.short_title, id: event.id }
expect(assigns(:url)).to eq "/conferences/lama101/program/proposals/#{event.id}"
end
context 'resubmits successfully' do
before do
patch :restart, conference_id: conference.short_title, id: event.id
patch :restart, params: { conference_id: conference.short_title, id: event.id }
end
it 'changes state of event to new' do
@ -550,7 +550,7 @@ describe ProposalsController do
context 'event resubmission fails' do
before do
allow_any_instance_of(Event).to receive(:restart).and_raise(Transitions::InvalidTransition)
patch :restart, conference_id: conference.short_title, id: event.id
patch :restart, params: { conference_id: conference.short_title, id: event.id }
end
it 'does not change state of event to new' do
@ -570,7 +570,7 @@ describe ProposalsController do
context 'event save fails' do
before do
allow_any_instance_of(Event).to receive(:save).and_return(false)
patch :restart, conference_id: conference.short_title, id: event.id
patch :restart, params: { conference_id: conference.short_title, id: event.id }
end
it 'does not change state of event to new' do