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 }
|
|
|
|
|
|
|
|
let(:libelle) { 'Procédure de test' }
|
|
|
|
let(:description) { 'Description de test' }
|
|
|
|
let(:organisation) { 'Organisation de test' }
|
|
|
|
let(:direction) { 'Direction de test' }
|
|
|
|
let(:lien_demarche) { 'http://localhost.com' }
|
2018-04-24 16:02:36 +02:00
|
|
|
let(:cadre_juridique) { 'cadre juridique' }
|
2015-12-08 10:11:58 +01:00
|
|
|
let(:use_api_carto) { '0' }
|
|
|
|
let(:quartiers_prioritaires) { '0' }
|
|
|
|
let(:cadastre) { '0' }
|
2018-05-24 14:48:52 +02:00
|
|
|
let(:duree_conservation_dossiers_dans_ds) { 3 }
|
|
|
|
let(:duree_conservation_dossiers_hors_ds) { 6 }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
|
|
|
let(:procedure_params) {
|
|
|
|
{
|
2018-01-15 19:02:12 +01:00
|
|
|
libelle: libelle,
|
|
|
|
description: description,
|
|
|
|
organisation: organisation,
|
|
|
|
direction: direction,
|
|
|
|
lien_demarche: lien_demarche,
|
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,
|
|
|
|
duree_conservation_dossiers_hors_ds: duree_conservation_dossiers_hors_ds,
|
2018-01-15 19:02:12 +01:00
|
|
|
module_api_carto_attributes: {
|
|
|
|
use_api_carto: use_api_carto,
|
|
|
|
quartiers_prioritaires: quartiers_prioritaires,
|
|
|
|
cadastre: cadastre
|
|
|
|
}
|
2015-10-26 15:54:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in admin
|
|
|
|
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
|
|
|
|
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
|
|
|
|
let(:procedure_draft) { create :procedure, administrateur: admin, published_at: nil, archived_at: nil }
|
2018-05-17 15:43:33 +02:00
|
|
|
let(:procedure_published) { create :procedure, administrateur: admin, aasm_state: :publiee, published_at: Time.now, archived_at: nil }
|
|
|
|
let(:procedure_archived) { create :procedure, administrateur: admin, aasm_state: :archivee, published_at: nil, archived_at: Time.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
|
|
|
|
|
|
|
context 'when procedure is draft' do
|
|
|
|
let!(:procedure) { procedure_draft }
|
|
|
|
|
|
|
|
describe 'tech params' do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 302 }
|
|
|
|
it { expect(flash[:notice]).to be_present }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'destroy procedure is call' do
|
|
|
|
expect_any_instance_of(Procedure).to receive(:destroy)
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { subject }.to change { Procedure.count }.by(-1) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure is published' do
|
|
|
|
let(:procedure) { procedure_published }
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 401 }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure is archived' do
|
|
|
|
let(:procedure) { procedure_published }
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 401 }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when administrateur does not own the procedure" do
|
|
|
|
let(:procedure_not_owned) { create :procedure, administrateur: create(:administrateur), published_at: nil, archived_at: nil }
|
|
|
|
|
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
|
|
|
|
|
|
|
it { expect{ subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-04 16:17:35 +01:00
|
|
|
describe 'GET #edit' do
|
2017-07-11 14:21:10 +02:00
|
|
|
let(:published_at) { nil }
|
|
|
|
let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
|
2015-11-04 17:27:01 +01:00
|
|
|
let(:procedure_id) { procedure.id }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { get :edit, params: { id: procedure_id } }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
|
|
|
context 'when user is not connected' do
|
|
|
|
before do
|
|
|
|
sign_out admin
|
|
|
|
end
|
|
|
|
|
2017-02-15 17:09:25 +01:00
|
|
|
it { is_expected.to redirect_to new_user_session_path }
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is connected' do
|
|
|
|
context 'when procedure exist' do
|
2015-10-26 18:08:41 +01:00
|
|
|
let(:procedure_id) { procedure.id }
|
2017-02-15 17:09:25 +01:00
|
|
|
it { is_expected.to have_http_status(:success) }
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
context 'when procedure is published' do
|
2017-07-11 14:21:10 +02:00
|
|
|
let(:published_at) { Time.now }
|
2017-02-15 17:09:25 +01:00
|
|
|
it { is_expected.to have_http_status(:success) }
|
2015-12-21 12:02:53 +01:00
|
|
|
end
|
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
context "when procedure doesn't exist" do
|
2015-10-26 18:08:41 +01:00
|
|
|
let(:procedure_id) { bad_procedure_id }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
2017-02-15 17:09:25 +01:00
|
|
|
it { is_expected.to have_http_status(404) }
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
2015-11-04 17:27:01 +01:00
|
|
|
context 'when all attributs are filled' do
|
2015-10-26 15:54:20 +01:00
|
|
|
describe 'new procedure in database' do
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { post :create, params: { procedure: procedure_params } }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
|
|
|
it { expect { subject }.to change { Procedure.count }.by(1) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure is correctly save' do
|
|
|
|
before do
|
2018-01-16 13:34:24 +01:00
|
|
|
post :create, params: { procedure: procedure_params }
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'procedure attributs in database' do
|
|
|
|
subject { Procedure.last }
|
|
|
|
|
|
|
|
it { expect(subject.libelle).to eq(libelle) }
|
|
|
|
it { expect(subject.description).to eq(description) }
|
|
|
|
it { expect(subject.organisation).to eq(organisation) }
|
|
|
|
it { expect(subject.direction).to eq(direction) }
|
|
|
|
it { expect(subject.lien_demarche).to eq(lien_demarche) }
|
2015-11-16 18:25:31 +01:00
|
|
|
it { expect(subject.administrateur_id).to eq(admin.id) }
|
2018-05-24 14:48:52 +02:00
|
|
|
it { expect(subject.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds) }
|
|
|
|
it { expect(subject.duree_conservation_dossiers_hors_ds).to eq(duree_conservation_dossiers_hors_ds) }
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
2015-12-08 10:11:58 +01:00
|
|
|
describe 'procedure module api carto attributs in database' do
|
|
|
|
let(:procedure) { Procedure.last }
|
|
|
|
let(:use_api_carto) { '1' }
|
|
|
|
let(:quartiers_prioritaires) { '1' }
|
|
|
|
|
|
|
|
subject { ModuleAPICarto.last }
|
|
|
|
|
|
|
|
it { expect(subject.procedure).to eq(procedure) }
|
|
|
|
it { expect(subject.use_api_carto).to be_truthy }
|
|
|
|
it { expect(subject.quartiers_prioritaires).to be_truthy }
|
|
|
|
end
|
|
|
|
|
2017-02-15 17:09:25 +01:00
|
|
|
it { is_expected.to redirect_to(admin_procedure_types_de_champ_path(procedure_id: Procedure.last.id)) }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
|
|
|
it { expect(flash[:notice]).to be_present }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when many attributs are not valid' do
|
|
|
|
let(:libelle) { '' }
|
|
|
|
let(:description) { '' }
|
|
|
|
|
|
|
|
describe 'no new procedure in database' do
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { post :create, params: { procedure: procedure_params } }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
|
|
|
it { expect { subject }.to change { Procedure.count }.by(0) }
|
2015-12-08 10:11:58 +01:00
|
|
|
|
|
|
|
describe 'no new module api carto in database' do
|
|
|
|
it { expect { subject }.to change { ModuleAPICarto.count }.by(0) }
|
|
|
|
end
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'flash message is present' do
|
|
|
|
before do
|
2018-01-16 13:34:24 +01:00
|
|
|
post :create, params: { procedure: procedure_params }
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(flash[:alert]).to be_present }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT #update' do
|
2015-11-27 10:39:05 +01:00
|
|
|
let!(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, administrateur: admin) }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
|
|
|
context 'when administrateur is not connected' do
|
|
|
|
before do
|
|
|
|
sign_out admin
|
|
|
|
end
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { put :update, params: { id: procedure.id } }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
2017-02-15 17:09:25 +01:00
|
|
|
it { is_expected.to redirect_to new_user_session_path }
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when administrateur is connected' do
|
|
|
|
before do
|
2018-01-16 13:34:24 +01:00
|
|
|
put :update, params: { id: procedure.id, procedure: procedure_params }
|
2015-10-26 15:54:20 +01:00
|
|
|
procedure.reload
|
|
|
|
end
|
|
|
|
|
2017-02-15 17:09:25 +01:00
|
|
|
context 'when all attributs are present' do
|
2015-10-26 15:54:20 +01:00
|
|
|
let(:libelle) { 'Blable' }
|
|
|
|
let(:description) { 'blabla' }
|
|
|
|
let(:organisation) { 'plop' }
|
|
|
|
let(:direction) { 'plap' }
|
|
|
|
let(:lien_demarche) { 'http://plip.com' }
|
2015-12-08 10:11:58 +01:00
|
|
|
let(:use_api_carto) { '1' }
|
|
|
|
let(:cadastre) { '1' }
|
2018-05-24 14:48:52 +02:00
|
|
|
let(:duree_conservation_dossiers_dans_ds) { 7 }
|
|
|
|
let(:duree_conservation_dossiers_hors_ds) { 5 }
|
2015-10-26 15:54:20 +01:00
|
|
|
|
|
|
|
describe 'procedure attributs in database' do
|
|
|
|
subject { procedure }
|
|
|
|
|
|
|
|
it { expect(subject.libelle).to eq(libelle) }
|
|
|
|
it { expect(subject.description).to eq(description) }
|
|
|
|
it { expect(subject.organisation).to eq(organisation) }
|
|
|
|
it { expect(subject.direction).to eq(direction) }
|
|
|
|
it { expect(subject.lien_demarche).to eq(lien_demarche) }
|
2018-05-24 14:48:52 +02:00
|
|
|
it { expect(subject.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds) }
|
|
|
|
it { expect(subject.duree_conservation_dossiers_hors_ds).to eq(duree_conservation_dossiers_hors_ds) }
|
2015-12-08 10:11:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'procedure module api carto attributs in database' do
|
|
|
|
subject { procedure.module_api_carto }
|
|
|
|
|
|
|
|
it { expect(subject.use_api_carto).to be_truthy }
|
|
|
|
it { expect(subject.quartiers_prioritaires).to be_falsey }
|
|
|
|
it { expect(subject.cadastre).to be_truthy }
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
2017-02-15 17:09:25 +01:00
|
|
|
it { is_expected.to redirect_to(edit_admin_procedure_path id: procedure.id) }
|
2015-10-26 15:54:20 +01:00
|
|
|
it { expect(flash[:notice]).to be_present }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when many attributs are not valid' do
|
|
|
|
let(:libelle) { '' }
|
|
|
|
let(:description) { '' }
|
|
|
|
|
|
|
|
describe 'flash message is present' do
|
|
|
|
it { expect(flash[:alert]).to be_present }
|
|
|
|
end
|
2015-12-08 10:11:58 +01:00
|
|
|
|
|
|
|
describe 'procedure module api carto attributs in database' do
|
|
|
|
subject { procedure.module_api_carto }
|
|
|
|
|
|
|
|
it { expect(subject.use_api_carto).to be_falsey }
|
|
|
|
it { expect(subject.quartiers_prioritaires).to be_falsey }
|
|
|
|
it { expect(subject.cadastre).to be_falsey }
|
|
|
|
end
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
2017-02-15 17:09:25 +01:00
|
|
|
|
|
|
|
context 'when procedure is published' do
|
|
|
|
let!(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, :published, administrateur: admin) }
|
|
|
|
|
|
|
|
describe 'only some properties can be updated' do
|
|
|
|
subject { procedure }
|
|
|
|
|
|
|
|
it { expect(subject.libelle).to eq procedure_params[:libelle] }
|
|
|
|
it { expect(subject.description).to eq procedure_params[:description] }
|
|
|
|
it { expect(subject.organisation).to eq procedure_params[:organisation] }
|
|
|
|
it { expect(subject.direction).to eq procedure_params[:direction] }
|
|
|
|
|
|
|
|
it { expect(subject.lien_demarche).not_to eq procedure_params[:lien_demarche] }
|
|
|
|
it { expect(subject.for_individual).not_to eq procedure_params[:for_individual] }
|
|
|
|
it { expect(subject.individual_with_siret).not_to eq procedure_params[:individual_with_siret] }
|
|
|
|
it { expect(subject.use_api_carto).not_to eq procedure_params[:module_api_carto_attributes][:use_api_carto] }
|
|
|
|
end
|
|
|
|
end
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
end
|
2015-11-26 18:41:41 +01:00
|
|
|
|
2016-06-24 16:41:44 +02:00
|
|
|
describe 'PUT #publish' do
|
|
|
|
let(:procedure) { create(:procedure, administrateur: admin) }
|
|
|
|
let(:procedure2) { create(:procedure, :published, administrateur: admin) }
|
|
|
|
let(:procedure3) { create(:procedure, :published) }
|
|
|
|
|
|
|
|
context 'when admin is the owner of the procedure' do
|
|
|
|
before do
|
2018-01-16 13:34:24 +01:00
|
|
|
put :publish, params: { procedure_id: procedure.id, procedure_path: procedure_path }
|
2016-06-24 16:41:44 +02:00
|
|
|
procedure.reload
|
|
|
|
procedure2.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'procedure path does not exist' do
|
|
|
|
let(:procedure_path) { 'new_path' }
|
|
|
|
|
|
|
|
it 'publish the given procedure' do
|
2017-07-13 15:14:28 +02:00
|
|
|
expect(procedure.publiee?).to be_truthy
|
2016-06-24 16:41:44 +02:00
|
|
|
expect(procedure.path).to eq(procedure_path)
|
2018-05-17 15:43:33 +02:00
|
|
|
expect(response.status).to eq 302
|
2016-06-24 16:41:44 +02:00
|
|
|
expect(flash[:notice]).to have_content 'Procédure publiée'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'procedure path exists and is owned by current administrator' do
|
|
|
|
let(:procedure_path) { procedure2.path }
|
|
|
|
|
|
|
|
it 'publish the given procedure' do
|
2017-07-13 15:14:28 +02:00
|
|
|
expect(procedure.publiee?).to be_truthy
|
2016-06-24 16:41:44 +02:00
|
|
|
expect(procedure.path).to eq(procedure_path)
|
2018-05-17 15:43:33 +02:00
|
|
|
expect(response.status).to eq 302
|
2016-06-24 16:41:44 +02:00
|
|
|
expect(flash[:notice]).to have_content 'Procédure publiée'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'archive previous procedure' do
|
2017-07-13 15:09:25 +02:00
|
|
|
expect(procedure2.archivee?).to be_truthy
|
2016-12-21 11:00:05 +01:00
|
|
|
expect(procedure2.path).to be_nil
|
2016-06-24 16:41:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-29 11:44:44 +02:00
|
|
|
context 'procedure path exists and has archived procedure' do
|
|
|
|
let(:procedure_path) { procedure2.path }
|
|
|
|
let(:procedure2) { create(:procedure, :archived, administrateur: admin) }
|
|
|
|
|
|
|
|
it 'publish the given procedure' do
|
|
|
|
expect(procedure.publiee?).to be_truthy
|
|
|
|
expect(procedure.path).to eq(procedure_path)
|
|
|
|
expect(response.status).to eq 302
|
|
|
|
expect(flash[:notice]).to have_content 'Procédure publiée'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'archive previous procedure' do
|
|
|
|
expect(procedure2.archivee?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-24 16:41:44 +02:00
|
|
|
context 'procedure path exists and is not owned by current administrator' do
|
|
|
|
let(:procedure_path) { procedure3.path }
|
|
|
|
|
|
|
|
it 'does not publish the given procedure' do
|
2017-07-13 15:14:28 +02:00
|
|
|
expect(procedure.publiee?).to be_falsey
|
2016-06-24 16:41:44 +02:00
|
|
|
expect(procedure.path).to be_nil
|
2016-06-30 12:33:43 +02:00
|
|
|
expect(response.status).to eq 200
|
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
|
2017-07-13 15:09:25 +02:00
|
|
|
expect(procedure2.archivee?).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
|
|
|
|
let(:procedure_path) { 'Invalid Procedure Path' }
|
|
|
|
|
|
|
|
it 'does not publish the given procedure' do
|
2017-07-13 15:14:28 +02:00
|
|
|
expect(procedure.publiee?).to be_falsey
|
2016-06-24 16:41:44 +02:00
|
|
|
expect(procedure.path).to be_nil
|
|
|
|
expect(response).to redirect_to :admin_procedures
|
|
|
|
expect(flash[:alert]).to have_content 'Lien de la procédure invalide'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin is not the owner of the procedure' do
|
|
|
|
let(:admin_2) { create(:administrateur) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_out admin
|
|
|
|
sign_in admin_2
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
put :publish, params: { procedure_id: procedure.id, procedure_path: 'fake_path' }
|
2016-06-24 16:41:44 +02:00
|
|
|
procedure.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails' do
|
|
|
|
expect(response).to redirect_to :admin_procedures
|
2017-07-13 10:16:55 +02:00
|
|
|
expect(flash[:alert]).to have_content 'Procédure inexistante'
|
2016-06-24 16:41:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-26 18:41:41 +01:00
|
|
|
describe 'PUT #archive' do
|
2017-07-13 16:22:59 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, administrateur: admin) }
|
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
|
2017-07-13 15:09:25 +02:00
|
|
|
it { expect(procedure.archivee?).to be_truthy }
|
2015-12-02 16:52:09 +01:00
|
|
|
it { expect(response).to redirect_to :admin_procedures }
|
2016-06-24 16:41:44 +02:00
|
|
|
it { expect(flash[:notice]).to have_content 'Procédure archivée' }
|
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
|
2018-01-16 13:34:24 +01:00
|
|
|
put :publish, params: { procedure_id: procedure.id, procedure_path: 'fake_path' }
|
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 }
|
2016-06-24 16:57:35 +02:00
|
|
|
it { expect(flash[:notice]).to have_content 'Procédure 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
|
|
|
|
sign_out admin
|
|
|
|
sign_in admin_2
|
|
|
|
|
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 }
|
2017-07-13 10:16:55 +02:00
|
|
|
it { expect(flash[:alert]).to have_content 'Procédure 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
|
2016-06-15 11:34:05 +02:00
|
|
|
expect(flash[:notice]).to have_content 'Procédure clonée'
|
|
|
|
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
|
|
|
|
sign_out admin
|
|
|
|
sign_in admin_2
|
|
|
|
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)
|
|
|
|
expect(flash[:notice]).to have_content 'Procédure clonée'
|
|
|
|
end
|
2016-06-15 11:34:05 +02:00
|
|
|
end
|
|
|
|
end
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
describe 'GET #path_list' do
|
|
|
|
let!(:procedure) { create(:procedure, :published, administrateur: admin) }
|
|
|
|
let(:admin2) { create(:administrateur) }
|
|
|
|
let!(:procedure2) { create(:procedure, :published, administrateur: admin2) }
|
2016-11-07 17:08:33 +01:00
|
|
|
let!(:procedure3) { create(:procedure, :published, administrateur: admin2) }
|
|
|
|
|
2016-06-24 16:41:44 +02:00
|
|
|
subject { get :path_list }
|
2016-11-07 17:08:33 +01:00
|
|
|
|
2016-06-24 16:41:44 +02:00
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
2016-11-07 17:08:33 +01:00
|
|
|
describe 'when no params' do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
2016-06-24 16:41:44 +02:00
|
|
|
|
2016-11-07 17:08:33 +01:00
|
|
|
it { expect(response.status).to eq(200) }
|
|
|
|
it { expect(body.size).to eq(3) }
|
|
|
|
it { expect(body.first['label']).to eq(procedure.path) }
|
|
|
|
it { expect(body.first['mine']).to be_truthy }
|
|
|
|
it { expect(body.second['label']).to eq(procedure2.path) }
|
|
|
|
it { expect(body.second['mine']).to be_falsy }
|
|
|
|
end
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
context 'filtered' do
|
2016-11-07 17:08:33 +01:00
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2017-07-20 14:51:57 +02:00
|
|
|
subject { get :path_list, params: { request: URI.encode(procedure2.path) } }
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
it { expect(response.status).to eq(200) }
|
|
|
|
it { expect(body.size).to eq(1) }
|
|
|
|
it { expect(body.first['label']).to eq(procedure2.path) }
|
|
|
|
it { expect(body.first['mine']).to be_falsy }
|
|
|
|
end
|
2016-11-07 17:08:33 +01:00
|
|
|
|
|
|
|
context 'when procedure is archived' do
|
|
|
|
before do
|
2017-07-10 23:42:33 +02:00
|
|
|
procedure3.update_attribute :archived_at, Time.now
|
2016-11-07 17:08:33 +01:00
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'do not return on the json' do
|
|
|
|
expect(body.size).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
2016-06-24 16:41:44 +02:00
|
|
|
end
|
|
|
|
|
2018-05-17 15:34:51 +02:00
|
|
|
describe 'POST #transfer' do
|
2016-07-22 11:34:34 +02:00
|
|
|
let!(:procedure) { create :procedure, administrateur: admin }
|
|
|
|
|
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 }
|
|
|
|
it { expect { subject }.to change(Procedure, :count).by(1) }
|
|
|
|
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
|
|
|
|
|
|
|
|
it { expect(Procedure.last.administrateur).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-17 15:34:51 +02:00
|
|
|
describe "POST #hide" do
|
2017-07-20 14:44:54 +02:00
|
|
|
subject { post :hide, params: { id: procedure.id } }
|
|
|
|
|
|
|
|
context "when procedure is not owned by administrateur" do
|
2018-05-17 15:34:51 +02:00
|
|
|
let(:procedure) { create :procedure, administrateur: create(:administrateur) }
|
2017-07-20 14:44:54 +02:00
|
|
|
|
|
|
|
it { expect{ subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when procedure is owned by administrateur" do
|
2018-05-17 15:34:51 +02:00
|
|
|
let(:procedure) { create :procedure, :published, administrateur: admin }
|
2017-07-20 14:44:54 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
procedure.reload
|
|
|
|
end
|
|
|
|
|
2017-12-15 17:15:24 +01:00
|
|
|
it { expect(procedure.hidden_at).not_to be_nil }
|
2018-05-29 11:44:44 +02:00
|
|
|
it { expect(procedure.procedure_path).to be_nil }
|
2017-07-20 14:44:54 +02:00
|
|
|
end
|
2018-01-18 17:45:33 +01:00
|
|
|
|
|
|
|
context "when procedure has no path" do
|
2018-05-17 15:34:51 +02:00
|
|
|
let(:procedure) { create :procedure, administrateur: admin }
|
2018-01-18 17:45:33 +01:00
|
|
|
|
|
|
|
it { expect{ subject }.not_to raise_error }
|
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(procedure.reload.hidden_at).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
2017-07-20 14:44:54 +02:00
|
|
|
end
|
2018-05-31 11:15:44 +02:00
|
|
|
|
|
|
|
describe "DELETE #delete_deliberation" do
|
|
|
|
let(:procedure) { create(:procedure, :with_deliberation) }
|
|
|
|
|
|
|
|
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
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|