app: move archive to NewAdministrateur::ProceduresController
This commit is contained in:
parent
e7c8a9fff5
commit
a004ac59df
5 changed files with 47 additions and 48 deletions
|
@ -1,13 +1,2 @@
|
|||
class Admin::ProceduresController < AdminController
|
||||
def archive
|
||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
procedure.close!
|
||||
|
||||
flash.notice = "Démarche close"
|
||||
redirect_to admin_procedures_path
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
flash.alert = 'Démarche inexistante'
|
||||
redirect_to admin_procedures_path
|
||||
end
|
||||
end
|
||||
|
|
|
@ -132,6 +132,18 @@ module NewAdministrateur
|
|||
redirect_to admin_procedures_path
|
||||
end
|
||||
|
||||
def archive
|
||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
procedure.close!
|
||||
|
||||
flash.notice = "Démarche close"
|
||||
redirect_to admin_procedures_path
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
flash.alert = 'Démarche inexistante'
|
||||
redirect_to admin_procedures_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
procedure = current_administrateur.procedures.find(params[:id])
|
||||
|
||||
|
|
|
@ -193,10 +193,6 @@ Rails.application.routes.draw do
|
|||
get 'procedures/archived', to: redirect('/admin/procedures?statut=archivees')
|
||||
get 'procedures/draft', to: redirect('/admin/procedures?statut=brouillons')
|
||||
|
||||
resources :procedures, only: [] do
|
||||
put 'archive' => 'procedures#archive', as: :archive
|
||||
end
|
||||
|
||||
namespace :assigns do
|
||||
get 'show' # delete after fixed tests admin/instructeurs/show_spec without this line
|
||||
end
|
||||
|
@ -404,6 +400,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
put 'clone'
|
||||
put 'archive'
|
||||
get 'publication' => 'procedures#publication', as: :publication
|
||||
put 'publish' => 'procedures#publish', as: :publish
|
||||
get 'transfert' => 'procedures#transfert', as: :transfert
|
||||
|
|
|
@ -34,37 +34,4 @@ describe Admin::ProceduresController, type: :controller do
|
|||
before do
|
||||
sign_in(admin.user)
|
||||
end
|
||||
|
||||
describe 'PUT #archive' do
|
||||
let(:procedure) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) }
|
||||
|
||||
context 'when admin is the owner of the procedure' do
|
||||
before do
|
||||
put :archive, params: { procedure_id: procedure.id }
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
context 'when owner want archive procedure' do
|
||||
it { expect(procedure.close?).to be_truthy }
|
||||
it { expect(response).to redirect_to :admin_procedures }
|
||||
it { expect(flash[:notice]).to have_content 'Démarche close' }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when admin is not the owner of the procedure' do
|
||||
let(:admin_2) { create(:administrateur) }
|
||||
|
||||
before do
|
||||
sign_out(admin.user)
|
||||
sign_in(admin_2.user)
|
||||
|
||||
put :archive, params: { procedure_id: procedure.id }
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
it { expect(response).to redirect_to :admin_procedures }
|
||||
it { expect(flash[:alert]).to have_content 'Démarche inexistante' }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -343,6 +343,40 @@ describe NewAdministrateur::ProceduresController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'PUT #archive' do
|
||||
let(:procedure) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) }
|
||||
|
||||
context 'when the admin is an owner of the procedure' do
|
||||
before do
|
||||
put :archive, params: { procedure_id: procedure.id }
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
it 'archives the procedure' do
|
||||
expect(procedure.close?).to be_truthy
|
||||
expect(response).to redirect_to :admin_procedures
|
||||
expect(flash[:notice]).to have_content 'Démarche close'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the admin is not an owner of the procedure' do
|
||||
let(:admin_2) { create(:administrateur) }
|
||||
|
||||
before do
|
||||
sign_out(admin.user)
|
||||
sign_in(admin_2.user)
|
||||
|
||||
put :archive, params: { procedure_id: procedure.id }
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
it 'displays an error message' do
|
||||
expect(response).to redirect_to :admin_procedures
|
||||
expect(flash[:alert]).to have_content 'Démarche inexistante'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:procedure_draft) { create(:procedure, administrateurs: [admin]) }
|
||||
let(:procedure_published) { create(:procedure, :published, administrateurs: [admin]) }
|
||||
|
|
Loading…
Reference in a new issue