Merge branch 'dev'
This commit is contained in:
commit
34db18b888
31 changed files with 228 additions and 179 deletions
|
@ -113,15 +113,7 @@ module NewGestionnaire
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_commentaire
|
def create_commentaire
|
||||||
commentaire_hash = commentaire_params.merge(email: current_gestionnaire.email, dossier: dossier)
|
@commentaire = CommentaireService.create(current_gestionnaire, dossier, commentaire_params)
|
||||||
|
|
||||||
# avoid simple_format replacing '' by '<p></p>'
|
|
||||||
# and thus skipping the not empty constraint on commentaire's body
|
|
||||||
if commentaire_hash[:body].present?
|
|
||||||
commentaire_hash[:body] = simple_format(commentaire_hash[:body])
|
|
||||||
end
|
|
||||||
|
|
||||||
@commentaire = Commentaire.new(commentaire_hash)
|
|
||||||
|
|
||||||
if @commentaire.save
|
if @commentaire.save
|
||||||
current_gestionnaire.follow(dossier)
|
current_gestionnaire.follow(dossier)
|
||||||
|
|
17
app/services/commentaire_service.rb
Normal file
17
app/services/commentaire_service.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
class CommentaireService
|
||||||
|
class << self
|
||||||
|
def create(sender, dossier, params)
|
||||||
|
attributes = params.merge(email: sender.email, dossier: dossier)
|
||||||
|
|
||||||
|
# If the user submits a empty message, simple_format will replace '' by '<p></p>',
|
||||||
|
# and thus bypass the not-empty constraint on commentaire's body.
|
||||||
|
#
|
||||||
|
# To avoid this, format the message only if a body is present in the first place.
|
||||||
|
if attributes[:body].present?
|
||||||
|
attributes[:body] = ActionController::Base.helpers.simple_format(attributes[:body])
|
||||||
|
end
|
||||||
|
|
||||||
|
Commentaire.new(attributes)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -269,7 +269,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
||||||
describe "#create_commentaire" do
|
describe "#create_commentaire" do
|
||||||
let(:saved_commentaire) { dossier.commentaires.first }
|
let(:saved_commentaire) { dossier.commentaires.first }
|
||||||
let(:body) { "avant\napres" }
|
let(:body) { "avant\napres" }
|
||||||
let(:file) { nil }
|
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||||
let(:scan_result) { true }
|
let(:scan_result) { true }
|
||||||
|
|
||||||
subject {
|
subject {
|
||||||
|
@ -287,35 +287,23 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
||||||
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
it "creates a commentaire" do
|
||||||
subject
|
expect { subject }.to change(Commentaire, :count).by(1)
|
||||||
|
|
||||||
expect(saved_commentaire.body).to eq("<p>avant\n<br />apres</p>")
|
|
||||||
expect(saved_commentaire.email).to eq(gestionnaire.email)
|
|
||||||
expect(saved_commentaire.dossier).to eq(dossier)
|
|
||||||
expect(response).to redirect_to(messagerie_gestionnaire_dossier_path(dossier.procedure, dossier))
|
|
||||||
expect(gestionnaire.followed_dossiers).to include(dossier)
|
expect(gestionnaire.followed_dossiers).to include(dossier)
|
||||||
expect(saved_commentaire.file.present?).to eq(false)
|
|
||||||
|
expect(response).to redirect_to(messagerie_gestionnaire_dossier_path(dossier.procedure, dossier))
|
||||||
|
expect(flash.notice).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect { subject }.to change(Commentaire, :count).by(1) }
|
context "when the commentaire creation fails" do
|
||||||
|
let(:scan_result) { false }
|
||||||
|
|
||||||
context "without a body" do
|
it "renders the messagerie page with the invalid commentaire" do
|
||||||
let(:body) { nil }
|
expect { subject }.not_to change(Commentaire, :count)
|
||||||
|
|
||||||
it { expect { subject }.not_to change(Commentaire, :count) }
|
expect(response).to render_template :messagerie
|
||||||
end
|
expect(flash.alert).to be_present
|
||||||
|
expect(assigns(:commentaire).body).to eq("<p>avant\n<br />apres</p>")
|
||||||
context "with a file" do
|
|
||||||
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
|
||||||
|
|
||||||
it { subject; expect(saved_commentaire.file.present?).to eq(true) }
|
|
||||||
it { expect { subject }.to change(Commentaire, :count).by(1) }
|
|
||||||
|
|
||||||
context "and a virus" do
|
|
||||||
let(:scan_result) { false }
|
|
||||||
|
|
||||||
it { expect { subject }.not_to change(Commentaire, :count) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,6 @@ FactoryBot.define do
|
||||||
sequence(:administrateur_email) { |n| "admin#{n}@admin.com" }
|
sequence(:administrateur_email) { |n| "admin#{n}@admin.com" }
|
||||||
factory :administrateur do
|
factory :administrateur do
|
||||||
email { generate(:administrateur_email) }
|
email { generate(:administrateur_email) }
|
||||||
password 'password'
|
password { 'password' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,6 @@ FactoryBot.define do
|
||||||
sequence(:administration_email) { |n| "plop#{n}@plop.com" }
|
sequence(:administration_email) { |n| "plop#{n}@plop.com" }
|
||||||
factory :administration do
|
factory :administration do
|
||||||
email { generate(:administration_email) }
|
email { generate(:administration_email) }
|
||||||
password 'password'
|
password { 'password' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :attestation_template do
|
factory :attestation_template do
|
||||||
title 'title'
|
title { 'title' }
|
||||||
body 'body'
|
body { 'body' }
|
||||||
footer 'footer'
|
footer { 'footer' }
|
||||||
activated true
|
activated { true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :avis do
|
factory :avis do
|
||||||
introduction 'Bonjour, merci de me donner votre avis sur ce dossier'
|
introduction { 'Bonjour, merci de me donner votre avis sur ce dossier' }
|
||||||
|
|
||||||
before(:create) do |avis, _evaluator|
|
before(:create) do |avis, _evaluator|
|
||||||
if !avis.gestionnaire
|
if !avis.gestionnaire
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :cadastre do
|
factory :cadastre do
|
||||||
numero '001'
|
numero { '001' }
|
||||||
feuille 1
|
feuille { 1 }
|
||||||
section 'OM'
|
section { 'OM' }
|
||||||
geometry '{"type": "MultiPolygon", "coordinates": [[[[2.37112834276229, 48.8773116214902], [2.37163254350824, 48.8775780792784], [2.37112834276229, 48.8773116214902]]]]}'
|
geometry { '{"type": "MultiPolygon", "coordinates": [[[[2.37112834276229, 48.8773116214902], [2.37163254350824, 48.8775780792784], [2.37112834276229, 48.8773116214902]]]]}' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :commentaire do
|
factory :commentaire do
|
||||||
body 'plop'
|
body { 'plop' }
|
||||||
|
|
||||||
before(:create) do |commentaire, _evaluator|
|
before(:create) do |commentaire, _evaluator|
|
||||||
if !commentaire.dossier
|
if !commentaire.dossier
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :deleted_dossier do
|
factory :deleted_dossier do
|
||||||
dossier_id 1111
|
dossier_id { 1111 }
|
||||||
state Dossier.states.fetch(:en_construction)
|
state { Dossier.states.fetch(:en_construction) }
|
||||||
deleted_at DateTime.now
|
deleted_at { DateTime.now }
|
||||||
|
|
||||||
association :procedure, :published
|
association :procedure, :published
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :dossier do
|
factory :dossier do
|
||||||
autorisation_donnees true
|
autorisation_donnees { true }
|
||||||
state Dossier.states.fetch(:brouillon)
|
state { Dossier.states.fetch(:brouillon) }
|
||||||
association :user, factory: [:user]
|
association :user, factory: [:user]
|
||||||
|
|
||||||
before(:create) do |dossier, _evaluator|
|
before(:create) do |dossier, _evaluator|
|
||||||
|
@ -46,11 +46,11 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :archived do
|
trait :archived do
|
||||||
archived true
|
archived { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :not_archived do
|
trait :not_archived do
|
||||||
archived false
|
archived { false }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :with_dossier_link do
|
trait :with_dossier_link do
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :drop_down_list do
|
factory :drop_down_list do
|
||||||
value "val1\r\nval2\r\n--separateur--\r\nval3"
|
value { "val1\r\nval2\r\n--separateur--\r\nval3" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,36 +1,36 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :etablissement do
|
factory :etablissement do
|
||||||
siret '44011762001530'
|
siret { '44011762001530' }
|
||||||
siege_social true
|
siege_social { true }
|
||||||
naf '4950Z'
|
naf { '4950Z' }
|
||||||
libelle_naf 'Transports par conduites'
|
libelle_naf { 'Transports par conduites' }
|
||||||
adresse "GRTGAZ\r IMMEUBLE BORA\r 6 RUE RAOUL NORDLING\r 92270 BOIS COLOMBES\r"
|
adresse { "GRTGAZ\r IMMEUBLE BORA\r 6 RUE RAOUL NORDLING\r 92270 BOIS COLOMBES\r" }
|
||||||
numero_voie '6'
|
numero_voie { '6' }
|
||||||
type_voie 'RUE'
|
type_voie { 'RUE' }
|
||||||
nom_voie 'RAOUL NORDLING'
|
nom_voie { 'RAOUL NORDLING' }
|
||||||
complement_adresse 'IMMEUBLE BORA'
|
complement_adresse { 'IMMEUBLE BORA' }
|
||||||
code_postal '92270'
|
code_postal { '92270' }
|
||||||
localite 'BOIS COLOMBES'
|
localite { 'BOIS COLOMBES' }
|
||||||
code_insee_localite '92009'
|
code_insee_localite { '92009' }
|
||||||
|
|
||||||
entreprise_siren '440117620'
|
entreprise_siren { '440117620' }
|
||||||
entreprise_capital_social 537_100_000
|
entreprise_capital_social { 537_100_000 }
|
||||||
entreprise_numero_tva_intracommunautaire 'FR27440117620'
|
entreprise_numero_tva_intracommunautaire { 'FR27440117620' }
|
||||||
entreprise_forme_juridique 'SA à conseil d\'administration (s.a.i.)'
|
entreprise_forme_juridique { 'SA à conseil d\'administration (s.a.i.)' }
|
||||||
entreprise_forme_juridique_code '5599'
|
entreprise_forme_juridique_code { '5599' }
|
||||||
entreprise_nom_commercial 'GRTGAZ'
|
entreprise_nom_commercial { 'GRTGAZ' }
|
||||||
entreprise_raison_sociale 'GRTGAZ'
|
entreprise_raison_sociale { 'GRTGAZ' }
|
||||||
entreprise_siret_siege_social '44011762001530'
|
entreprise_siret_siege_social { '44011762001530' }
|
||||||
entreprise_code_effectif_entreprise '51'
|
entreprise_code_effectif_entreprise { '51' }
|
||||||
entreprise_date_creation "1990-04-24"
|
entreprise_date_creation { "1990-04-24" }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :is_association do
|
trait :is_association do
|
||||||
association_rna "W072000535"
|
association_rna { "W072000535" }
|
||||||
association_titre "ASSOCIATION POUR LA PROMOTION DE SPECTACLES AU CHATEAU DE ROCHEMAURE"
|
association_titre { "ASSOCIATION POUR LA PROMOTION DE SPECTACLES AU CHATEAU DE ROCHEMAURE" }
|
||||||
association_objet "mise en oeuvre et réalisation de spectacles au chateau de rochemaure"
|
association_objet { "mise en oeuvre et réalisation de spectacles au chateau de rochemaure" }
|
||||||
association_date_creation "1990-04-24"
|
association_date_creation { "1990-04-24" }
|
||||||
association_date_declaration "2014-11-28"
|
association_date_declaration { "2014-11-28" }
|
||||||
association_date_publication "1990-05-16"
|
association_date_publication { "1990-05-16" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :exercice do
|
factory :exercice do
|
||||||
ca '12345678'
|
ca { '12345678' }
|
||||||
date_fin_exercice "2014-12-30 23:00:00"
|
date_fin_exercice { "2014-12-30 23:00:00" }
|
||||||
date_fin_exercice_timestamp 1419980400
|
date_fin_exercice_timestamp { 1419980400 }
|
||||||
association :etablissement, factory: [:etablissement]
|
association :etablissement, factory: [:etablissement]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :feedback do
|
factory :feedback do
|
||||||
rating Feedback.ratings.fetch(:happy)
|
rating { Feedback.ratings.fetch(:happy) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :france_connect_information do
|
factory :france_connect_information do
|
||||||
given_name 'plop'
|
given_name { 'plop' }
|
||||||
family_name 'plip'
|
family_name { 'plip' }
|
||||||
birthdate '1976-02-24'
|
birthdate { '1976-02-24' }
|
||||||
france_connect_particulier_id '1234567'
|
france_connect_particulier_id { '1234567' }
|
||||||
email_france_connect 'plip@octo.com'
|
email_france_connect { 'plip@octo.com' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,6 @@ FactoryBot.define do
|
||||||
sequence(:gestionnaire_email) { |n| "gest#{n}@gest.com" }
|
sequence(:gestionnaire_email) { |n| "gest#{n}@gest.com" }
|
||||||
factory :gestionnaire do
|
factory :gestionnaire do
|
||||||
email { generate(:gestionnaire_email) }
|
email { generate(:gestionnaire_email) }
|
||||||
password 'password'
|
password { 'password' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :individual do
|
factory :individual do
|
||||||
gender 'M.'
|
gender { 'M.' }
|
||||||
nom 'Julien'
|
nom { 'Julien' }
|
||||||
prenom 'Xavier'
|
prenom { 'Xavier' }
|
||||||
birthdate Date.new(1991, 11, 01)
|
birthdate { Date.new(1991, 11, 01) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :invite do
|
factory :invite do
|
||||||
email 'plop@octo.com'
|
email { 'plop@octo.com' }
|
||||||
|
|
||||||
after(:build) do |invite, _evaluator|
|
after(:build) do |invite, _evaluator|
|
||||||
if invite.dossier.nil?
|
if invite.dossier.nil?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :invite_user do
|
factory :invite_user do
|
||||||
email 'plop@octo.com'
|
email { 'plop@octo.com' }
|
||||||
|
|
||||||
after(:build) do |invite, _evaluator|
|
after(:build) do |invite, _evaluator|
|
||||||
if invite.dossier.nil?
|
if invite.dossier.nil?
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :closed_mail, class: Mails::ClosedMail do
|
factory :closed_mail, class: Mails::ClosedMail do
|
||||||
subject "Subject, voila voila"
|
subject { "Subject, voila voila" }
|
||||||
body "Blabla ceci est mon body"
|
body { "Blabla ceci est mon body" }
|
||||||
|
|
||||||
factory :received_mail, class: Mails::ReceivedMail
|
factory :received_mail, class: Mails::ReceivedMail
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@ FactoryBot.define do
|
||||||
factory :without_continuation_mail, class: Mails::WithoutContinuationMail
|
factory :without_continuation_mail, class: Mails::WithoutContinuationMail
|
||||||
|
|
||||||
factory :initiated_mail, class: Mails::InitiatedMail do
|
factory :initiated_mail, class: Mails::InitiatedMail do
|
||||||
subject "[demarches-simplifiees.fr] Accusé de réception pour votre dossier nº --numéro du dossier--"
|
subject { "[demarches-simplifiees.fr] Accusé de réception pour votre dossier nº --numéro du dossier--" }
|
||||||
body "Votre administration vous confirme la bonne réception de votre dossier nº --numéro du dossier--"
|
body { "Votre administration vous confirme la bonne réception de votre dossier nº --numéro du dossier--" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :module_api_carto do
|
factory :module_api_carto do
|
||||||
use_api_carto false
|
use_api_carto { false }
|
||||||
quartiers_prioritaires false
|
quartiers_prioritaires { false }
|
||||||
cadastre false
|
cadastre { false }
|
||||||
|
|
||||||
trait :with_api_carto do
|
trait :with_api_carto do
|
||||||
use_api_carto true
|
use_api_carto { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :with_quartiers_prioritaires do
|
trait :with_quartiers_prioritaires do
|
||||||
use_api_carto true
|
use_api_carto { true }
|
||||||
quartiers_prioritaires true
|
quartiers_prioritaires { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :with_cadastre do
|
trait :with_cadastre do
|
||||||
use_api_carto true
|
use_api_carto { true }
|
||||||
cadastre true
|
cadastre { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :with_qp_and_cadastre do
|
trait :with_qp_and_cadastre do
|
||||||
use_api_carto true
|
use_api_carto { true }
|
||||||
quartiers_prioritaires true
|
quartiers_prioritaires { true }
|
||||||
cadastre true
|
cadastre { true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :piece_justificative do
|
factory :piece_justificative do
|
||||||
trait :rib do
|
trait :rib do
|
||||||
content Rack::Test::UploadedFile.new("./spec/support/files/RIB.pdf", 'application/pdf')
|
content { Rack::Test::UploadedFile.new("./spec/support/files/RIB.pdf", 'application/pdf') }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :contrat do
|
trait :contrat do
|
||||||
content Rack::Test::UploadedFile.new("./spec/support/files/Contrat.pdf", 'application/pdf')
|
content { Rack::Test::UploadedFile.new("./spec/support/files/Contrat.pdf", 'application/pdf') }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
sequence(:published_path) { |n| "fake_path#{n}" }
|
sequence(:published_path) { |n| "fake_path#{n}" }
|
||||||
factory :procedure do
|
factory :procedure do
|
||||||
lien_demarche 'http://localhost'
|
lien_demarche { 'http://localhost' }
|
||||||
sequence(:libelle) { |n| "Procedure #{n}" }
|
sequence(:libelle) { |n| "Procedure #{n}" }
|
||||||
description "Demande de subvention à l'intention des associations"
|
description { "Demande de subvention à l'intention des associations" }
|
||||||
organisation "Orga DINSIC"
|
organisation { "Orga DINSIC" }
|
||||||
direction "direction DINSIC"
|
direction { "direction DINSIC" }
|
||||||
cadre_juridique "un cadre juridique important"
|
cadre_juridique { "un cadre juridique important" }
|
||||||
published_at nil
|
published_at { nil }
|
||||||
administrateur { create(:administrateur) }
|
administrateur { create(:administrateur) }
|
||||||
duree_conservation_dossiers_dans_ds 3
|
duree_conservation_dossiers_dans_ds { 3 }
|
||||||
duree_conservation_dossiers_hors_ds 6
|
duree_conservation_dossiers_hors_ds { 6 }
|
||||||
|
|
||||||
factory :procedure_with_dossiers do
|
factory :procedure_with_dossiers do
|
||||||
transient do
|
transient do
|
||||||
dossiers_count 1
|
dossiers_count { 1 }
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
|
@ -58,7 +58,7 @@ FactoryBot.define do
|
||||||
|
|
||||||
trait :with_type_de_champ do
|
trait :with_type_de_champ do
|
||||||
transient do
|
transient do
|
||||||
types_de_champ_count 1
|
types_de_champ_count { 1 }
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:build) do |procedure, evaluator|
|
after(:build) do |procedure, evaluator|
|
||||||
|
@ -72,7 +72,7 @@ FactoryBot.define do
|
||||||
|
|
||||||
trait :with_type_de_champ_private do
|
trait :with_type_de_champ_private do
|
||||||
transient do
|
transient do
|
||||||
types_de_champ_private_count 1
|
types_de_champ_private_count { 1 }
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:build) do |procedure, evaluator|
|
after(:build) do |procedure, evaluator|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :procedure_path do
|
factory :procedure_path do
|
||||||
path 'fake_path'
|
path { 'fake_path' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :quartier_prioritaire do
|
factory :quartier_prioritaire do
|
||||||
code 'QPcode'
|
code { 'QPcode' }
|
||||||
commune 'Paris'
|
commune { 'Paris' }
|
||||||
nom 'Test des QP'
|
nom { 'Test des QP' }
|
||||||
geometry '{"type": "MultiPolygon", "coordinates": [[[[2.37112834276229, 48.8773116214902], [2.37163254350824, 48.8775780792784], [2.37112834276229, 48.8773116214902]]]]}'
|
geometry { '{"type": "MultiPolygon", "coordinates": [[[[2.37112834276229, 48.8773116214902], [2.37163254350824, 48.8775780792784], [2.37112834276229, 48.8773116214902]]]]}' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :service do
|
factory :service do
|
||||||
nom 'service'
|
nom { 'service' }
|
||||||
organisme 'organisme'
|
organisme { 'organisme' }
|
||||||
type_organisme Service.type_organismes.fetch(:commune)
|
type_organisme { Service.type_organismes.fetch(:commune) }
|
||||||
administrateur { create(:administrateur) }
|
administrateur { create(:administrateur) }
|
||||||
email 'email@toto.com'
|
email { 'email@toto.com' }
|
||||||
telephone '1234'
|
telephone { '1234' }
|
||||||
horaires 'de 9 h à 18 h'
|
horaires { 'de 9 h à 18 h' }
|
||||||
adresse 'adresse'
|
adresse { 'adresse' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,90 +1,94 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :type_de_champ, class: 'TypesDeChamp::TextTypeDeChamp' do
|
factory :type_de_champ, class: 'TypesDeChamp::TextTypeDeChamp' do
|
||||||
private false
|
private { false }
|
||||||
|
|
||||||
|
# Previous line is kept blank so that rubocop does not complain
|
||||||
sequence(:libelle) { |n| "Libelle du champ #{n}" }
|
sequence(:libelle) { |n| "Libelle du champ #{n}" }
|
||||||
sequence(:description) { |n| "description du champ #{n}" }
|
sequence(:description) { |n| "description du champ #{n}" }
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:text)
|
type_champ { TypeDeChamp.type_champs.fetch(:text) }
|
||||||
order_place 1
|
order_place { 1 }
|
||||||
mandatory false
|
mandatory { false }
|
||||||
|
|
||||||
factory :type_de_champ_text, class: 'TypesDeChamp::TextTypeDeChamp' do
|
factory :type_de_champ_text, class: 'TypesDeChamp::TextTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:text)
|
type_champ { TypeDeChamp.type_champs.fetch(:text) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_textarea, class: 'TypesDeChamp::TextareaTypeDeChamp' do
|
factory :type_de_champ_textarea, class: 'TypesDeChamp::TextareaTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:textarea)
|
type_champ { TypeDeChamp.type_champs.fetch(:textarea) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_number, class: 'TypesDeChamp::NumberTypeDeChamp' do
|
factory :type_de_champ_number, class: 'TypesDeChamp::NumberTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:number)
|
type_champ { TypeDeChamp.type_champs.fetch(:number) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_checkbox, class: 'TypesDeChamp::CheckboxTypeDeChamp' do
|
factory :type_de_champ_checkbox, class: 'TypesDeChamp::CheckboxTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:checkbox)
|
type_champ { TypeDeChamp.type_champs.fetch(:checkbox) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_civilite, class: 'TypesDeChamp::CiviliteTypeDeChamp' do
|
factory :type_de_champ_civilite, class: 'TypesDeChamp::CiviliteTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:civilite)
|
type_champ { TypeDeChamp.type_champs.fetch(:civilite) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_email, class: 'TypesDeChamp::EmailTypeDeChamp' do
|
factory :type_de_champ_email, class: 'TypesDeChamp::EmailTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:email)
|
type_champ { TypeDeChamp.type_champs.fetch(:email) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_phone, class: 'TypesDeChamp::PhoneTypeDeChamp' do
|
factory :type_de_champ_phone, class: 'TypesDeChamp::PhoneTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:phone)
|
type_champ { TypeDeChamp.type_champs.fetch(:phone) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_address, class: 'TypesDeChamp::AddressTypeDeChamp' do
|
factory :type_de_champ_address, class: 'TypesDeChamp::AddressTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:address)
|
type_champ { TypeDeChamp.type_champs.fetch(:address) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_yes_no, class: 'TypesDeChamp::YesNoTypeDeChamp' do
|
factory :type_de_champ_yes_no, class: 'TypesDeChamp::YesNoTypeDeChamp' do
|
||||||
libelle 'Yes/no'
|
libelle { 'Yes/no' }
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:yes_no)
|
type_champ { TypeDeChamp.type_champs.fetch(:yes_no) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_date, class: 'TypesDeChamp::DateTypeDeChamp' do
|
factory :type_de_champ_date, class: 'TypesDeChamp::DateTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:date)
|
type_champ { TypeDeChamp.type_champs.fetch(:date) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_datetime, class: 'TypesDeChamp::DatetimeTypeDeChamp' do
|
factory :type_de_champ_datetime, class: 'TypesDeChamp::DatetimeTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:datetime)
|
type_champ { TypeDeChamp.type_champs.fetch(:datetime) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_drop_down_list, class: 'TypesDeChamp::DropDownListTypeDeChamp' do
|
factory :type_de_champ_drop_down_list, class: 'TypesDeChamp::DropDownListTypeDeChamp' do
|
||||||
libelle 'Menu déroulant'
|
libelle { 'Menu déroulant' }
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:drop_down_list)
|
type_champ { TypeDeChamp.type_champs.fetch(:drop_down_list) }
|
||||||
drop_down_list { create(:drop_down_list) }
|
drop_down_list { create(:drop_down_list) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_multiple_drop_down_list, class: 'TypesDeChamp::MultipleDropDownListTypeDeChamp' do
|
factory :type_de_champ_multiple_drop_down_list, class: 'TypesDeChamp::MultipleDropDownListTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
|
type_champ { TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) }
|
||||||
drop_down_list { create(:drop_down_list) }
|
drop_down_list { create(:drop_down_list) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_linked_drop_down_list, class: 'TypesDeChamp::LinkedDropDownListTypeDeChamp' do
|
factory :type_de_champ_linked_drop_down_list, class: 'TypesDeChamp::LinkedDropDownListTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
|
type_champ { TypeDeChamp.type_champs.fetch(:linked_drop_down_list) }
|
||||||
drop_down_list { create(:drop_down_list) }
|
drop_down_list { create(:drop_down_list) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_pays, class: 'TypesDeChamp::PaysTypeDeChamp' do
|
factory :type_de_champ_pays, class: 'TypesDeChamp::PaysTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:pays)
|
type_champ { TypeDeChamp.type_champs.fetch(:pays) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_regions, class: 'TypesDeChamp::RegionTypeDeChamp' do
|
factory :type_de_champ_regions, class: 'TypesDeChamp::RegionTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:regions)
|
type_champ { TypeDeChamp.type_champs.fetch(:regions) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_departements, class: 'TypesDeChamp::DepartementTypeDeChamp' do
|
factory :type_de_champ_departements, class: 'TypesDeChamp::DepartementTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:departements)
|
type_champ { TypeDeChamp.type_champs.fetch(:departements) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_engagement, class: 'TypesDeChamp::EngagementTypeDeChamp' do
|
factory :type_de_champ_engagement, class: 'TypesDeChamp::EngagementTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:engagement)
|
type_champ { TypeDeChamp.type_champs.fetch(:engagement) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_header_section, class: 'TypesDeChamp::HeaderSectionTypeDeChamp' do
|
factory :type_de_champ_header_section, class: 'TypesDeChamp::HeaderSectionTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:header_section)
|
type_champ { TypeDeChamp.type_champs.fetch(:header_section) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_explication, class: 'TypesDeChamp::ExplicationTypeDeChamp' do
|
factory :type_de_champ_explication, class: 'TypesDeChamp::ExplicationTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:explication)
|
type_champ { TypeDeChamp.type_champs.fetch(:explication) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_dossier_link, class: 'TypesDeChamp::DossierLinkTypeDeChamp' do
|
factory :type_de_champ_dossier_link, class: 'TypesDeChamp::DossierLinkTypeDeChamp' do
|
||||||
libelle 'Référence autre dossier'
|
libelle { 'Référence autre dossier' }
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:dossier_link)
|
type_champ { TypeDeChamp.type_champs.fetch(:dossier_link) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_piece_justificative, class: 'TypesDeChamp::PieceJustificativeTypeDeChamp' do
|
factory :type_de_champ_piece_justificative, class: 'TypesDeChamp::PieceJustificativeTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:piece_justificative)
|
type_champ { TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
||||||
end
|
end
|
||||||
factory :type_de_champ_siret, class: 'TypesDeChamp::SiretTypeDeChamp' do
|
factory :type_de_champ_siret, class: 'TypesDeChamp::SiretTypeDeChamp' do
|
||||||
type_champ TypeDeChamp.type_champs.fetch(:siret)
|
type_champ { TypeDeChamp.type_champs.fetch(:siret) }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :private do
|
trait :private do
|
||||||
private true
|
private { true }
|
||||||
|
|
||||||
|
# Previous line is kept blank so that rubocop does not complain
|
||||||
sequence(:libelle) { |n| "Libelle champ privé #{n}" }
|
sequence(:libelle) { |n| "Libelle champ privé #{n}" }
|
||||||
sequence(:description) { |n| "description du champ privé #{n}" }
|
sequence(:description) { |n| "description du champ privé #{n}" }
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :type_de_piece_justificative do
|
factory :type_de_piece_justificative do
|
||||||
libelle 'RIB'
|
libelle { 'RIB' }
|
||||||
description 'Releve identité bancaire'
|
description { 'Releve identité bancaire' }
|
||||||
|
|
||||||
trait :rib do
|
trait :rib do
|
||||||
libelle 'RIB'
|
libelle { 'RIB' }
|
||||||
description 'Releve identité bancaire'
|
description { 'Releve identité bancaire' }
|
||||||
api_entreprise false
|
api_entreprise { false }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :msa do
|
trait :msa do
|
||||||
libelle 'Attestation MSA'
|
libelle { 'Attestation MSA' }
|
||||||
description 'recuperation automatique'
|
description { 'recuperation automatique' }
|
||||||
api_entreprise true
|
api_entreprise { true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ FactoryBot.define do
|
||||||
sequence(:user_email) { |n| "user#{n}@user.com" }
|
sequence(:user_email) { |n| "user#{n}@user.com" }
|
||||||
factory :user do
|
factory :user do
|
||||||
email { generate(:user_email) }
|
email { generate(:user_email) }
|
||||||
password 'password'
|
password { 'password' }
|
||||||
confirmed_at DateTime.now
|
confirmed_at { DateTime.now }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
48
spec/services/commentaire_service_spec.rb
Normal file
48
spec/services/commentaire_service_spec.rb
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe CommentaireService do
|
||||||
|
describe '.create' do
|
||||||
|
let(:dossier) { create :dossier }
|
||||||
|
let(:sender) { dossier.user }
|
||||||
|
let(:body) { 'Contenu du message.' }
|
||||||
|
let(:file) { nil }
|
||||||
|
let(:scan_result) { true }
|
||||||
|
|
||||||
|
subject(:commentaire) { CommentaireService.create(sender, dossier, { body: body, file: file }) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a new valid commentaire' do
|
||||||
|
expect(commentaire.email).to eq sender.email
|
||||||
|
expect(commentaire.dossier).to eq dossier
|
||||||
|
expect(commentaire.body).to eq '<p>Contenu du message.</p>'
|
||||||
|
expect(commentaire.file).to be_blank
|
||||||
|
expect(commentaire).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the body is empty' do
|
||||||
|
let(:body) { nil }
|
||||||
|
|
||||||
|
it 'creates an invalid comment' do
|
||||||
|
expect(commentaire.body).to be nil
|
||||||
|
expect(commentaire.valid?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when it has a file' do
|
||||||
|
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||||
|
|
||||||
|
it 'saves the attached file' do
|
||||||
|
expect(commentaire.file).to be_present
|
||||||
|
expect(commentaire).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'and a virus' do
|
||||||
|
let(:scan_result) { false }
|
||||||
|
it { expect(commentaire).not_to be_valid }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue