2015-10-26 15:54:20 +01:00
|
|
|
|
require 'spec_helper'
|
2017-07-20 14:51:57 +02:00
|
|
|
|
require 'uri'
|
2015-10-26 15:54:20 +01:00
|
|
|
|
|
|
|
|
|
describe Admin::ProceduresController, type: :controller do
|
|
|
|
|
let(:admin) { create(:administrateur) }
|
|
|
|
|
|
|
|
|
|
let(:bad_procedure_id) { 100000 }
|
|
|
|
|
|
2018-09-19 17:12:12 +02:00
|
|
|
|
let(:path) { 'ma-jolie-demarche' }
|
2018-09-05 14:48:42 +02:00
|
|
|
|
let(:libelle) { 'Démarche de test' }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
let(:description) { 'Description de test' }
|
|
|
|
|
let(:organisation) { 'Organisation de test' }
|
|
|
|
|
let(:direction) { 'Direction de test' }
|
2018-04-24 16:02:36 +02:00
|
|
|
|
let(:cadre_juridique) { 'cadre juridique' }
|
2018-05-24 14:48:52 +02:00
|
|
|
|
let(:duree_conservation_dossiers_dans_ds) { 3 }
|
|
|
|
|
let(:duree_conservation_dossiers_hors_ds) { 6 }
|
2019-07-17 15:34:10 +02:00
|
|
|
|
let(:monavis_embed) { nil }
|
2019-07-11 16:07:00 +02:00
|
|
|
|
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
|
|
|
|
|
let(:procedure_params) {
|
|
|
|
|
{
|
2018-09-19 17:12:12 +02:00
|
|
|
|
path: path,
|
2018-01-15 19:02:12 +01:00
|
|
|
|
libelle: libelle,
|
|
|
|
|
description: description,
|
|
|
|
|
organisation: organisation,
|
|
|
|
|
direction: direction,
|
2018-05-02 15:41:43 +02:00
|
|
|
|
cadre_juridique: cadre_juridique,
|
2018-05-24 14:48:52 +02:00
|
|
|
|
duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds,
|
2019-07-16 17:24:31 +02:00
|
|
|
|
duree_conservation_dossiers_hors_ds: duree_conservation_dossiers_hors_ds,
|
2019-07-11 16:07:00 +02:00
|
|
|
|
monavis_embed: monavis_embed,
|
|
|
|
|
lien_site_web: lien_site_web
|
2015-10-26 15:54:20 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
before do
|
2019-08-09 10:46:39 +02:00
|
|
|
|
sign_in(admin.user)
|
2015-10-26 15:54:20 +01:00
|
|
|
|
end
|
|
|
|
|
|
2015-11-26 16:00:12 +01:00
|
|
|
|
describe 'GET #index' do
|
2015-11-27 16:23:02 +01:00
|
|
|
|
subject { get :index }
|
|
|
|
|
|
|
|
|
|
it { expect(response.status).to eq(200) }
|
|
|
|
|
end
|
|
|
|
|
|
2018-01-30 14:43:56 +01:00
|
|
|
|
describe 'GET #index with sorting and pagination' do
|
2018-12-28 18:24:39 +01:00
|
|
|
|
before do
|
2019-02-26 16:57:04 +01:00
|
|
|
|
create(:procedure, administrateur: admin)
|
|
|
|
|
admin.reload
|
2018-12-28 18:24:39 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-01-30 14:43:56 +01:00
|
|
|
|
subject {
|
2018-01-23 18:16:44 +01:00
|
|
|
|
get :index, params: {
|
2018-01-30 14:43:56 +01:00
|
|
|
|
'procedures_smart_listing[page]': 1,
|
|
|
|
|
'procedures_smart_listing[per_page]': 10,
|
|
|
|
|
'procedures_smart_listing[sort][id]': 'asc'
|
2018-01-23 18:16:44 +01:00
|
|
|
|
}
|
2018-01-30 14:43:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq(200) }
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-27 16:23:02 +01:00
|
|
|
|
describe 'GET #archived' do
|
|
|
|
|
subject { get :archived }
|
2015-11-26 16:00:12 +01:00
|
|
|
|
|
|
|
|
|
it { expect(response.status).to eq(200) }
|
|
|
|
|
end
|
|
|
|
|
|
2018-01-30 14:43:56 +01:00
|
|
|
|
describe 'GET #archived with sorting and pagination' do
|
|
|
|
|
subject {
|
2018-01-23 18:16:44 +01:00
|
|
|
|
get :archived, params: {
|
2018-01-30 14:43:56 +01:00
|
|
|
|
'procedures_smart_listing[page]': 1,
|
|
|
|
|
'procedures_smart_listing[per_page]': 10,
|
|
|
|
|
'procedures_smart_listing[sort][libelle]': 'asc'
|
2018-01-23 18:16:44 +01:00
|
|
|
|
}
|
2018-01-30 14:43:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq(200) }
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
|
describe 'GET #published' do
|
|
|
|
|
subject { get :published }
|
|
|
|
|
|
|
|
|
|
it { expect(response.status).to eq(200) }
|
|
|
|
|
end
|
|
|
|
|
|
2018-01-30 14:43:56 +01:00
|
|
|
|
describe 'GET #draft with sorting and pagination' do
|
|
|
|
|
subject {
|
2018-01-23 18:16:44 +01:00
|
|
|
|
get :draft, params: {
|
2018-01-30 14:43:56 +01:00
|
|
|
|
'procedures_smart_listing[page]': 1,
|
|
|
|
|
'procedures_smart_listing[per_page]': 10,
|
|
|
|
|
'procedures_smart_listing[sort][published_at]': 'asc'
|
2018-01-23 18:16:44 +01:00
|
|
|
|
}
|
2018-01-30 14:43:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq(200) }
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-21 17:59:56 +01:00
|
|
|
|
describe 'DELETE #destroy' do
|
2019-11-14 09:43:45 +01:00
|
|
|
|
let(:procedure_draft) { create :procedure_with_dossiers, administrateur: admin, instructeurs: [admin.instructeur], published_at: nil, closed_at: nil }
|
|
|
|
|
let(:procedure_published) { create :procedure_with_dossiers, administrateur: admin, instructeurs: [admin.instructeur], aasm_state: :publiee, published_at: Time.zone.now, closed_at: nil }
|
|
|
|
|
let(:procedure_closed) { create :procedure_with_dossiers, administrateur: admin, instructeurs: [admin.instructeur], aasm_state: :close, published_at: nil, closed_at: Time.zone.now }
|
2017-12-21 17:59:56 +01:00
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
|
subject { delete :destroy, params: { id: procedure.id } }
|
2017-12-21 17:59:56 +01:00
|
|
|
|
|
2019-01-23 16:11:16 +01:00
|
|
|
|
context 'when the procedure is a draft' do
|
2017-12-21 17:59:56 +01:00
|
|
|
|
let!(:procedure) { procedure_draft }
|
|
|
|
|
|
2019-01-23 16:11:16 +01:00
|
|
|
|
it 'destroys the procedure' do
|
|
|
|
|
expect { subject }.to change { Procedure.count }.by(-1)
|
2017-12-21 17:59:56 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-01-23 16:13:14 +01:00
|
|
|
|
it 'deletes associated dossiers' do
|
|
|
|
|
subject
|
|
|
|
|
expect(Dossier.find_by(procedure_id: procedure.id)).to be_blank
|
|
|
|
|
end
|
|
|
|
|
|
2019-01-23 16:11:16 +01:00
|
|
|
|
it 'redirects to the procedure drafts page' do
|
2017-12-21 17:59:56 +01:00
|
|
|
|
subject
|
2019-01-23 16:11:16 +01:00
|
|
|
|
expect(response).to redirect_to admin_procedures_draft_path
|
|
|
|
|
expect(flash[:notice]).to be_present
|
2017-12-21 17:59:56 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when procedure is published' do
|
2019-01-23 16:13:14 +01:00
|
|
|
|
let!(:procedure) { procedure_published }
|
2017-12-21 17:59:56 +01:00
|
|
|
|
|
2019-01-23 16:13:14 +01:00
|
|
|
|
it { expect { subject }.not_to change { Procedure.count } }
|
|
|
|
|
it { expect { subject }.not_to change { Dossier.count } }
|
2017-12-21 17:59:56 +01:00
|
|
|
|
it { expect(subject.status).to eq 401 }
|
|
|
|
|
end
|
|
|
|
|
|
2019-11-14 09:43:45 +01:00
|
|
|
|
context 'when procedure is closed' do
|
|
|
|
|
let!(:procedure) { procedure_closed }
|
2017-12-21 17:59:56 +01:00
|
|
|
|
|
2019-01-23 16:13:14 +01:00
|
|
|
|
it { expect { subject }.not_to change { Procedure.count } }
|
|
|
|
|
it { expect { subject }.not_to change { Dossier.count } }
|
2017-12-21 17:59:56 +01:00
|
|
|
|
it { expect(subject.status).to eq 401 }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when administrateur does not own the procedure" do
|
2019-11-14 09:43:45 +01:00
|
|
|
|
let(:procedure_not_owned) { create :procedure, administrateur: create(:administrateur), published_at: nil, closed_at: nil }
|
2017-12-21 17:59:56 +01:00
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
|
subject { delete :destroy, params: { id: procedure_not_owned.id } }
|
2017-12-21 17:59:56 +01:00
|
|
|
|
|
2018-12-24 17:28:20 +01:00
|
|
|
|
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
2017-12-21 17:59:56 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-24 16:41:44 +02:00
|
|
|
|
describe 'PUT #publish' do
|
2019-07-23 12:09:48 +02:00
|
|
|
|
let(:procedure) { create(:procedure, administrateur: admin, lien_site_web: lien_site_web) }
|
2019-07-11 16:07:00 +02:00
|
|
|
|
let(:procedure2) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) }
|
|
|
|
|
let(:procedure3) { create(:procedure, :published, lien_site_web: lien_site_web) }
|
2019-07-11 11:49:01 +02:00
|
|
|
|
let(:lien_site_web) { 'http://some.administration/' }
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
|
|
context 'when admin is the owner of the procedure' do
|
|
|
|
|
before do
|
2019-07-30 16:54:43 +02:00
|
|
|
|
put :publish, format: :js, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web }
|
2016-06-24 16:41:44 +02:00
|
|
|
|
procedure.reload
|
|
|
|
|
procedure2.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'procedure path does not exist' do
|
2018-10-30 12:00:58 +01:00
|
|
|
|
let(:path) { 'new_path' }
|
2019-07-23 12:09:48 +02:00
|
|
|
|
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
|
|
it 'publish the given procedure' do
|
2017-07-13 15:14:28 +02:00
|
|
|
|
expect(procedure.publiee?).to be_truthy
|
2018-10-30 12:00:58 +01:00
|
|
|
|
expect(procedure.path).to eq(path)
|
2019-07-11 11:49:01 +02:00
|
|
|
|
expect(procedure.lien_site_web).to eq(lien_site_web)
|
2018-05-17 15:43:33 +02:00
|
|
|
|
expect(response.status).to eq 302
|
2018-09-05 14:48:42 +02:00
|
|
|
|
expect(flash[:notice]).to have_content 'Démarche publiée'
|
2016-06-24 16:41:44 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'procedure path exists and is owned by current administrator' do
|
2018-10-30 12:00:58 +01:00
|
|
|
|
let(:path) { procedure2.path }
|
2019-07-23 12:09:48 +02:00
|
|
|
|
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
|
|
it 'publish the given procedure' do
|
2017-07-13 15:14:28 +02:00
|
|
|
|
expect(procedure.publiee?).to be_truthy
|
2018-10-30 12:00:58 +01:00
|
|
|
|
expect(procedure.path).to eq(path)
|
2019-07-11 11:49:01 +02:00
|
|
|
|
expect(procedure.lien_site_web).to eq(lien_site_web)
|
2018-05-17 15:43:33 +02:00
|
|
|
|
expect(response.status).to eq 302
|
2018-09-05 14:48:42 +02:00
|
|
|
|
expect(flash[:notice]).to have_content 'Démarche publiée'
|
2016-06-24 16:41:44 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'archive previous procedure' do
|
2019-11-14 09:43:45 +01:00
|
|
|
|
expect(procedure2.close?).to be_truthy
|
2016-06-24 16:41:44 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'procedure path exists and is not owned by current administrator' do
|
2018-10-30 12:00:58 +01:00
|
|
|
|
let(:path) { procedure3.path }
|
2019-07-23 12:09:48 +02:00
|
|
|
|
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
|
|
it 'does not publish the given procedure' do
|
2017-07-13 15:14:28 +02:00
|
|
|
|
expect(procedure.publiee?).to be_falsey
|
2019-03-06 14:42:27 +01:00
|
|
|
|
expect(procedure.path).not_to match(path)
|
2019-07-23 12:09:48 +02:00
|
|
|
|
expect(procedure.lien_site_web).to match(lien_site_web)
|
2016-06-24 16:41:44 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'previous procedure remains published' do
|
2017-07-13 15:14:28 +02:00
|
|
|
|
expect(procedure2.publiee?).to be_truthy
|
2019-11-14 09:43:45 +01:00
|
|
|
|
expect(procedure2.close?).to be_falsey
|
2016-06-24 16:41:44 +02:00
|
|
|
|
expect(procedure2.path).to match(/fake_path/)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'procedure path is invalid' do
|
2018-10-30 12:00:58 +01:00
|
|
|
|
let(:path) { 'Invalid Procedure Path' }
|
2019-07-23 12:09:48 +02:00
|
|
|
|
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
|
|
it 'does not publish the given procedure' do
|
2017-07-13 15:14:28 +02:00
|
|
|
|
expect(procedure.publiee?).to be_falsey
|
2019-03-06 14:42:27 +01:00
|
|
|
|
expect(procedure.path).not_to match(path)
|
2019-07-23 12:09:48 +02:00
|
|
|
|
expect(procedure.lien_site_web).to match(lien_site_web)
|
2016-06-24 16:41:44 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when admin is not the owner of the procedure' do
|
|
|
|
|
let(:admin_2) { create(:administrateur) }
|
|
|
|
|
|
|
|
|
|
before do
|
2019-08-09 10:46:39 +02:00
|
|
|
|
sign_out(admin.user)
|
|
|
|
|
sign_in(admin_2.user)
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
2018-10-30 12:00:58 +01:00
|
|
|
|
put :publish, params: { procedure_id: procedure.id, path: 'fake_path' }
|
2016-06-24 16:41:44 +02:00
|
|
|
|
procedure.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'fails' do
|
2019-07-30 16:54:43 +02:00
|
|
|
|
expect(response).to have_http_status(404)
|
2016-06-24 16:41:44 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-07-23 12:09:48 +02:00
|
|
|
|
|
|
|
|
|
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 }
|
|
|
|
|
procedure.reload
|
|
|
|
|
end
|
|
|
|
|
context 'procedure path is valid but lien_site_web is missing' do
|
|
|
|
|
let(:path) { 'new_path2' }
|
|
|
|
|
let(:lien_site_web) { nil }
|
|
|
|
|
|
|
|
|
|
it 'does not publish the given procedure' do
|
|
|
|
|
expect(procedure.publiee?).to be_falsey
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-06-24 16:41:44 +02:00
|
|
|
|
end
|
|
|
|
|
|
2015-11-26 18:41:41 +01:00
|
|
|
|
describe 'PUT #archive' do
|
2019-07-11 16:07:00 +02:00
|
|
|
|
let(:procedure) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) }
|
2015-11-26 18:41:41 +01:00
|
|
|
|
|
|
|
|
|
context 'when admin is the owner of the procedure' do
|
|
|
|
|
before do
|
2018-01-16 13:34:24 +01:00
|
|
|
|
put :archive, params: { procedure_id: procedure.id }
|
2015-11-26 18:41:41 +01:00
|
|
|
|
procedure.reload
|
|
|
|
|
end
|
|
|
|
|
|
2015-12-02 16:52:09 +01:00
|
|
|
|
context 'when owner want archive procedure' do
|
2019-11-14 09:43:45 +01:00
|
|
|
|
it { expect(procedure.close?).to be_truthy }
|
2015-12-02 16:52:09 +01:00
|
|
|
|
it { expect(response).to redirect_to :admin_procedures }
|
2019-11-14 09:43:45 +01:00
|
|
|
|
it { expect(flash[:notice]).to have_content 'Démarche close' }
|
2015-12-02 16:52:09 +01:00
|
|
|
|
end
|
|
|
|
|
|
2016-06-30 10:24:01 +02:00
|
|
|
|
context 'when owner want to re-enable procedure' do
|
2016-06-24 16:57:35 +02:00
|
|
|
|
before do
|
2019-07-11 16:07:00 +02:00
|
|
|
|
put :publish, params: { procedure_id: procedure.id, path: 'fake_path', lien_site_web: lien_site_web }
|
2016-06-24 16:57:35 +02:00
|
|
|
|
procedure.reload
|
|
|
|
|
end
|
2015-12-02 16:52:09 +01:00
|
|
|
|
|
2018-05-17 15:43:33 +02:00
|
|
|
|
it { expect(procedure.publiee?).to be_truthy }
|
|
|
|
|
it { expect(response.status).to eq 302 }
|
2018-09-05 14:48:42 +02:00
|
|
|
|
it { expect(flash[:notice]).to have_content 'Démarche publiée' }
|
2015-12-02 16:52:09 +01:00
|
|
|
|
end
|
2015-11-26 18:41:41 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when admin is not the owner of the procedure' do
|
|
|
|
|
let(:admin_2) { create(:administrateur) }
|
|
|
|
|
|
|
|
|
|
before do
|
2019-08-09 10:46:39 +02:00
|
|
|
|
sign_out(admin.user)
|
|
|
|
|
sign_in(admin_2.user)
|
2015-11-26 18:41:41 +01:00
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
|
put :archive, params: { procedure_id: procedure.id }
|
2015-11-26 18:41:41 +01:00
|
|
|
|
procedure.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(response).to redirect_to :admin_procedures }
|
2018-09-05 14:48:42 +02:00
|
|
|
|
it { expect(flash[:alert]).to have_content 'Démarche inexistante' }
|
2015-11-26 18:41:41 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2016-06-15 11:34:05 +02:00
|
|
|
|
|
|
|
|
|
describe 'PUT #clone' do
|
2018-05-31 11:00:22 +02:00
|
|
|
|
let!(:procedure) { create(:procedure, :with_notice, :with_deliberation, administrateur: admin) }
|
2018-04-12 18:35:13 +02:00
|
|
|
|
let(:params) { { procedure_id: procedure.id } }
|
|
|
|
|
subject { put :clone, params: params }
|
2016-06-15 11:34:05 +02:00
|
|
|
|
|
2018-04-26 14:36:27 +02:00
|
|
|
|
before do
|
|
|
|
|
response = Typhoeus::Response.new(code: 200, body: 'Hello world')
|
|
|
|
|
Typhoeus.stub(/active_storage\/disk/).and_return(response)
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-20 17:37:04 +02:00
|
|
|
|
it { expect { subject }.to change(Procedure, :count).by(1) }
|
2016-06-15 11:34:05 +02:00
|
|
|
|
|
|
|
|
|
context 'when admin is the owner of the procedure' do
|
2018-04-12 18:35:13 +02:00
|
|
|
|
before { subject }
|
2016-06-15 11:34:05 +02:00
|
|
|
|
|
|
|
|
|
it 'creates a new procedure and redirect to it' do
|
|
|
|
|
expect(response).to redirect_to edit_admin_procedure_path(id: Procedure.last.id)
|
2018-04-26 14:36:27 +02:00
|
|
|
|
expect(Procedure.last.cloned_from_library).to be_falsey
|
|
|
|
|
expect(Procedure.last.notice.attached?).to be_truthy
|
2018-05-31 11:00:22 +02:00
|
|
|
|
expect(Procedure.last.deliberation.attached?).to be_truthy
|
2018-09-05 14:48:42 +02:00
|
|
|
|
expect(flash[:notice]).to have_content 'Démarche clonée'
|
2016-06-15 11:34:05 +02:00
|
|
|
|
end
|
2018-04-12 18:35:13 +02:00
|
|
|
|
|
|
|
|
|
context 'when the procedure is cloned from the library' do
|
|
|
|
|
let(:params) { { procedure_id: procedure.id, from_new_from_existing: true } }
|
|
|
|
|
|
|
|
|
|
it { expect(Procedure.last.cloned_from_library).to be(true) }
|
|
|
|
|
end
|
2016-06-15 11:34:05 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when admin is not the owner of the procedure' do
|
|
|
|
|
let(:admin_2) { create(:administrateur) }
|
|
|
|
|
|
|
|
|
|
before do
|
2019-08-09 10:46:39 +02:00
|
|
|
|
sign_out(admin.user)
|
|
|
|
|
sign_in(admin_2.user)
|
2016-06-15 11:34:05 +02:00
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
2018-01-08 14:44:28 +01:00
|
|
|
|
it 'creates a new procedure and redirect to it' do
|
|
|
|
|
expect(response).to redirect_to edit_admin_procedure_path(id: Procedure.last.id)
|
2018-09-05 14:48:42 +02:00
|
|
|
|
expect(flash[:notice]).to have_content 'Démarche clonée'
|
2018-01-08 14:44:28 +01:00
|
|
|
|
end
|
2016-06-15 11:34:05 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
2018-07-03 20:18:06 +02:00
|
|
|
|
describe 'GET #new_from_existing' do
|
|
|
|
|
before do
|
|
|
|
|
stub_const("Admin::ProceduresController::SIGNIFICANT_DOSSIERS_THRESHOLD", 2)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
subject { get :new_from_existing }
|
|
|
|
|
let(:grouped_procedures) { subject; assigns(:grouped_procedures) }
|
2018-12-24 17:53:16 +01:00
|
|
|
|
let(:response_procedures) { grouped_procedures.map { |_o, procedures| procedures }.flatten }
|
2018-07-03 20:18:06 +02:00
|
|
|
|
|
|
|
|
|
describe 'selecting' do
|
|
|
|
|
let!(:large_draft_procedure) { create(:procedure_with_dossiers, dossiers_count: 2) }
|
|
|
|
|
let!(:large_published_procedure) { create(:procedure_with_dossiers, :published, dossiers_count: 2) }
|
2019-11-14 09:43:45 +01:00
|
|
|
|
let!(:large_closed_procedure) { create(:procedure_with_dossiers, :closed, dossiers_count: 2) }
|
|
|
|
|
let!(:small_closed_procedure) { create(:procedure_with_dossiers, :closed, dossiers_count: 1) }
|
2018-07-03 20:18:06 +02:00
|
|
|
|
|
2019-11-14 09:43:45 +01:00
|
|
|
|
it 'displays published and closed procedures' do
|
2018-07-03 20:18:06 +02:00
|
|
|
|
expect(response_procedures).to include(large_published_procedure)
|
2019-11-14 09:43:45 +01:00
|
|
|
|
expect(response_procedures).to include(large_closed_procedure)
|
2018-07-03 20:18:06 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'doesn’t display procedures without a significant number of dossiers' do
|
2019-11-14 09:43:45 +01:00
|
|
|
|
expect(response_procedures).not_to include(small_closed_procedure)
|
2018-07-03 20:18:06 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'doesn’t display draft procedures' do
|
|
|
|
|
expect(response_procedures).not_to include(large_draft_procedure)
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-07-03 20:18:49 +02:00
|
|
|
|
|
|
|
|
|
describe 'grouping' do
|
|
|
|
|
let(:service_1) { create(:service, nom: 'DDT des Vosges') }
|
|
|
|
|
let(:service_2) { create(:service, nom: 'DDT du Loiret') }
|
|
|
|
|
let!(:procedure_with_service_1) { create(:procedure_with_dossiers, :published, organisation: nil, service: service_1, dossiers_count: 2) }
|
|
|
|
|
let!(:procedure_with_service_2) { create(:procedure_with_dossiers, :published, organisation: nil, service: service_2, dossiers_count: 2) }
|
|
|
|
|
let!(:procedure_without_service) { create(:procedure_with_dossiers, :published, organisation: 'DDT du Loiret', dossiers_count: 2) }
|
|
|
|
|
|
|
|
|
|
it 'groups procedures with services as well as procedures with organisations' do
|
|
|
|
|
expect(grouped_procedures.length).to eq 2
|
2018-12-24 17:53:16 +01:00
|
|
|
|
expect(grouped_procedures.find { |o, _p| o == 'DDT des Vosges' }.last).to contain_exactly(procedure_with_service_1)
|
|
|
|
|
expect(grouped_procedures.find { |o, _p| o == 'DDT du Loiret' }.last).to contain_exactly(procedure_with_service_2, procedure_without_service)
|
2018-07-03 20:18:49 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-07-03 20:18:06 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-05-17 15:34:51 +02:00
|
|
|
|
describe 'POST #transfer' do
|
2018-12-19 15:35:07 +01:00
|
|
|
|
let!(:procedure) { create :procedure, :with_service, administrateur: admin }
|
2016-07-22 11:34:34 +02:00
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
|
subject { post :transfer, params: { email_admin: email_admin, procedure_id: procedure.id } }
|
2016-07-22 11:34:34 +02:00
|
|
|
|
|
|
|
|
|
context 'when admin is unknow' do
|
|
|
|
|
let(:email_admin) { 'plop' }
|
|
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 404 }
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-26 16:06:53 +02:00
|
|
|
|
context 'when admin is known' do
|
|
|
|
|
let!(:new_admin) { create :administrateur, email: 'new_admin@admin.com' }
|
2016-07-22 11:34:34 +02:00
|
|
|
|
|
2017-06-26 16:06:53 +02:00
|
|
|
|
context "and its email address is correct" do
|
|
|
|
|
let(:email_admin) { 'new_admin@admin.com' }
|
|
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 200 }
|
2018-12-19 15:35:07 +01:00
|
|
|
|
it { expect { subject }.to change(new_admin.procedures, :count).by(1) }
|
|
|
|
|
|
|
|
|
|
it "should create a new service" do
|
|
|
|
|
subject
|
|
|
|
|
expect(new_admin.procedures.last.service_id).not_to eq(procedure.service_id)
|
|
|
|
|
end
|
2017-06-26 16:06:53 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when admin is know but its email was not downcased' do
|
|
|
|
|
let(:email_admin) { "NEW_admin@adMIN.com" }
|
|
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 200 }
|
|
|
|
|
it { expect { subject }.to change(Procedure, :count).by(1) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "correctly assigns the new admin" do
|
|
|
|
|
let(:email_admin) { 'new_admin@admin.com' }
|
2016-07-22 11:34:34 +02:00
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
2019-02-26 16:57:04 +01:00
|
|
|
|
it { expect(Procedure.last.administrateurs).to eq [new_admin] }
|
2017-06-26 16:06:53 +02:00
|
|
|
|
end
|
2016-07-22 11:34:34 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-07-20 14:44:54 +02:00
|
|
|
|
|
2018-05-31 11:15:44 +02:00
|
|
|
|
describe "DELETE #delete_deliberation" do
|
2018-10-02 10:14:38 +02:00
|
|
|
|
context "with a demarche the admin owns" do
|
|
|
|
|
let(:procedure) { create(:procedure, :with_deliberation, administrateur: admin) }
|
2018-05-31 11:15:44 +02:00
|
|
|
|
|
2018-10-02 10:14:38 +02:00
|
|
|
|
before do
|
|
|
|
|
delete :delete_deliberation, params: { id: procedure.id }
|
|
|
|
|
procedure.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(procedure.deliberation.attached?).to eq(false) }
|
|
|
|
|
it { expect(response).to redirect_to(edit_admin_procedure_path(procedure)) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "with a demarche the admin does not own" do
|
|
|
|
|
let(:procedure) { create(:procedure, :with_deliberation) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
delete :delete_deliberation, params: { id: procedure.id }
|
|
|
|
|
procedure.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(response.status).to eq(404) }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "DELETE #delete_notice" do
|
|
|
|
|
context "with a demarche the admin owns" do
|
|
|
|
|
let(:procedure) { create(:procedure, :with_notice, administrateur: admin) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
delete :delete_notice, params: { id: procedure.id }
|
|
|
|
|
procedure.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(procedure.notice.attached?).to eq(false) }
|
|
|
|
|
it { expect(response).to redirect_to(edit_admin_procedure_path(procedure)) }
|
2018-05-31 11:15:44 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-10-02 10:14:38 +02:00
|
|
|
|
context "with a demarche the admin does not own" do
|
|
|
|
|
let(:procedure) { create(:procedure, :with_notice) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
delete :delete_notice, params: { id: procedure.id }
|
|
|
|
|
procedure.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(response.status).to eq(404) }
|
|
|
|
|
end
|
2018-05-31 11:15:44 +02:00
|
|
|
|
end
|
2015-10-26 15:54:20 +01:00
|
|
|
|
end
|