Use respond_to

This commit is contained in:
Paul Chavard 2020-03-18 11:41:52 +01:00 committed by Pierre de La Morinerie
parent f558b61298
commit 04feada77e
2 changed files with 15 additions and 7 deletions

View file

@ -74,21 +74,27 @@ class Admin::ProceduresController < AdminController
flash.notice = "Démarche publiée"
render js: "window.location='#{admin_procedures_path}'"
rescue ActiveRecord::RecordInvalid
render 'publish_validate', formats: :js
respond_to do |format|
format.js { render :publish_validate }
end
end
def transfer
admin = Administrateur.by_email(params[:email_admin].downcase)
if admin.nil?
render '/admin/procedures/transfer', formats: 'js', status: 404
respond_to do |format|
format.js { render :transfer, status: :not_found }
end
else
procedure = current_administrateur.procedures.find(params[:procedure_id])
procedure.clone(admin, false)
flash.now.notice = "La démarche a correctement été clonée vers le nouvel administrateur."
render '/admin/procedures/transfer', formats: 'js', status: 200
respond_to do |format|
format.js
end
end
end

View file

@ -167,7 +167,7 @@ describe Admin::ProceduresController, type: :controller do
context 'when admin is the owner of the procedure' do
before do
put :publish, format: :js, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web }
put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web }, format: 'js'
procedure.reload
procedure2.reload
end
@ -246,7 +246,7 @@ describe Admin::ProceduresController, type: :controller do
sign_out(admin.user)
sign_in(admin_2.user)
put :publish, params: { procedure_id: procedure.id, path: 'fake_path' }
put :publish, params: { procedure_id: procedure.id, path: 'fake_path' }, format: 'js'
procedure.reload
end
@ -257,7 +257,7 @@ describe Admin::ProceduresController, type: :controller do
context 'when the admin does not provide a lien_site_web' do
before do
put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web }
put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web }, format: 'js'
procedure.reload
end
context 'procedure path is valid but lien_site_web is missing' do
@ -411,7 +411,9 @@ describe Admin::ProceduresController, type: :controller do
describe 'POST #transfer' do
let!(:procedure) { create :procedure, :with_service, administrateur: admin }
subject { post :transfer, params: { email_admin: email_admin, procedure_id: procedure.id } }
subject do
post :transfer, params: { email_admin: email_admin, procedure_id: procedure.id }, format: 'js'
end
context 'when admin is unknow' do
let(:email_admin) { 'plop' }