diff --git a/Gemfile b/Gemfile
index 456da8de1..4127ede86 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,11 +1,11 @@
source 'https://rubygems.org'
-gem 'rails', '~> 5.2.0'
+gem 'rails'
# Use SCSS for stylesheets
gem 'sass-rails'
# Use Uglifier as compressor for JavaScript assets
-gem 'uglifier', '>= 1.3.0'
+gem 'uglifier'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
@@ -42,6 +42,7 @@ gem 'unicode_utils'
# Gestion des comptes utilisateurs
gem 'devise'
+gem 'devise-async'
gem 'openid_connect'
gem 'omniauth-github'
@@ -133,7 +134,7 @@ group :test do
gem 'timecop'
gem 'guard'
gem 'guard-rspec', require: false
- gem 'guard-livereload', '~> 2.4', require: false
+ gem 'guard-livereload', require: false
gem 'vcr'
gem 'rails-controller-testing'
end
diff --git a/Gemfile.lock b/Gemfile.lock
index bac604e89..110b9c397 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -175,6 +175,9 @@ GEM
railties (>= 4.1.0, < 6.0)
responders
warden (~> 1.2.3)
+ devise-async (1.0.0)
+ activejob (>= 5.0)
+ devise (>= 4.0)
diff-lcs (1.3)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
@@ -195,7 +198,7 @@ GEM
erubis (2.7.0)
ethon (0.11.0)
ffi (>= 1.3.0)
- eventmachine (1.2.5)
+ eventmachine (1.2.7)
excon (0.60.0)
execjs (2.7.0)
factory_bot (4.8.2)
@@ -458,7 +461,7 @@ GEM
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
- lumberjack (1.0.12)
+ lumberjack (1.0.13)
mail (2.7.0)
mini_mime (>= 0.1.1)
mailjet (1.5.4)
@@ -803,6 +806,7 @@ DEPENDENCIES
delayed_job_active_record
delayed_job_web!
devise
+ devise-async
dotenv-rails
draper
factory_bot
@@ -811,7 +815,7 @@ DEPENDENCIES
fog-openstack
font-awesome-rails
guard
- guard-livereload (~> 2.4)
+ guard-livereload
guard-rspec
haml-lint
haml-rails
@@ -835,7 +839,7 @@ DEPENDENCIES
pry-byebug
rack-handlers
rack-mini-profiler
- rails (~> 5.2.0)
+ rails
rails-controller-testing
rbnacl-libsodium
rest-client
@@ -861,7 +865,7 @@ DEPENDENCIES
timecop
turbolinks
typhoeus
- uglifier (>= 1.3.0)
+ uglifier
unicode_utils
unicorn
vcr
diff --git a/app/controllers/admin/gestionnaires_controller.rb b/app/controllers/admin/gestionnaires_controller.rb
index 305400bee..831dd6f38 100644
--- a/app/controllers/admin/gestionnaires_controller.rb
+++ b/app/controllers/admin/gestionnaires_controller.rb
@@ -50,7 +50,7 @@ class Admin::GestionnairesController < AdminController
@gestionnaire.invite!
if User.exists?(email: @gestionnaire.email)
- GestionnaireMailer.user_to_gestionnaire(@gestionnaire.email).deliver_now!
+ GestionnaireMailer.user_to_gestionnaire(@gestionnaire.email).deliver_later
else
User.create(email: email, password: password)
end
diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index 8e5518d7f..25277784b 100644
--- a/app/controllers/invites_controller.rb
+++ b/app/controllers/invites_controller.rb
@@ -13,9 +13,9 @@ class InvitesController < ApplicationController
if invite.valid?
if invite.user.present?
- InviteMailer.invite_user(invite).deliver_now!
+ InviteMailer.invite_user(invite).deliver_later
else
- InviteMailer.invite_guest(invite).deliver_now!
+ InviteMailer.invite_guest(invite).deliver_later
end
flash.notice = "Invitation envoyée (#{invite.email})"
diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb
index f3b7928a0..a62359a18 100644
--- a/app/controllers/new_gestionnaire/dossiers_controller.rb
+++ b/app/controllers/new_gestionnaire/dossiers_controller.rb
@@ -91,25 +91,22 @@ module NewGestionnaire
case params[:process_action]
when "refuser"
dossier.refuse!
- notice = "Dossier considéré comme refusé."
- template = procedure.refused_mail_template
+ dossier.save
+ flash.notice = "Dossier considéré comme refusé."
+ NotificationMailer.send_refused_notification(dossier).deliver_later
when "classer_sans_suite"
dossier.sans_suite!
- notice = "Dossier considéré comme sans suite."
- template = procedure.without_continuation_mail_template
+ dossier.save
+ flash.notice = "Dossier considéré comme sans suite."
+ NotificationMailer.send_without_continuation_notification(dossier).deliver_later
when "accepter"
dossier.accepte!
dossier.attestation = dossier.build_attestation
- notice = "Dossier traité avec succès."
- template = procedure.closed_mail_template
+ dossier.save
+ flash.notice = "Dossier traité avec succès."
+ NotificationMailer.send_closed_notification(dossier).deliver_later
end
- dossier.save
-
- flash.notice = notice
-
- NotificationMailer.send_notification(dossier, template).deliver_now!
-
redirect_to gestionnaire_dossier_path(procedure, dossier)
end
diff --git a/app/controllers/new_gestionnaire/procedures_controller.rb b/app/controllers/new_gestionnaire/procedures_controller.rb
index 81f36b586..d9584e5e0 100644
--- a/app/controllers/new_gestionnaire/procedures_controller.rb
+++ b/app/controllers/new_gestionnaire/procedures_controller.rb
@@ -234,18 +234,22 @@ module NewGestionnaire
.includes(relation)
.where("champs.type_de_champ_id = ?", filter['column'].to_i)
.where("champs.value LIKE ?", "%#{filter['value']}%")
-
- when 'user', 'etablissement', 'entreprise'
+ when 'entreprise'
+ table = 'etablissement'
if filter['column'] == 'date_creation'
date = filter['value'].to_date rescue nil
dossiers
- .includes(filter['table'])
- .where("#{filter['table'].pluralize}.#{filter['column']} = ?", date)
+ .includes(table)
+ .where("#{table.pluralize}.entreprise_#{filter['column']} = ?", date)
else
dossiers
- .includes(filter['table'])
- .where("#{filter['table'].pluralize}.#{filter['column']} LIKE ?", "%#{filter['value']}%")
+ .includes(table)
+ .where("#{table.pluralize}.entreprise_#{filter['column']} LIKE ?", "%#{filter['value']}%")
end
+ when 'user', 'etablissement'
+ dossiers
+ .includes(filter['table'])
+ .where("#{filter['table'].pluralize}.#{filter['column']} LIKE ?", "%#{filter['value']}%")
end.pluck(:id)
end.reduce(:&)
end
diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb
index e05ce8a5f..56bf50f4a 100644
--- a/app/controllers/new_user/dossiers_controller.rb
+++ b/app/controllers/new_user/dossiers_controller.rb
@@ -71,7 +71,7 @@ module NewUser
render :modifier
elsif @dossier.brouillon?
@dossier.en_construction!
- NotificationMailer.send_notification(@dossier, @dossier.procedure.initiated_mail_template).deliver_now!
+ NotificationMailer.send_initiated_notification(@dossier).deliver_later
redirect_to merci_dossier_path(@dossier)
elsif owns_dossier?
redirect_to users_dossier_recapitulatif_path(@dossier)
diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb
index 5c10df942..9080ae890 100644
--- a/app/controllers/users/description_controller.rb
+++ b/app/controllers/users/description_controller.rb
@@ -55,7 +55,7 @@ class Users::DescriptionController < UsersController
if dossier.brouillon?
dossier.en_construction!
# TODO move to model
- NotificationMailer.send_notification(dossier, procedure.initiated_mail_template).deliver_now!
+ NotificationMailer.send_initiated_notification(dossier).deliver_later
end
flash.notice = 'Félicitations, votre demande a bien été enregistrée.'
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: dossier.id)
@@ -130,7 +130,7 @@ class Users::DescriptionController < UsersController
@dossier ||= current_user_dossier
if (@dossier.procedure.for_individual? && @dossier.individual.nil?) ||
- (!@dossier.procedure.for_individual? && @dossier.entreprise.nil?)
+ (!@dossier.procedure.for_individual? && @dossier.etablissement.nil?)
redirect_to url_for(users_dossier_path(@dossier.id))
end
end
diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb
index bec811f06..d9e1dd609 100644
--- a/app/controllers/users/dossiers_controller.rb
+++ b/app/controllers/users/dossiers_controller.rb
@@ -112,7 +112,7 @@ class Users::DossiersController < UsersController
update_current_user_siret!(siret)
- etablissement_attributes = ApiEntrepriseService.get_etablissement_params_for_siret(siret, @facade.dossier.procedure_id, @facade.dossier)
+ etablissement_attributes = ApiEntrepriseService.get_etablissement_params_for_siret(siret, @facade.dossier.procedure_id)
if etablissement_attributes.present?
etablissement_attributes = ActionController::Parameters.new(etablissement_attributes).permit!
diff --git a/app/decorators/entreprise_decorator.rb b/app/decorators/entreprise_decorator.rb
deleted file mode 100644
index 9cb958ca3..000000000
--- a/app/decorators/entreprise_decorator.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-class EntrepriseDecorator < Draper::Decorator
- delegate_all
-
- def raison_sociale_or_name
- raison_sociale.presence || "#{nom} #{prenom}"
- end
-
- def effectif
- {
- 'NN' => "Unités non employeuses (pas de salarié au cours de l'année de référence et pas d'effectif au 31/12).",
- '00' => "0 salarié (n'ayant pas d'effectif au 31/12 mais ayant employé des salariés au cours de l'année de référence)",
- '01' => '1 ou 2 salariés',
- '02' => '3 à 5 salariés',
- '03' => '6 à 9 salariés',
- '11' => '10 à 19 salariés',
- '12' => '20 à 49 salariés',
- '21' => '50 à 99 salariés',
- '22' => '100 à 199 salariés',
- '31' => '200 à 249 salariés',
- '32' => '250 à 499 salariés',
- '41' => '500 à 999 salariés',
- '42' => '1 000 à 1 999 salariés',
- '51' => '2 000 à 4 999 salariés',
- '52' => '5 000 à 9 999 salariés',
- '53' => '10 000 salariés et plus'
- }[code_effectif_entreprise]
- end
-
- def pretty_capital_social
- h.number_to_currency(capital_social, delimiter: ' ', unit: '€', format: '%n %u')
- end
-end
diff --git a/app/decorators/etablissement_decorator.rb b/app/decorators/etablissement_decorator.rb
deleted file mode 100644
index b6e03db6a..000000000
--- a/app/decorators/etablissement_decorator.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class EtablissementDecorator < Draper::Decorator
- delegate_all
-end
diff --git a/app/facades/dossier_facades.rb b/app/facades/dossier_facades.rb
index 7e1346833..9539cc724 100644
--- a/app/facades/dossier_facades.rb
+++ b/app/facades/dossier_facades.rb
@@ -13,10 +13,6 @@ class DossierFacades
@dossier.ordered_champs
end
- def entreprise
- @dossier.entreprise.decorate if @dossier.entreprise.present? && @dossier.entreprise.siren.present?
- end
-
def etablissement
@dossier.etablissement
end
diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb
index aefbb0490..b9145628a 100644
--- a/app/helpers/champ_helper.rb
+++ b/app/helpers/champ_helper.rb
@@ -2,10 +2,4 @@ module ChampHelper
def is_not_header_nor_explication?(champ)
!['header_section', 'explication'].include?(champ.type_champ)
end
-
- def html_formatted_description(description)
- html_formatted = simple_format(description)
- with_links = html_formatted.gsub(URI.regexp, '\0')
- sanitize(with_links, attributes: %w(href target))
- end
end
diff --git a/app/helpers/etablissement_helper.rb b/app/helpers/etablissement_helper.rb
index 3c4de3d6f..e12c485a3 100644
--- a/app/helpers/etablissement_helper.rb
+++ b/app/helpers/etablissement_helper.rb
@@ -2,4 +2,35 @@ module EtablissementHelper
def pretty_currency(capital_social)
number_to_currency(capital_social, locale: :fr)
end
+
+ def raison_sociale_or_name(etablissement)
+ if etablissement.association?
+ etablissement.association_titre
+ elsif etablissement.entreprise_raison_sociale.present?
+ etablissement.entreprise_raison_sociale
+ else
+ "#{etablissement.entreprise_nom} #{etablissement.entreprise_prenom}"
+ end
+ end
+
+ def effectif(etablissement)
+ {
+ 'NN' => "Unités non employeuses (pas de salarié au cours de l'année de référence et pas d'effectif au 31/12).",
+ '00' => "0 salarié (n'ayant pas d'effectif au 31/12 mais ayant employé des salariés au cours de l'année de référence)",
+ '01' => '1 ou 2 salariés',
+ '02' => '3 à 5 salariés',
+ '03' => '6 à 9 salariés',
+ '11' => '10 à 19 salariés',
+ '12' => '20 à 49 salariés',
+ '21' => '50 à 99 salariés',
+ '22' => '100 à 199 salariés',
+ '31' => '200 à 249 salariés',
+ '32' => '250 à 499 salariés',
+ '41' => '500 à 999 salariés',
+ '42' => '1 000 à 1 999 salariés',
+ '51' => '2 000 à 4 999 salariés',
+ '52' => '5 000 à 9 999 salariés',
+ '53' => '10 000 salariés et plus'
+ }[etablissement.entreprise_code_effectif_entreprise]
+ end
end
diff --git a/app/helpers/string_to_html_helper.rb b/app/helpers/string_to_html_helper.rb
new file mode 100644
index 000000000..793bc8b58
--- /dev/null
+++ b/app/helpers/string_to_html_helper.rb
@@ -0,0 +1,7 @@
+module StringToHtmlHelper
+ def string_to_html(str)
+ html_formatted = simple_format(str)
+ with_links = html_formatted.gsub(URI.regexp, '\0')
+ sanitize(with_links, attributes: %w(href target))
+ end
+end
diff --git a/app/jobs/etablissement_update_job.rb b/app/jobs/etablissement_update_job.rb
index fa85e144c..bcd81fa75 100644
--- a/app/jobs/etablissement_update_job.rb
+++ b/app/jobs/etablissement_update_job.rb
@@ -2,12 +2,9 @@ class EtablissementUpdateJob < ApplicationJob
queue_as :default
def perform(dossier, siret)
- etablissement_attributes = ApiEntrepriseService.get_etablissement_params_for_siret(siret, dossier.procedure_id, dossier)
+ etablissement_attributes = ApiEntrepriseService.get_etablissement_params_for_siret(siret, dossier.procedure_id)
if etablissement_attributes.present?
- if dossier.entreprise.present?
- dossier.entreprise.destroy
- end
if dossier.etablissement.present?
dossier.etablissement.destroy
end
diff --git a/app/jobs/find_dubious_procedures_job.rb b/app/jobs/find_dubious_procedures_job.rb
index ecfb3b56c..a1aa3dbba 100644
--- a/app/jobs/find_dubious_procedures_job.rb
+++ b/app/jobs/find_dubious_procedures_job.rb
@@ -24,6 +24,6 @@ class FindDubiousProceduresJob < ApplicationJob
.group_by(&:procedure_id)
.map { |_procedure_id, tdcs| [tdcs[0].procedure, tdcs] }
- AdministrationMailer.dubious_procedures(dubious_procedures_and_tdcs).deliver_now
+ AdministrationMailer.dubious_procedures(dubious_procedures_and_tdcs).deliver_later
end
end
diff --git a/app/lib/api_entreprise/entreprise_adapter.rb b/app/lib/api_entreprise/entreprise_adapter.rb
index 015c64ec2..b32305c47 100644
--- a/app/lib/api_entreprise/entreprise_adapter.rb
+++ b/app/lib/api_entreprise/entreprise_adapter.rb
@@ -9,7 +9,7 @@ class ApiEntreprise::EntrepriseAdapter < ApiEntreprise::Adapter
def process_params
params = data_source[:entreprise].slice(*attr_to_fetch)
params[:date_creation] = Time.at(params[:date_creation]).to_datetime
- params
+ params.transform_keys { |k| :"entreprise_#{k}" }
end
def attr_to_fetch
diff --git a/app/lib/api_entreprise/rna_adapter.rb b/app/lib/api_entreprise/rna_adapter.rb
index 333a382cc..9d0612788 100644
--- a/app/lib/api_entreprise/rna_adapter.rb
+++ b/app/lib/api_entreprise/rna_adapter.rb
@@ -9,7 +9,7 @@ class ApiEntreprise::RNAAdapter < ApiEntreprise::Adapter
if data_source[:association][:id].present?
params = data_source[:association].slice(*attr_to_fetch)
params[:rna] = data_source[:association][:id]
- params
+ params.transform_keys { |k| :"association_#{k}" }
else
{}
end
diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb
index 5119693a1..b493f8407 100644
--- a/app/mailers/notification_mailer.rb
+++ b/app/mailers/notification_mailer.rb
@@ -8,15 +8,6 @@ class NotificationMailer < ApplicationMailer
send_notification(dossier, dossier.procedure.received_mail_template)
end
- def send_notification(dossier, mail_template)
- vars_mailer(dossier)
-
- @subject = mail_template.subject_for_dossier dossier
- @body = mail_template.body_for_dossier dossier
-
- mail(subject: @subject) { |format| format.html { @body } }
- end
-
def send_draft_notification(dossier)
vars_mailer(dossier)
@@ -25,12 +16,41 @@ class NotificationMailer < ApplicationMailer
mail(subject: @subject)
end
+ def send_initiated_notification(dossier)
+ send_notification(dossier, dossier.procedure.initiated_mail_template)
+ end
+
+ def send_received_notification(dossier)
+ send_notification(dossier, dossier.procedure.received_mail_template)
+ end
+
+ def send_closed_notification(dossier)
+ send_notification(dossier, dossier.procedure.closed_mail_template)
+ end
+
+ def send_refused_notification(dossier)
+ send_notification(dossier, dossier.procedure.refused_mail_template)
+ end
+
+ def send_without_continuation_notification(dossier)
+ send_notification(dossier, dossier.procedure.without_continuation_mail_template)
+ end
+
def new_answer(dossier)
send_mail dossier, "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}"
end
private
+ def send_notification(dossier, mail_template)
+ vars_mailer(dossier)
+
+ @subject = mail_template.subject_for_dossier dossier
+ @body = mail_template.body_for_dossier dossier
+
+ mail(subject: @subject) { |format| format.html { @body } }
+ end
+
def create_commentaire_for_notification
Commentaire.create(
dossier: @dossier,
diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb
index e1063b294..e4fd48ca8 100644
--- a/app/models/administrateur.rb
+++ b/app/models/administrateur.rb
@@ -2,7 +2,7 @@ class Administrateur < ApplicationRecord
include CredentialsSyncableConcern
include EmailSanitizableConcern
- devise :database_authenticatable, :registerable,
+ devise :database_authenticatable, :registerable, :async,
:recoverable, :rememberable, :trackable, :validatable
has_and_belongs_to_many :gestionnaires
@@ -51,7 +51,7 @@ class Administrateur < ApplicationRecord
reset_password_token = set_reset_password_token
- AdministrationMailer.invite_admin(self, reset_password_token).deliver_now!
+ AdministrationMailer.invite_admin(self, reset_password_token).deliver_later
reset_password_token
end
diff --git a/app/models/administration.rb b/app/models/administration.rb
index d0da076e5..2428749f3 100644
--- a/app/models/administration.rb
+++ b/app/models/administration.rb
@@ -1,7 +1,7 @@
class Administration < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
- devise :database_authenticatable, :rememberable, :trackable, :validatable, :omniauthable, omniauth_providers: [:github]
+ devise :database_authenticatable, :rememberable, :trackable, :validatable, :omniauthable, :async, omniauth_providers: [:github]
def self.from_omniauth(params)
find_by(email: params["info"]["email"])
@@ -17,7 +17,7 @@ class Administration < ApplicationRecord
})
if administrateur.save
- AdministrationMailer.new_admin_email(administrateur, self).deliver_now!
+ AdministrationMailer.new_admin_email(administrateur, self).deliver_later
administrateur.invite!
User.create({
email: email,
diff --git a/app/models/avis.rb b/app/models/avis.rb
index 108d24777..37d8e96cf 100644
--- a/app/models/avis.rb
+++ b/app/models/avis.rb
@@ -34,7 +34,7 @@ class Avis < ApplicationRecord
private
def notify_gestionnaire
- AvisMailer.avis_invitation(self).deliver_now
+ AvisMailer.avis_invitation(self).deliver_later
end
def try_to_assign_gestionnaire
diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb
index 75e34596a..be89d2ef8 100644
--- a/app/models/commentaire.rb
+++ b/app/models/commentaire.rb
@@ -42,7 +42,7 @@ class Commentaire < ApplicationRecord
end
def notify_user
- NotificationMailer.new_answer(dossier).deliver_now!
+ NotificationMailer.new_answer(dossier).deliver_later
end
def is_virus_free?
diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb
index e3ee333bd..d220f5f80 100644
--- a/app/models/concerns/tags_substitution_concern.rb
+++ b/app/models/concerns/tags_substitution_concern.rb
@@ -107,7 +107,7 @@ module TagsSubstitutionConcern
{
libelle: 'adresse',
description: '',
- lambda: -> (e) { e&.etablissement&.inline_adresse },
+ target: :inline_adresse,
available_for_states: Dossier::SOUMIS
}
]
@@ -187,7 +187,7 @@ module TagsSubstitutionConcern
tags_and_datas = [
[dossier_tags, dossier],
[INDIVIDUAL_TAGS, dossier.individual],
- [ENTREPRISE_TAGS, dossier.entreprise]
+ [ENTREPRISE_TAGS, dossier.etablissement&.entreprise]
]
tags_and_datas
diff --git a/app/models/dossier.rb b/app/models/dossier.rb
index 301c04fa0..8fbe99ee4 100644
--- a/app/models/dossier.rb
+++ b/app/models/dossier.rb
@@ -14,7 +14,6 @@ class Dossier < ApplicationRecord
SOUMIS = EN_CONSTRUCTION_OU_INSTRUCTION + TERMINE
has_one :etablissement, dependent: :destroy
- has_one :entreprise, dependent: :destroy
has_one :individual, dependent: :destroy
has_one :attestation
has_many :cerfa, dependent: :destroy
@@ -56,7 +55,7 @@ class Dossier < ApplicationRecord
scope :en_construction, -> { not_archived.state_en_construction }
scope :en_instruction, -> { not_archived.state_en_instruction }
scope :termine, -> { not_archived.state_termine }
- scope :downloadable_sorted, -> { state_not_brouillon.includes(:entreprise, :etablissement, :champs, :champs_private).order(en_construction_at: 'asc') }
+ scope :downloadable_sorted, -> { state_not_brouillon.includes(:etablissement, :champs, :champs_private).order(en_construction_at: 'asc') }
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
scope :followed_by, -> (gestionnaire) { joins(:follows).where(follows: { gestionnaire: gestionnaire }) }
@@ -64,8 +63,7 @@ class Dossier < ApplicationRecord
accepts_nested_attributes_for :individual
- delegate :siren, to: :entreprise
- delegate :siret, to: :etablissement, allow_nil: true
+ delegate :siret, :siren, to: :etablissement, allow_nil: true
delegate :types_de_piece_justificative, to: :procedure
delegate :types_de_champ, to: :procedure
delegate :france_connect_information, to: :user
@@ -220,7 +218,7 @@ class Dossier < ApplicationRecord
when 'france_connect_information'
self.user.france_connect_information&.send(column)
when 'entreprise'
- self.entreprise&.send(column)
+ self.etablissement&.send(:"entreprise_#{column}")
when 'etablissement'
self.etablissement&.send(column)
when 'type_de_champ'
@@ -235,8 +233,8 @@ class Dossier < ApplicationRecord
end
def owner_name
- if entreprise.present?
- entreprise.raison_sociale
+ if etablissement.present?
+ etablissement.entreprise_raison_sociale
elsif individual.present?
"#{individual.nom} #{individual.prenom}"
end
@@ -298,8 +296,8 @@ class Dossier < ApplicationRecord
def export_etablissement_data
if etablissement.present?
- etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.transform_keys { |k| "etablissement.#{k}".parameterize.underscore.to_sym }
- entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym }
+ etablissement_attr = EtablissementCsvSerializer.new(etablissement).attributes.transform_keys { |k| "etablissement.#{k}".parameterize.underscore.to_sym }
+ entreprise_attr = EntrepriseSerializer.new(etablissement.entreprise).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym }
else
etablissement_attr = EtablissementSerializer.new(Etablissement.new).attributes.transform_keys { |k| "etablissement.#{k}".parameterize.underscore.to_sym }
entreprise_attr = EntrepriseSerializer.new(Entreprise.new).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym }
@@ -324,7 +322,7 @@ class Dossier < ApplicationRecord
def send_draft_notification_email
if brouillon?
- NotificationMailer.send_draft_notification(self).deliver_now!
+ NotificationMailer.send_draft_notification(self).deliver_later
end
end
diff --git a/app/models/entreprise.rb b/app/models/entreprise.rb
index bbf8c58ec..19cecd7e1 100644
--- a/app/models/entreprise.rb
+++ b/app/models/entreprise.rb
@@ -1,16 +1,20 @@
-class Entreprise < ApplicationRecord
- belongs_to :dossier
- has_one :etablissement
- has_one :rna_information, dependent: :destroy
-
- validates :siren, presence: true
- validates :dossier_id, uniqueness: true
-
- accepts_nested_attributes_for :rna_information, update_only: true
-
- before_save :default_values
-
- def default_values
- self.raison_sociale ||= ''
+class Entreprise < Hashie::Dash
+ def read_attribute_for_serialization(attribute)
+ self[attribute]
end
+
+ property :siren
+ property :capital_social
+ property :numero_tva_intracommunautaire
+ property :forme_juridique
+ property :forme_juridique_code
+ property :nom_commercial
+ property :raison_sociale
+ property :siret_siege_social
+ property :code_effectif_entreprise
+ property :date_creation
+ property :nom
+ property :prenom
+
+ property :inline_adresse
end
diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb
index 7ea3a94c9..9c103aa5a 100644
--- a/app/models/etablissement.rb
+++ b/app/models/etablissement.rb
@@ -1,18 +1,20 @@
class Etablissement < ApplicationRecord
belongs_to :dossier
- belongs_to :entreprise, dependent: :destroy
has_one :champ, class_name: 'Champs::SiretChamp'
has_many :exercices, dependent: :destroy
accepts_nested_attributes_for :exercices
- accepts_nested_attributes_for :entreprise, update_only: true
validates :siret, presence: true
validates :dossier_id, uniqueness: { allow_nil: true }
validate :validate_signature
+ def siren
+ entreprise_siren
+ end
+
def geo_adresse
[numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ')
end
@@ -22,10 +24,6 @@ class Etablissement < ApplicationRecord
"#{numero_voie} #{type_voie} #{nom_voie}, #{complement_adresse}, #{code_postal} #{localite}".squeeze(' ')
end
- def titre
- entreprise_raison_sociale || association_titre
- end
-
def verify
SignatureService.verify(signature, message_for_signature)
end
@@ -36,29 +34,26 @@ class Etablissement < ApplicationRecord
attr_accessor :signature
- def entreprise_raison_sociale_or_name
- entreprise_raison_sociale.presence || "#{entreprise_nom} #{entreprise_prenom}"
+ def association?
+ association_rna.present?
end
- def entreprise_effectif
- {
- 'NN' => "Unités non employeuses (pas de salarié au cours de l'année de référence et pas d'effectif au 31/12).",
- '00' => "0 salarié (n'ayant pas d'effectif au 31/12 mais ayant employé des salariés au cours de l'année de référence)",
- '01' => '1 ou 2 salariés',
- '02' => '3 à 5 salariés',
- '03' => '6 à 9 salariés',
- '11' => '10 à 19 salariés',
- '12' => '20 à 49 salariés',
- '21' => '50 à 99 salariés',
- '22' => '100 à 199 salariés',
- '31' => '200 à 249 salariés',
- '32' => '250 à 499 salariés',
- '41' => '500 à 999 salariés',
- '42' => '1 000 à 1 999 salariés',
- '51' => '2 000 à 4 999 salariés',
- '52' => '5 000 à 9 999 salariés',
- '53' => '10 000 salariés et plus'
- }[entreprise_code_effectif_entreprise]
+ def entreprise
+ Entreprise.new(
+ siren: entreprise_siren,
+ capital_social: entreprise_capital_social,
+ numero_tva_intracommunautaire: entreprise_numero_tva_intracommunautaire,
+ forme_juridique: entreprise_forme_juridique,
+ forme_juridique_code: entreprise_forme_juridique_code,
+ nom_commercial: entreprise_nom_commercial,
+ raison_sociale: entreprise_raison_sociale,
+ siret_siege_social: entreprise_siret_siege_social,
+ code_effectif_entreprise: entreprise_code_effectif_entreprise,
+ date_creation: entreprise_date_creation,
+ nom: entreprise_nom,
+ prenom: entreprise_prenom,
+ inline_adresse: inline_adresse
+ )
end
private
diff --git a/app/models/exercice.rb b/app/models/exercice.rb
index 0902916ee..f222bd768 100644
--- a/app/models/exercice.rb
+++ b/app/models/exercice.rb
@@ -2,8 +2,4 @@ class Exercice < ApplicationRecord
belongs_to :etablissement
validates :ca, presence: true, allow_blank: false, allow_nil: false
-
- def date_fin_exercice
- super || dateFinExercice
- end
end
diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb
index d96c603df..76b737e9a 100644
--- a/app/models/gestionnaire.rb
+++ b/app/models/gestionnaire.rb
@@ -2,7 +2,7 @@ class Gestionnaire < ApplicationRecord
include CredentialsSyncableConcern
include EmailSanitizableConcern
- devise :database_authenticatable, :registerable,
+ devise :database_authenticatable, :registerable, :async,
:recoverable, :rememberable, :trackable, :validatable
has_and_belongs_to_many :administrateurs
@@ -147,7 +147,7 @@ class Gestionnaire < ApplicationRecord
def invite!
reset_password_token = set_reset_password_token
- GestionnaireMailer.invite_gestionnaire(self, reset_password_token).deliver_now!
+ GestionnaireMailer.invite_gestionnaire(self, reset_password_token).deliver_later
end
private
diff --git a/app/models/procedure.rb b/app/models/procedure.rb
index a1927ca16..dbf8ede3d 100644
--- a/app/models/procedure.rb
+++ b/app/models/procedure.rb
@@ -34,10 +34,10 @@ class Procedure < ApplicationRecord
mount_uploader :logo, ProcedureLogoUploader
default_scope { where(hidden_at: nil) }
- scope :brouillons, -> { where(published_at: nil).where(archived_at: nil) }
- scope :publiees, -> { where.not(published_at: nil).where(archived_at: nil) }
- scope :archivees, -> { where.not(archived_at: nil) }
- scope :publiees_ou_archivees, -> { where.not(published_at: nil) }
+ scope :brouillons, -> { where(aasm_state: :brouillon) }
+ scope :publiees, -> { where(aasm_state: :publiee) }
+ scope :archivees, -> { where(aasm_state: :archivee) }
+ scope :publiees_ou_archivees, -> { where(aasm_state: [:publiee, :archivee]) }
scope :by_libelle, -> { order(libelle: :asc) }
scope :created_during, -> (range) { where(created_at: range) }
scope :cloned_from_library, -> { where(cloned_from_library: true) }
@@ -193,6 +193,8 @@ class Procedure < ApplicationRecord
types_de_champ: :drop_down_list,
types_de_champ_private: :drop_down_list
})
+ procedure.aasm_state = :brouillon
+ procedure.test_started_at = nil
procedure.archived_at = nil
procedure.published_at = nil
procedure.logo_secure_token = nil
@@ -285,12 +287,12 @@ class Procedure < ApplicationRecord
if !for_individual || (for_individual && individual_with_siret)
fields << [
- field_hash('SIREN', 'entreprise', 'siren'),
- field_hash('Forme juridique', 'entreprise', 'forme_juridique'),
- field_hash('Nom commercial', 'entreprise', 'nom_commercial'),
- field_hash('Raison sociale', 'entreprise', 'raison_sociale'),
- field_hash('SIRET siège social', 'entreprise', 'siret_siege_social'),
- field_hash('Date de création', 'entreprise', 'date_creation')
+ field_hash('SIREN', 'etablissement', 'entreprise_siren'),
+ field_hash('Forme juridique', 'etablissement', 'entreprise_forme_juridique'),
+ field_hash('Nom commercial', 'etablissement', 'entreprise_nom_commercial'),
+ field_hash('Raison sociale', 'etablissement', 'entreprise_raison_sociale'),
+ field_hash('SIRET siège social', 'etablissement', 'entreprise_siret_siege_social'),
+ field_hash('Date de création', 'etablissement', 'entreprise_date_creation')
]
fields << [
diff --git a/app/models/rna_information.rb b/app/models/rna_information.rb
deleted file mode 100644
index 9797d1072..000000000
--- a/app/models/rna_information.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-class RNAInformation < ApplicationRecord
- belongs_to :entreprise
-
- validates :association_id, presence: true, allow_blank: false, allow_nil: false
-
- def rna=(id)
- write_attribute(:association_id, id)
- end
-end
diff --git a/app/models/user.rb b/app/models/user.rb
index 1bd1668a7..2de403c64 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -9,7 +9,7 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
- devise :database_authenticatable, :registerable,
+ devise :database_authenticatable, :registerable, :async,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
has_many :dossiers, dependent: :destroy
diff --git a/app/serializers/dossier_serializer.rb b/app/serializers/dossier_serializer.rb
index a3b70dc31..18601f89e 100644
--- a/app/serializers/dossier_serializer.rb
+++ b/app/serializers/dossier_serializer.rb
@@ -34,6 +34,10 @@ class DossierSerializer < ActiveModel::Serializer
object.user.try(:email)
end
+ def entreprise
+ object.etablissement&.entreprise
+ end
+
def state
case object.state
when 'en_construction'
diff --git a/app/serializers/entreprise_serializer.rb b/app/serializers/entreprise_serializer.rb
index d46ab8672..3a52d7917 100644
--- a/app/serializers/entreprise_serializer.rb
+++ b/app/serializers/entreprise_serializer.rb
@@ -11,4 +11,8 @@ class EntrepriseSerializer < ActiveModel::Serializer
:date_creation,
:nom,
:prenom
+
+ def date_creation
+ object.date_creation ? object.date_creation.to_datetime : nil
+ end
end
diff --git a/app/services/api_entreprise_service.rb b/app/services/api_entreprise_service.rb
index ea77019a9..0dec08efc 100644
--- a/app/services/api_entreprise_service.rb
+++ b/app/services/api_entreprise_service.rb
@@ -1,5 +1,5 @@
class ApiEntrepriseService
- def self.get_etablissement_params_for_siret(siret, procedure_id, dossier = nil)
+ def self.get_etablissement_params_for_siret(siret, procedure_id)
etablissement_params = ApiEntreprise::EtablissementAdapter.new(siret, procedure_id).to_params
entreprise_params = ApiEntreprise::EntrepriseAdapter.new(siret, procedure_id).to_params
@@ -7,26 +7,10 @@ class ApiEntrepriseService
association_params = ApiEntreprise::RNAAdapter.new(siret, procedure_id).to_params
exercices_params = ApiEntreprise::ExercicesAdapter.new(siret, procedure_id).to_params
- params = etablissement_params
- .merge(entreprise_params.transform_keys { |k| "entreprise_#{k}" })
- .merge(association_params.transform_keys { |k| "association_#{k}" })
+ etablissement_params
+ .merge(entreprise_params)
+ .merge(association_params)
.merge(exercices_params)
-
- # This is to fill legacy models and relationships
- if dossier.present?
- handle_legacy_models!(params, entreprise_params, dossier, association_params)
- end
-
- params
end
end
-
- def self.handle_legacy_models!(params, entreprise_params, dossier, association_params)
- params[:entreprise_attributes] = entreprise_params.merge(
- {
- dossier: dossier,
- rna_information_attributes: association_params.presence
- }.compact
- )
- end
end
diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml
index 521fa4329..e26e40545 100644
--- a/app/views/admin/procedures/show.html.haml
+++ b/app/views/admin/procedures/show.html.haml
@@ -68,7 +68,7 @@
%h4.text-info
= procedure.libelle
- = h sanitize(procedure.description)
+ = h string_to_html(procedure.description)
.champs.col-xs-6.col-md-3
%h4.text-info
diff --git a/app/views/dossiers/_dossier_show.html.haml b/app/views/dossiers/_dossier_show.html.haml
index 2d2a4d259..79102a2c9 100644
--- a/app/views/dossiers/_dossier_show.html.haml
+++ b/app/views/dossiers/_dossier_show.html.haml
@@ -16,7 +16,7 @@
.col-lg-4.col-md-4.col-sm-4.col-xs-4.action
Renseigner un SIRET
-- if @facade.entreprise.present?
+- if @facade.etablissement.present?
.default-data-block
.row.show-block.infos#infos_entreprise
.header
diff --git a/app/views/dossiers/_infos_entreprise.html.haml b/app/views/dossiers/_infos_entreprise.html.haml
index aad89acb7..f07f3e90c 100644
--- a/app/views/dossiers/_infos_entreprise.html.haml
+++ b/app/views/dossiers/_infos_entreprise.html.haml
@@ -1,6 +1,6 @@
.col-md-12.col-sm-12.col-xs-12.col-xs-12
%h4
- = @facade.entreprise.raison_sociale_or_name
+ = raison_sociale_or_name(@facade.etablissement)
.row.split-row
.col-xs-12.split-hr
.row
@@ -9,13 +9,13 @@
.row
.col-xs-4.entreprise-label Siret :
.col-xs-8.entreprise-info= @facade.etablissement.siret
- - if @facade.etablissement.siret != @facade.entreprise.siret_siege_social
+ - if @facade.etablissement.siret != @facade.etablissement.entreprise.siret_siege_social
.row
.col-xs-4.entreprise-label SIRET siège social :
- .col-xs-8.entreprise-info= @facade.entreprise.siret_siege_social
+ .col-xs-8.entreprise-info= @facade.etablissement.entreprise.siret_siege_social
.row
.col-xs-4.entreprise-label Forme juridique :
- .col-xs-8.entreprise-info= @facade.entreprise.forme_juridique
+ .col-xs-8.entreprise-info= @facade.etablissement.entreprise.forme_juridique
.row
.col-xs-4.entreprise-label Libellé naf :
.col-xs-8.entreprise-info= @facade.etablissement.libelle_naf
@@ -24,16 +24,16 @@
.col-xs-8.entreprise-info= @facade.etablissement.naf
.row
.col-xs-4.entreprise-label Date de création :
- .col-xs-8.entreprise-info= Time.at(@facade.entreprise.date_creation).localtime.strftime "%d-%m-%Y"
+ .col-xs-8.entreprise-info= @facade.etablissement.entreprise.date_creation&.strftime("%d-%m-%Y")
.row
.col-xs-4.entreprise-label Effectif organisation :
- .col-xs-8.entreprise-info= @facade.entreprise.effectif
+ .col-xs-8.entreprise-info= effectif(@facade.etablissement)
.row
.col-xs-4.entreprise-label Code effectif :
- .col-xs-8.entreprise-info= @facade.entreprise.code_effectif_entreprise
+ .col-xs-8.entreprise-info= @facade.etablissement.entreprise.code_effectif_entreprise
.row
.col-xs-4.entreprise-label Numéro TVA intracommunautaire :
- .col-xs-8.entreprise-info= @facade.entreprise.numero_tva_intracommunautaire
+ .col-xs-8.entreprise-info= @facade.etablissement.entreprise.numero_tva_intracommunautaire
.row
.col-xs-4.entreprise-label Adresse :
@@ -42,7 +42,7 @@
= line
.row
.col-xs-4.entreprise-label Capital social :
- .col-xs-8.entreprise-info= @facade.entreprise.pretty_capital_social
+ .col-xs-8.entreprise-info= pretty_currency(@facade.etablissement.entreprise.capital_social)
.row
.col-xs-4.entreprise-label Exercices :
@@ -55,5 +55,5 @@
.row.split-row
.col-xs-12.split-hr
-- if @facade.entreprise.rna_information.present?
+- if @facade.etablissement.association?
= render partial: '/dossiers/infos_rna'
diff --git a/app/views/dossiers/_infos_rna.html.haml b/app/views/dossiers/_infos_rna.html.haml
index 0685a2afa..b57a2c718 100644
--- a/app/views/dossiers/_infos_rna.html.haml
+++ b/app/views/dossiers/_infos_rna.html.haml
@@ -2,21 +2,21 @@
.col-lg-6.col-md-6.col-sm-6.col-xs-6
%dl.dl-horizontal
%dt Association ID :
- %dd.text-success= @facade.entreprise.rna_information.association_id
+ %dd.text-success= @facade.etablissement.association_rna
%dt Titre :
- %dd= @facade.entreprise.rna_information.titre
+ %dd= @facade.etablissement.association_titre
%dt Objet :
- %dd= @facade.entreprise.rna_information.objet
+ %dd= @facade.etablissement.association_objet
.col-lg-6.col-md-6.col-sm-6.col-xs-6
%dl.dl-horizontal
%dt Date création :
- %dd= @facade.entreprise.rna_information.date_creation
+ %dd= @facade.etablissement.association_date_creation&.strftime("%d/%m/%Y")
%dt Capital publication :
- %dd= @facade.entreprise.rna_information.date_publication
+ %dd= @facade.etablissement.association_date_publication&.strftime("%d/%m/%Y")
%dt Capital déclaration :
- %dd= @facade.entreprise.rna_information.date_declaration
+ %dd= @facade.etablissement.association_date_declaration&.strftime("%d/%m/%Y")
diff --git a/app/views/dossiers/etapes/_etape1.html.haml b/app/views/dossiers/etapes/_etape1.html.haml
index 5d6391f8e..7b12d5ecc 100644
--- a/app/views/dossiers/etapes/_etape1.html.haml
+++ b/app/views/dossiers/etapes/_etape1.html.haml
@@ -1,7 +1,7 @@
.col-xs-3.center
%h3 Ma procédure
- #logos.center{ class: (@facade.entreprise.nil? ? '' : 'mask') }
+ #logos.center{ class: (@facade.etablissement.nil? ? '' : 'mask') }
- if @facade.procedure.euro_flag
#euro_flag.flag
= image_tag('drapeau_europe.png')
@@ -15,8 +15,8 @@
%h2#titre-procedure.text-info
= @facade.procedure.libelle
- #description_procedure{ style: 'width: 95%;', class: (@facade.entreprise.nil? ? '' : 'mask') }
- = h simple_format(@facade.procedure.description)
+ #description_procedure{ style: 'width: 95%;', class: (@facade.etablissement.nil? ? '' : 'mask') }
+ = h string_to_html(@facade.procedure.description)
- if @facade.procedure.lien_site_web.present?
.center
diff --git a/app/views/dossiers/etapes/etape_2/_entreprise.html.haml b/app/views/dossiers/etapes/etape_2/_entreprise.html.haml
index 69c44a179..7298345b1 100644
--- a/app/views/dossiers/etapes/etape_2/_entreprise.html.haml
+++ b/app/views/dossiers/etapes/etape_2/_entreprise.html.haml
@@ -2,7 +2,7 @@
%h3
Mes informations
%br
- - if @facade.entreprise.present?
+ - if @facade.etablissement.present?
.center{ style: 'margin-left: -5%;' }
Vous êtes authentifié avec le SIRET
@@ -14,7 +14,7 @@
.etape.etapes-informations.col-xs-9
.row
- - if @facade.entreprise.nil?
+ - if @facade.etablissement.nil?
#new_siret{ style: 'margin-left: 20%; margin-top: 5%;' }
= form_for @facade.dossier, html: { class: 'form-inline' }, url: users_dossier_siret_informations_path(dossier_id: @facade.dossier.id), method: :post, remote: true do |f|
.form-group.form-group-lg
diff --git a/app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml b/app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml
index ff83d56ef..64d63f581 100644
--- a/app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml
+++ b/app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml
@@ -2,13 +2,13 @@
%tbody
%tr
%th.libelle Dénomination :
- %td= etablissement.entreprise_raison_sociale_or_name
+ %td= raison_sociale_or_name(etablissement)
%tr
%th.libelle SIRET :
- %td= etablissement.entreprise_siret_siege_social
+ %td= etablissement.entreprise.siret_siege_social
%tr
%th.libelle Forme juridique :
- %td= sanitize(etablissement.entreprise_forme_juridique)
+ %td= sanitize(etablissement.entreprise.forme_juridique)
%tr
%th.libelle Libellé NAF :
%td= etablissement.libelle_naf
@@ -17,16 +17,16 @@
%td= etablissement.naf
%tr
%th.libelle Date de création :
- %td= etablissement.entreprise_date_creation&.strftime("%d/%m/%Y")
+ %td= etablissement.entreprise.date_creation&.strftime("%d/%m/%Y")
%tr
%th.libelle Effectif de l'organisation :
- %td= etablissement.entreprise_effectif
+ %td= effectif(etablissement)
%tr
%th.libelle Code effectif :
- %td= etablissement.entreprise_code_effectif_entreprise
+ %td= etablissement.entreprise.code_effectif_entreprise
%tr
%th.libelle Numéro de TVA intracommunautaire :
- %td= etablissement.entreprise_numero_tva_intracommunautaire
+ %td= etablissement.entreprise.numero_tva_intracommunautaire
%tr
%th.libelle Adresse :
%td
@@ -35,7 +35,7 @@
%br
%tr
%th.libelle Capital social :
- %td= pretty_currency(etablissement.entreprise_capital_social)
+ %td= pretty_currency(etablissement.entreprise.capital_social)
%tr
%th.libelle Exercices :
%td
@@ -43,7 +43,7 @@
= "#{exercice.date_fin_exercice.year} : "
= pretty_currency(exercice.ca)
%br
- - if etablissement.association_rna.present?
+ - if etablissement.association?
%tr
%th.libelle Numéro RNA :
%td= etablissement.association_rna
diff --git a/app/views/new_user/dossiers/identite.html.haml b/app/views/new_user/dossiers/identite.html.haml
index 54fea25a4..6847dc8f6 100644
--- a/app/views/new_user/dossiers/identite.html.haml
+++ b/app/views/new_user/dossiers/identite.html.haml
@@ -9,7 +9,7 @@
%h2.procedure-title
= @dossier.procedure.libelle
.procedure-description
- = h simple_format(@dossier.procedure.description)
+ = h string_to_html(@dossier.procedure.description)
.column
= form_for @dossier.individual, url: update_identite_dossier_path(@dossier), html: { class: "form" } do |f|
diff --git a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml
index 76d7c3596..8c1070299 100644
--- a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml
+++ b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml
@@ -8,4 +8,4 @@
= "modifié le #{champ.updated_at.strftime('%d/%m/%Y à %H:%M')}"
- if champ.description.present?
- %span.notice= html_formatted_description(champ.description)
+ %span.notice= string_to_html(champ.description)
diff --git a/app/views/shared/dossiers/editable_champs/_etablissement_titre.html.haml b/app/views/shared/dossiers/editable_champs/_etablissement_titre.html.haml
index b63734321..8a4d379b3 100644
--- a/app/views/shared/dossiers/editable_champs/_etablissement_titre.html.haml
+++ b/app/views/shared/dossiers/editable_champs/_etablissement_titre.html.haml
@@ -1,6 +1,6 @@
.etablissement-titre
- = etablissement.titre
+ = raison_sociale_or_name(etablissement)
= etablissement.entreprise_forme_juridique
- if etablissement.entreprise_capital_social.present?
au capital social de
- = number_to_currency(etablissement.entreprise_capital_social)
+ = pretty_currency(etablissement.entreprise_capital_social)
diff --git a/app/views/shared/dossiers/editable_champs/_explication.html.haml b/app/views/shared/dossiers/editable_champs/_explication.html.haml
index 07ef71490..4dce77388 100644
--- a/app/views/shared/dossiers/editable_champs/_explication.html.haml
+++ b/app/views/shared/dossiers/editable_champs/_explication.html.haml
@@ -1,3 +1,3 @@
%h2.explication-libelle= champ.libelle
.explication
- = html_formatted_description(champ.description)
+ = string_to_html(champ.description)
diff --git a/app/views/users/sessions/_resume_procedure.html.haml b/app/views/users/sessions/_resume_procedure.html.haml
index f42a11ad1..56ea59e91 100644
--- a/app/views/users/sessions/_resume_procedure.html.haml
+++ b/app/views/users/sessions/_resume_procedure.html.haml
@@ -13,7 +13,7 @@
%h2#titre-procedure.text-info
= @dossier.procedure.libelle
%p.procedure-description
- = h sanitize(@dossier.procedure.description)
+ = h string_to_html(@dossier.procedure.description)
- else
#logo_procedure.flag
diff --git a/app/views/users/siret/_pro.html.haml b/app/views/users/siret/_pro.html.haml
index f263f255a..5ddb0de3d 100644
--- a/app/views/users/siret/_pro.html.haml
+++ b/app/views/users/siret/_pro.html.haml
@@ -6,7 +6,7 @@
= @procedure.libelle
%div
- = simple_format(@procedure.description)
+ = h string_to_html(@procedure.description)
%br
= form_tag(url_for({ controller: :dossiers, action: :create }), class: 'form-inline', method: 'POST') do |f|
diff --git a/db/migrate/20180418094115_update_searches_to_version_3.rb b/db/migrate/20180418094115_update_searches_to_version_3.rb
new file mode 100644
index 000000000..f9736b4a0
--- /dev/null
+++ b/db/migrate/20180418094115_update_searches_to_version_3.rb
@@ -0,0 +1,9 @@
+class UpdateSearchesToVersion3 < ActiveRecord::Migration[5.2]
+ def up
+ replace_view :searches, version: 3
+ end
+
+ def down
+ replace_view :searches, version: 2
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 177d23408..16ea44e85 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -609,15 +609,13 @@ ActiveRecord::Schema.define(version: 2018_05_22_142109) do
create_view "searches", sql_definition: <<-SQL
SELECT dossiers.id AS dossier_id,
- (((((((((((((((((((((((((((((((((((((((((((((((((((((((COALESCE(users.email, ''::character varying))::text || ' '::text) || (COALESCE(france_connect_informations.given_name, ''::character varying))::text) || ' '::text) || (COALESCE(france_connect_informations.family_name, ''::character varying))::text) || ' '::text) || (COALESCE(cerfas.content, ''::character varying))::text) || ' '::text) || (COALESCE(champs.value, ''::character varying))::text) || ' '::text) || (COALESCE(drop_down_lists.value, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siren, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.numero_tva_intracommunautaire, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique_code, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom_commercial, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.raison_sociale, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siret_siege_social, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.association_id, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.titre, ''::character varying))::text) || ' '::text) || COALESCE(rna_informations.objet, ''::text)) || ' '::text) || (COALESCE(etablissements.siret, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.libelle_naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.adresse, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_postal, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.localite, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_insee_localite, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.nom, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(pieces_justificatives.content, ''::character varying))::text) AS term
- FROM ((((((((((dossiers
+ (((((((((((((((((((((((((((((((((((((((((((((((((((((((COALESCE(users.email, ''::character varying))::text || ' '::text) || (COALESCE(france_connect_informations.given_name, ''::character varying))::text) || ' '::text) || (COALESCE(france_connect_informations.family_name, ''::character varying))::text) || ' '::text) || (COALESCE(cerfas.content, ''::character varying))::text) || ' '::text) || (COALESCE(champs.value, ''::character varying))::text) || ' '::text) || (COALESCE(drop_down_lists.value, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_siren, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_numero_tva_intracommunautaire, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_forme_juridique, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_forme_juridique_code, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_nom_commercial, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_raison_sociale, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_siret_siege_social, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_nom, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_prenom, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.association_rna, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.association_titre, ''::character varying))::text) || ' '::text) || COALESCE(etablissements.association_objet, ''::text)) || ' '::text) || (COALESCE(etablissements.siret, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.libelle_naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.adresse, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_postal, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.localite, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_insee_localite, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.nom, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(pieces_justificatives.content, ''::character varying))::text) AS term
+ FROM ((((((((dossiers
JOIN users ON ((users.id = dossiers.user_id)))
LEFT JOIN france_connect_informations ON ((france_connect_informations.user_id = dossiers.user_id)))
LEFT JOIN cerfas ON ((cerfas.dossier_id = dossiers.id)))
LEFT JOIN champs ON ((champs.dossier_id = dossiers.id)))
LEFT JOIN drop_down_lists ON ((drop_down_lists.type_de_champ_id = champs.type_de_champ_id)))
- LEFT JOIN entreprises ON ((entreprises.dossier_id = dossiers.id)))
- LEFT JOIN rna_informations ON ((rna_informations.entreprise_id = entreprises.id)))
LEFT JOIN etablissements ON ((etablissements.dossier_id = dossiers.id)))
LEFT JOIN individuals ON ((individuals.dossier_id = dossiers.id)))
LEFT JOIN pieces_justificatives ON ((pieces_justificatives.dossier_id = dossiers.id)));
diff --git a/db/views/searches_v03.sql b/db/views/searches_v03.sql
new file mode 100644
index 000000000..f847fc13f
--- /dev/null
+++ b/db/views/searches_v03.sql
@@ -0,0 +1,41 @@
+-- this version merges all possible search terms together, complicating the
+-- view, but enables searching for multiple terms from multiple tables at once.
+
+SELECT dossiers.id AS dossier_id,
+ COALESCE(users.email, '') || ' ' ||
+ COALESCE(france_connect_informations.given_name, '') || ' ' ||
+ COALESCE(france_connect_informations.family_name, '') || ' ' ||
+ COALESCE(cerfas.content, '') || ' ' ||
+ COALESCE(champs.value, '') || ' ' ||
+ COALESCE(drop_down_lists.value, '') || ' ' ||
+ COALESCE(etablissements.entreprise_siren, '') || ' ' ||
+ COALESCE(etablissements.entreprise_numero_tva_intracommunautaire, '') || ' ' ||
+ COALESCE(etablissements.entreprise_forme_juridique, '') || ' ' ||
+ COALESCE(etablissements.entreprise_forme_juridique_code, '') || ' ' ||
+ COALESCE(etablissements.entreprise_nom_commercial, '') || ' ' ||
+ COALESCE(etablissements.entreprise_raison_sociale, '') || ' ' ||
+ COALESCE(etablissements.entreprise_siret_siege_social, '') || ' ' ||
+ COALESCE(etablissements.entreprise_nom, '') || ' ' ||
+ COALESCE(etablissements.entreprise_prenom, '') || ' ' ||
+ COALESCE(etablissements.association_rna, '') || ' ' ||
+ COALESCE(etablissements.association_titre, '') || ' ' ||
+ COALESCE(etablissements.association_objet, '') || ' ' ||
+ COALESCE(etablissements.siret, '') || ' ' ||
+ COALESCE(etablissements.naf, '') || ' ' ||
+ COALESCE(etablissements.libelle_naf, '') || ' ' ||
+ COALESCE(etablissements.adresse, '') || ' ' ||
+ COALESCE(etablissements.code_postal, '') || ' ' ||
+ COALESCE(etablissements.localite, '') || ' ' ||
+ COALESCE(etablissements.code_insee_localite, '') || ' ' ||
+ COALESCE(individuals.nom, '') || ' ' ||
+ COALESCE(individuals.prenom, '') || ' ' ||
+ COALESCE(pieces_justificatives.content, '') AS term
+FROM dossiers
+INNER JOIN users ON users.id = dossiers.user_id
+LEFT JOIN france_connect_informations ON france_connect_informations.user_id = dossiers.user_id
+LEFT JOIN cerfas ON cerfas.dossier_id = dossiers.id
+LEFT JOIN champs ON champs.dossier_id = dossiers.id
+LEFT JOIN drop_down_lists ON drop_down_lists.type_de_champ_id = champs.type_de_champ_id
+LEFT JOIN etablissements ON etablissements.dossier_id = dossiers.id
+LEFT JOIN individuals ON individuals.dossier_id = dossiers.id
+LEFT JOIN pieces_justificatives ON pieces_justificatives.dossier_id = dossiers.id
diff --git a/spec/controllers/admin/gestionnaires_controller_spec.rb b/spec/controllers/admin/gestionnaires_controller_spec.rb
index 6fe2da4d0..0e495f9e7 100644
--- a/spec/controllers/admin/gestionnaires_controller_spec.rb
+++ b/spec/controllers/admin/gestionnaires_controller_spec.rb
@@ -71,7 +71,7 @@ describe Admin::GestionnairesController, type: :controller do
describe 'Email Notification' do
it {
expect(GestionnaireMailer).not_to receive(:new_gestionnaire)
- expect(GestionnaireMailer).not_to receive(:deliver_now!)
+ expect(GestionnaireMailer).not_to receive(:deliver_later)
subject
}
end
@@ -87,7 +87,7 @@ describe Admin::GestionnairesController, type: :controller do
it 'Notification email is not send' do
expect(GestionnaireMailer).not_to receive(:new_gestionnaire)
- expect(GestionnaireMailer).not_to receive(:deliver_now!)
+ expect(GestionnaireMailer).not_to receive(:deliver_later)
end
end
@@ -104,7 +104,7 @@ describe Admin::GestionnairesController, type: :controller do
describe 'Email notification' do
it 'is not sent when email already exists' do
expect(GestionnaireMailer).not_to receive(:new_gestionnaire)
- expect(GestionnaireMailer).not_to receive(:deliver_now!)
+ expect(GestionnaireMailer).not_to receive(:deliver_later)
subject
end
diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb
index 3852b60eb..99b83e973 100644
--- a/spec/controllers/api/v1/dossiers_controller_spec.rb
+++ b/spec/controllers/api/v1/dossiers_controller_spec.rb
@@ -173,7 +173,7 @@ describe API::V1::DossiersController do
it { expect(subject[:raison_sociale]).to eq('GRTGAZ') }
it { expect(subject[:siret_siege_social]).to eq('44011762001530') }
it { expect(subject[:code_effectif_entreprise]).to eq('51') }
- it { expect(subject[:date_creation]).to eq('2016-01-28T10:16:29.000Z') }
+ it { expect(subject[:date_creation]).to eq('1990-04-24T00:00:00.000+00:00') }
it { expect(subject.keys).to match_array(field_list) }
end
diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb
index 3765184e1..d65754633 100644
--- a/spec/controllers/invites_controller_spec.rb
+++ b/spec/controllers/invites_controller_spec.rb
@@ -131,7 +131,7 @@ describe InvitesController, type: :controller do
context 'when user does not exist' do
it 'send email' do
expect(InviteMailer).to receive(:invite_guest).and_return(InviteMailer)
- expect(InviteMailer).to receive(:deliver_now!)
+ expect(InviteMailer).to receive(:deliver_later)
subject
end
@@ -144,7 +144,7 @@ describe InvitesController, type: :controller do
it 'send email' do
expect(InviteMailer).to receive(:invite_user).and_return(InviteMailer)
- expect(InviteMailer).to receive(:deliver_now!)
+ expect(InviteMailer).to receive(:deliver_later)
subject
end
diff --git a/spec/controllers/manager/administrateurs_controller_spec.rb b/spec/controllers/manager/administrateurs_controller_spec.rb
index 86fbe4ea5..432aa9daa 100644
--- a/spec/controllers/manager/administrateurs_controller_spec.rb
+++ b/spec/controllers/manager/administrateurs_controller_spec.rb
@@ -18,9 +18,9 @@ describe Manager::AdministrateursController, type: :controller do
it 'alert new mail are send' do
expect(AdministrationMailer).to receive(:new_admin_email).and_return(AdministrationMailer)
- expect(AdministrationMailer).to receive(:deliver_now!)
+ expect(AdministrationMailer).to receive(:deliver_later)
expect(AdministrationMailer).to receive(:invite_admin).and_return(AdministrationMailer)
- expect(AdministrationMailer).to receive(:deliver_now!)
+ expect(AdministrationMailer).to receive(:deliver_later)
subject
end
end
diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb
index e23bfa5f8..960595898 100644
--- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb
+++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb
@@ -151,9 +151,9 @@ describe NewGestionnaire::DossiersController, type: :controller do
end
it 'Notification email is sent' do
- expect(NotificationMailer).to receive(:send_notification)
- .with(dossier, kind_of(Mails::RefusedMail)).and_return(NotificationMailer)
- expect(NotificationMailer).to receive(:deliver_now!)
+ expect(NotificationMailer).to receive(:send_refused_notification)
+ .with(dossier).and_return(NotificationMailer)
+ expect(NotificationMailer).to receive(:deliver_later)
subject
end
@@ -177,9 +177,9 @@ describe NewGestionnaire::DossiersController, type: :controller do
end
it 'Notification email is sent' do
- expect(NotificationMailer).to receive(:send_notification)
- .with(dossier, kind_of(Mails::WithoutContinuationMail)).and_return(NotificationMailer)
- expect(NotificationMailer).to receive(:deliver_now!)
+ expect(NotificationMailer).to receive(:send_without_continuation_notification)
+ .with(dossier).and_return(NotificationMailer)
+ expect(NotificationMailer).to receive(:deliver_later)
subject
end
@@ -192,11 +192,11 @@ describe NewGestionnaire::DossiersController, type: :controller do
dossier.en_instruction!
sign_in gestionnaire
- expect(NotificationMailer).to receive(:send_notification)
- .with(dossier, kind_of(Mails::ClosedMail))
+ expect(NotificationMailer).to receive(:send_closed_notification)
+ .with(dossier)
.and_return(NotificationMailer)
- expect(NotificationMailer).to receive(:deliver_now!)
+ expect(NotificationMailer).to receive(:deliver_later)
end
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id } }
diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb
index 005d39287..0f2b958eb 100644
--- a/spec/controllers/new_user/dossiers_controller_spec.rb
+++ b/spec/controllers/new_user/dossiers_controller_spec.rb
@@ -221,14 +221,14 @@ describe NewUser::DossiersController, type: :controller do
it 'sends an email only on the first #update' do
delivery = double
- expect(delivery).to receive(:deliver_now!).with(no_args)
+ expect(delivery).to receive(:deliver_later).with(no_args)
- expect(NotificationMailer).to receive(:send_notification)
+ expect(NotificationMailer).to receive(:send_initiated_notification)
.and_return(delivery)
subject
- expect(NotificationMailer).not_to receive(:send_notification)
+ expect(NotificationMailer).not_to receive(:send_initiated_notification)
subject
end
@@ -246,7 +246,7 @@ describe NewUser::DossiersController, type: :controller do
it { expect(flash.alert).to eq(['nop']) }
it 'does not send an email' do
- expect(NotificationMailer).not_to receive(:send_notification)
+ expect(NotificationMailer).not_to receive(:send_received_notification)
subject
end
diff --git a/spec/controllers/users/carte_controller_spec.rb b/spec/controllers/users/carte_controller_spec.rb
index 8fbb7216b..8cea48644 100644
--- a/spec/controllers/users/carte_controller_spec.rb
+++ b/spec/controllers/users/carte_controller_spec.rb
@@ -12,7 +12,6 @@ RSpec.describe Users::CarteController, type: :controller do
let(:invite_by_user) { create :user, email: 'invite@plop.com' }
let(:dossier_with_no_carto) { create(:dossier) }
- let!(:entreprise) { create(:entreprise, dossier: dossier) }
let!(:etablissement) { create(:etablissement, dossier: dossier) }
let(:bad_dossier_id) { Dossier.count + 1000 }
let(:adresse) { etablissement.geo_adresse }
diff --git a/spec/controllers/users/description_controller_shared_example.rb b/spec/controllers/users/description_controller_shared_example.rb
index 05354ccea..f9d8f755b 100644
--- a/spec/controllers/users/description_controller_shared_example.rb
+++ b/spec/controllers/users/description_controller_shared_example.rb
@@ -16,7 +16,7 @@ shared_examples 'description_controller_spec' do
context 'when all is ok' do
before do
- dossier.entreprise = create :entreprise
+ dossier.etablissement = create(:etablissement)
get :show, params: { dossier_id: dossier_id }
end
@@ -85,8 +85,8 @@ shared_examples 'description_controller_spec' do
describe 'before action check_starter_dossier_informations' do
subject { get :show, params: { dossier_id: dossier_id } }
- context 'when dossier does not have an enterprise datas' do
- it { expect(dossier.entreprise).to be_nil }
+ context 'when dossier does not have an etablissement datas' do
+ it { expect(dossier.etablissement).to be_nil }
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
end
@@ -132,9 +132,12 @@ shared_examples 'description_controller_spec' do
after { Timecop.return }
it 'sets the state of the dossier before sending the mail' do
- expect_any_instance_of(Mails::InitiatedMail)
- .to receive(:subject_for_dossier)
+ sender = double("notification sender")
+ allow(sender).to receive(:deliver_later)
+ expect(NotificationMailer)
+ .to receive(:send_initiated_notification)
.with(have_attributes(en_construction_at: DateTime.now))
+ .and_return(sender)
submit_dossier
end
diff --git a/spec/controllers/users/dossiers/commentaires_controller_spec.rb b/spec/controllers/users/dossiers/commentaires_controller_spec.rb
index 00519c3e2..3cae043b9 100644
--- a/spec/controllers/users/dossiers/commentaires_controller_spec.rb
+++ b/spec/controllers/users/dossiers/commentaires_controller_spec.rb
@@ -24,7 +24,7 @@ describe Users::Dossiers::CommentairesController, type: :controller do
it 'should notify user' do
expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer)
- expect(NotificationMailer).to receive(:deliver_now!)
+ expect(NotificationMailer).to receive(:deliver_later)
subject
end
diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb
index 2208e04a7..99770bf05 100644
--- a/spec/controllers/users/dossiers_controller_spec.rb
+++ b/spec/controllers/users/dossiers_controller_spec.rb
@@ -212,15 +212,6 @@ describe Users::DossiersController, type: :controller do
expect { subject }.to change { Dossier.count }.by(0)
end
- it 'creates entreprise' do
- expect { subject }.to change { Entreprise.count }.by(1)
- end
-
- it 'links entreprise to dossier' do
- subject
- expect(Entreprise.last.dossier).to eq(Dossier.last)
- end
-
it "links dossier to user" do
subject
expect(Dossier.last.user).to eq(user)
@@ -237,7 +228,7 @@ describe Users::DossiersController, type: :controller do
it 'links etablissement to entreprise' do
subject
- expect(Etablissement.last.entreprise).to eq(Entreprise.last)
+ expect(Etablissement.last.entreprise).to be_truthy
end
it 'creates exercices for dossier' do
@@ -267,8 +258,9 @@ describe Users::DossiersController, type: :controller do
let(:rna_status) { 404 }
let(:rna_body) { '' }
- it 'not creates rna information for entreprise' do
- expect { subject }.to change { RNAInformation.count }.by(0)
+ it 'not creates association information for etablissement' do
+ subject
+ expect(Dossier.last.etablissement.association?).to be_falsey
end
end
@@ -277,12 +269,8 @@ describe Users::DossiersController, type: :controller do
let(:rna_body) { File.read('spec/support/files/rna.json') }
it 'creates rna information for entreprise' do
- expect { subject }.to change { RNAInformation.count }.by(1)
- end
-
- it 'links rna informations to entreprise' do
subject
- expect(RNAInformation.last.entreprise).to eq(Entreprise.last)
+ expect(Dossier.last.etablissement.association?).to be_truthy
end
end
end
diff --git a/spec/controllers/users/registrations_controller_spec.rb b/spec/controllers/users/registrations_controller_spec.rb
index 36d26d9de..8fe725f9f 100644
--- a/spec/controllers/users/registrations_controller_spec.rb
+++ b/spec/controllers/users/registrations_controller_spec.rb
@@ -15,8 +15,9 @@ describe Users::RegistrationsController, type: :controller do
context 'when user is correct' do
it 'sends confirmation instruction' do
- expect(DeviseUserMailer).to receive(:confirmation_instructions).and_return(DeviseUserMailer)
- expect(DeviseUserMailer).to receive(:deliver)
+ message = double()
+ expect(DeviseUserMailer).to receive(:confirmation_instructions).and_return(message)
+ expect(message).to receive(:deliver_later)
subject
end
diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb
index c0b08421a..68a8a5f86 100644
--- a/spec/controllers/users/sessions_controller_spec.rb
+++ b/spec/controllers/users/sessions_controller_spec.rb
@@ -199,7 +199,7 @@ describe Users::SessionsController, type: :controller do
end
context 'when procedure is not published' do
- let(:procedure) { create :procedure, published_at: nil }
+ let(:procedure) { create :procedure }
before do
session["user_return_to"] = "?procedure_id=#{procedure.id}"
end
@@ -209,7 +209,7 @@ describe Users::SessionsController, type: :controller do
end
context 'when procedure_id exist' do
- let(:procedure) { create :procedure, published_at: Time.now }
+ let(:procedure) { create :procedure, :published }
before do
session["user_return_to"] = "?procedure_id=#{procedure.id}"
diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb
index e2a73254b..a491b48b8 100644
--- a/spec/factories/dossier.rb
+++ b/spec/factories/dossier.rb
@@ -14,8 +14,6 @@ FactoryBot.define do
trait :with_entreprise do
after(:build) do |dossier, _evaluator|
etablissement = create(:etablissement)
- entreprise = create(:entreprise, etablissement: etablissement)
- dossier.entreprise = entreprise
dossier.etablissement = etablissement
end
end
diff --git a/spec/factories/entreprise.rb b/spec/factories/entreprise.rb
deleted file mode 100644
index 9598017da..000000000
--- a/spec/factories/entreprise.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-FactoryBot.define do
- factory :entreprise do
- siren '440117620'
- capital_social 537_100_000
- numero_tva_intracommunautaire 'FR27440117620'
- forme_juridique 'SA à conseil d\'administration (s.a.i.)'
- forme_juridique_code '5599'
- nom_commercial 'GRTGAZ'
- raison_sociale 'GRTGAZ'
- siret_siege_social '44011762001530'
- code_effectif_entreprise '51'
- date_creation Time.at(1453976189).to_datetime
- end
-end
diff --git a/spec/factories/rna_information.rb b/spec/factories/rna_information.rb
deleted file mode 100644
index bba5d5371..000000000
--- a/spec/factories/rna_information.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-FactoryBot.define do
- factory :rna_information do
- association_id "W072000535"
- titre "ASSOCIATION POUR LA PROMOTION DE SPECTACLES AU CHATEAU DE ROCHEMAURE"
- objet "mise en oeuvre et réalisation de spectacles au chateau de rochemaure"
- date_creation "1990-04-24"
- date_declaration "2014-11-28"
- date_publication "1990-05-16"
- association :entreprise, factory: [:entreprise]
- end
-end
diff --git a/spec/features/new_gestionnaire/gestionnaire_spec.rb b/spec/features/new_gestionnaire/gestionnaire_spec.rb
index c67cbe71f..5c7617d17 100644
--- a/spec/features/new_gestionnaire/gestionnaire_spec.rb
+++ b/spec/features/new_gestionnaire/gestionnaire_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
feature 'The gestionnaire part' do
+ include ActiveJob::TestHelper
+
let(:password) { 'secret_password' }
let!(:gestionnaire) { create(:gestionnaire, password: password) }
@@ -56,6 +58,7 @@ feature 'The gestionnaire part' do
scenario 'A gestionnaire can use avis' do
ActionMailer::Base.deliveries = []
+ ActiveJob::Base.queue_adapter = :test
log_in(gestionnaire.email, password)
@@ -66,7 +69,10 @@ feature 'The gestionnaire part' do
expect(page).to have_current_path(avis_gestionnaire_dossier_path(procedure, dossier))
expert_email = 'expert@tps.com'
- ask_confidential_avis(expert_email, 'a good introduction')
+
+ perform_enqueued_jobs do
+ ask_confidential_avis(expert_email, 'a good introduction')
+ end
log_out
diff --git a/spec/decorators/entreprise_decorator_spec.rb b/spec/helpers/etablissement_helper_spec.rb
similarity index 61%
rename from spec/decorators/entreprise_decorator_spec.rb
rename to spec/helpers/etablissement_helper_spec.rb
index 90076d179..3936f7d16 100644
--- a/spec/decorators/entreprise_decorator_spec.rb
+++ b/spec/helpers/etablissement_helper_spec.rb
@@ -1,29 +1,29 @@
-require 'spec_helper'
-
-describe EntrepriseDecorator do
+RSpec.describe EtablissementHelper, type: :helper do
let(:code_effectif) { '00' }
let(:raison_sociale) { 'GRTGaz' }
let(:nom) { 'mon nom' }
let(:prenom) { 'mon prenom' }
let(:entreprise_params) do
{
- capital_social: 123_000,
- code_effectif_entreprise: code_effectif,
- raison_sociale: raison_sociale,
- nom: nom,
- prenom: prenom
+ entreprise_capital_social: 123_000,
+ entreprise_code_effectif_entreprise: code_effectif,
+ entreprise_raison_sociale: raison_sociale,
+ entreprise_nom: nom,
+ entreprise_prenom: prenom
}
end
- let(:entreprise) { create(:entreprise, entreprise_params) }
- subject { entreprise.decorate }
+ let(:etablissement) { create(:etablissement, entreprise_params) }
+
describe '#raison_sociale_or_name' do
- subject { super().raison_sociale_or_name }
+ subject { raison_sociale_or_name(etablissement) }
+
context 'when raison_sociale exist' do
let(:raison_sociale) { 'ma super raison_sociale' }
it 'display raison_sociale' do
expect(subject).to eq(raison_sociale)
end
end
+
context 'when raison_sociale is nil' do
let(:raison_sociale) { nil }
it 'display nom and prenom' do
@@ -33,20 +33,22 @@ describe EntrepriseDecorator do
end
describe '#effectif' do
- subject { super().effectif }
+ subject { effectif(etablissement) }
+
context 'when code_effectif is 00' do
let(:code_effectif) { '01' }
it { is_expected.to eq('1 ou 2 salariés') }
end
+
context 'when code_effectif is 32' do
let(:code_effectif) { '32' }
it { is_expected.to eq('250 à 499 salariés') }
end
end
- describe '#pretty_capital_social' do
- it 'pretty display capital_social' do
- expect(subject.pretty_capital_social).to eq('123 000,00 €')
- end
+ describe '#pretty_currency' do
+ subject { pretty_currency(etablissement.entreprise_capital_social) }
+
+ it { is_expected.to eq('123 000,00 €') }
end
end
diff --git a/spec/helpers/champ_helper_spec.rb b/spec/helpers/string_to_html_helper_spec.rb
similarity index 81%
rename from spec/helpers/champ_helper_spec.rb
rename to spec/helpers/string_to_html_helper_spec.rb
index 581e1be2c..c597fb8f5 100644
--- a/spec/helpers/champ_helper_spec.rb
+++ b/spec/helpers/string_to_html_helper_spec.rb
@@ -1,6 +1,6 @@
-RSpec.describe ChampHelper, type: :helper do
- describe "#html_formatted_description" do
- subject { html_formatted_description(description) }
+RSpec.describe StringToHtmlHelper, type: :helper do
+ describe "#string_to_html" do
+ subject { string_to_html(description) }
context "with some simple texte" do
let(:description) { "1er ligne \n 2ieme ligne" }
diff --git a/spec/jobs/find_dubious_procedures_job_spec.rb b/spec/jobs/find_dubious_procedures_job_spec.rb
index 8303b9d39..2c1fb450a 100644
--- a/spec/jobs/find_dubious_procedures_job_spec.rb
+++ b/spec/jobs/find_dubious_procedures_job_spec.rb
@@ -2,7 +2,7 @@ require 'rails_helper'
RSpec.describe FindDubiousProceduresJob, type: :job do
describe 'perform' do
- let(:mailer_double) { double('mailer', deliver_now: true) }
+ let(:mailer_double) { double('mailer', deliver_later: true) }
let(:procedure) { create(:procedure) }
let(:allowed_tdc) { create(:type_de_champ, libelle: 'fournir') }
diff --git a/spec/lib/api_entreprise/entreprise_adapter_spec.rb b/spec/lib/api_entreprise/entreprise_adapter_spec.rb
index f9eaf62eb..52b70e490 100644
--- a/spec/lib/api_entreprise/entreprise_adapter_spec.rb
+++ b/spec/lib/api_entreprise/entreprise_adapter_spec.rb
@@ -17,51 +17,51 @@ describe ApiEntreprise::EntrepriseAdapter do
context 'Attributs Entreprises' do
it 'L\'entreprise contient bien un siren' do
- expect(subject[:siren]).to eq(siren)
+ expect(subject[:entreprise_siren]).to eq(siren)
end
it 'L\'entreprise contient bien un capital_social' do
- expect(subject[:capital_social]).to eq(462308)
+ expect(subject[:entreprise_capital_social]).to eq(462308)
end
it 'L\'entreprise contient bien un numero_tva_intracommunautaire' do
- expect(subject[:numero_tva_intracommunautaire]).to eq('FR16418166096')
+ expect(subject[:entreprise_numero_tva_intracommunautaire]).to eq('FR16418166096')
end
it 'L\'entreprise contient bien une forme_juridique' do
- expect(subject[:forme_juridique]).to eq('SA à directoire (s.a.i.)')
+ expect(subject[:entreprise_forme_juridique]).to eq('SA à directoire (s.a.i.)')
end
it 'L\'entreprise contient bien un forme_juridique_code' do
- expect(subject[:forme_juridique_code]).to eq('5699')
+ expect(subject[:entreprise_forme_juridique_code]).to eq('5699')
end
it 'L\'entreprise contient bien un nom_commercial' do
- expect(subject[:nom_commercial]).to eq('OCTO-TECHNOLOGY')
+ expect(subject[:entreprise_nom_commercial]).to eq('OCTO-TECHNOLOGY')
end
it 'L\'entreprise contient bien une raison_sociale' do
- expect(subject[:raison_sociale]).to eq('OCTO-TECHNOLOGY')
+ expect(subject[:entreprise_raison_sociale]).to eq('OCTO-TECHNOLOGY')
end
it 'L\'entreprise contient bien un siret_siege_social' do
- expect(subject[:siret_siege_social]).to eq('41816609600051')
+ expect(subject[:entreprise_siret_siege_social]).to eq('41816609600051')
end
it 'L\'entreprise contient bien un code_effectif_entreprise' do
- expect(subject[:code_effectif_entreprise]).to eq('31')
+ expect(subject[:entreprise_code_effectif_entreprise]).to eq('31')
end
it 'L\'entreprise contient bien une date_creation' do
- expect(subject[:date_creation]).to eq('Wed, 01 Apr 1998 00:00:00.000000000 +0200')
+ expect(subject[:entreprise_date_creation]).to eq('Wed, 01 Apr 1998 00:00:00.000000000 +0200')
end
it 'L\'entreprise contient bien un nom' do
- expect(subject[:nom]).to eq('test_nom')
+ expect(subject[:entreprise_nom]).to eq('test_nom')
end
it 'L\'entreprise contient bien un prenom' do
- expect(subject[:prenom]).to eq('test_prenom')
+ expect(subject[:entreprise_prenom]).to eq('test_prenom')
end
end
end
diff --git a/spec/lib/api_entreprise/rna_adapter_spec.rb b/spec/lib/api_entreprise/rna_adapter_spec.rb
index 2df856cbe..b567c47ec 100644
--- a/spec/lib/api_entreprise/rna_adapter_spec.rb
+++ b/spec/lib/api_entreprise/rna_adapter_spec.rb
@@ -25,16 +25,16 @@ describe ApiEntreprise::RNAAdapter do
it { expect(subject).to be_an_instance_of(Hash) }
describe 'Attributs Associations' do
- it { expect(subject[:rna]).to eq('W595001988') }
+ it { expect(subject[:association_rna]).to eq('W595001988') }
- it { expect(subject[:titre]).to eq('UN SUR QUATRE') }
+ it { expect(subject[:association_titre]).to eq('UN SUR QUATRE') }
- it { expect(subject[:objet]).to eq("valoriser, transmettre et partager auprès des publics les plus larges possibles, les bienfaits de l'immigration, la richesse de la diversité et la curiosité de l'autre autrement") }
+ it { expect(subject[:association_objet]).to eq("valoriser, transmettre et partager auprès des publics les plus larges possibles, les bienfaits de l'immigration, la richesse de la diversité et la curiosité de l'autre autrement") }
- it { expect(subject[:date_creation]).to eq('2014-01-23') }
+ it { expect(subject[:association_date_creation]).to eq('2014-01-23') }
- it { expect(subject[:date_declaration]).to eq('2014-01-24') }
+ it { expect(subject[:association_date_declaration]).to eq('2014-01-24') }
- it { expect(subject[:date_publication]).to eq('2014-02-08') }
+ it { expect(subject[:association_date_publication]).to eq('2014-02-08') }
end
end
diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb
index d6d1dd1dd..d60fb10a3 100644
--- a/spec/mailers/notification_mailer_spec.rb
+++ b/spec/mailers/notification_mailer_spec.rb
@@ -18,7 +18,19 @@ RSpec.describe NotificationMailer, type: :mailer do
describe '.send_notification' do
let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') }
- subject { described_class.send_notification(dossier, email_template) }
+ subject do
+ klass = Class.new(described_class) do
+ # We’re testing the (private) method `NotificationMailer#send_notification`.
+ #
+ # The standard trick to test a private method would be to `send(:send_notification`, but doesn’t work here,
+ # because ActionMailer does some magic to expose public instace methods as class methods.
+ # So, we use inheritance instead to make the private method public for testing purposes.
+ def send_notification(dossier, template)
+ super
+ end
+ end
+ klass.send_notification(dossier, email_template)
+ end
it { expect(subject.subject).to eq(email_template.subject_for_dossier) }
it { expect(subject.body).to eq(email_template.body_for_dossier) }
diff --git a/spec/mailers/previews/notification_mailer_preview.rb b/spec/mailers/previews/notification_mailer_preview.rb
index 6fdcc4174..a5349a255 100644
--- a/spec/mailers/previews/notification_mailer_preview.rb
+++ b/spec/mailers/previews/notification_mailer_preview.rb
@@ -1,6 +1,6 @@
class NotificationMailerPreview < ActionMailer::Preview
def send_notification
- NotificationMailer.send_notification(Dossier.last, Dossier.last.procedure.initiated_mail_template)
+ NotificationMailer.send_initiated_notification(Dossier.last)
end
def send_draft_notification
diff --git a/spec/models/attestation_template_spec.rb b/spec/models/attestation_template_spec.rb
index 1cd889aa5..0a0ff4dcc 100644
--- a/spec/models/attestation_template_spec.rb
+++ b/spec/models/attestation_template_spec.rb
@@ -98,11 +98,10 @@ describe AttestationTemplate, type: :model do
end
let(:for_individual) { false }
let(:individual) { nil }
- let(:etablissement) { nil }
- let(:entreprise) { create(:entreprise, etablissement: etablissement) }
+ let(:etablissement) { create(:etablissement) }
let(:types_de_champ) { [] }
let(:types_de_champ_private) { [] }
- let!(:dossier) { create(:dossier, procedure: procedure, individual: individual, entreprise: entreprise) }
+ let!(:dossier) { create(:dossier, procedure: procedure, individual: individual, etablissement: etablissement) }
let(:template_title) { 'title' }
let(:template_body) { 'body' }
let(:attestation_template) do
diff --git a/spec/models/avis_spec.rb b/spec/models/avis_spec.rb
index 2975e0d5d..c692f0d60 100644
--- a/spec/models/avis_spec.rb
+++ b/spec/models/avis_spec.rb
@@ -90,7 +90,7 @@ RSpec.describe Avis, type: :model do
describe '#notify_gestionnaire' do
context 'when an avis is created' do
before do
- avis_invitation_double = double('avis_invitation', deliver_now: true)
+ avis_invitation_double = double('avis_invitation', deliver_later: true)
allow(AvisMailer).to receive(:avis_invitation).and_return(avis_invitation_double)
Avis.create(claimant: claimant, email: 'email@l.com')
end
diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb
index 5825c7c98..cd62db3ac 100644
--- a/spec/models/concern/tags_substitution_concern_spec.rb
+++ b/spec/models/concern/tags_substitution_concern_spec.rb
@@ -30,9 +30,8 @@ describe TagsSubstitutionConcern, type: :model do
describe 'replace_tags' do
let(:individual) { nil }
- let(:etablissement) { nil }
- let(:entreprise) { create(:entreprise, etablissement: etablissement) }
- let!(:dossier) { create(:dossier, procedure: procedure, individual: individual, entreprise: entreprise) }
+ let(:etablissement) { create(:etablissement) }
+ let!(:dossier) { create(:dossier, procedure: procedure, individual: individual, etablissement: etablissement) }
before { Timecop.freeze(Time.now) }
@@ -61,7 +60,7 @@ describe TagsSubstitutionConcern, type: :model do
let(:etablissement) { create(:etablissement) }
let(:expected_text) do
- "#{entreprise.siren} #{entreprise.numero_tva_intracommunautaire} #{entreprise.siret_siege_social} #{entreprise.raison_sociale} #{etablissement.inline_adresse}"
+ "#{etablissement.entreprise_siren} #{etablissement.entreprise_numero_tva_intracommunautaire} #{etablissement.entreprise_siret_siege_social} #{etablissement.entreprise_raison_sociale} #{etablissement.inline_adresse}"
end
it { is_expected.to eq(expected_text) }
diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb
index c6471c5e8..09501c4d8 100644
--- a/spec/models/dossier_spec.rb
+++ b/spec/models/dossier_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe Dossier do
+ include ActiveJob::TestHelper
+
let(:user) { create(:user) }
describe "without_followers scope" do
@@ -27,8 +29,6 @@ describe Dossier do
describe 'methods' do
let(:dossier) { create(:dossier, :with_entreprise, user: user) }
-
- let(:entreprise) { dossier.entreprise }
let(:etablissement) { dossier.etablissement }
subject { dossier }
@@ -200,7 +200,7 @@ describe Dossier do
it { expect(subject[:entreprise_raison_sociale]).to eq('GRTGAZ') }
it { expect(subject[:entreprise_siret_siege_social]).to eq('44011762001530') }
it { expect(subject[:entreprise_code_effectif_entreprise]).to eq('51') }
- it { expect(subject[:entreprise_date_creation]).to eq('Thu, 28 Jan 2016 10:16:29 UTC +00:0') }
+ it { expect(subject[:entreprise_date_creation]).to eq('1990-04-24T00:00:00+00:00') }
it { expect(subject[:entreprise_nom]).to be_nil }
it { expect(subject[:entreprise_prenom]).to be_nil }
@@ -311,7 +311,7 @@ describe Dossier do
"GRTGAZ",
"44011762001530",
"51",
- dossier.entreprise.date_creation,
+ "1990-04-24T00:00:00+00:00",
nil,
nil
]
@@ -325,22 +325,16 @@ describe Dossier do
describe '#reset!' do
let!(:dossier) { create :dossier, :with_entreprise, autorisation_donnees: true }
- let!(:rna_information) { create :rna_information, entreprise: dossier.entreprise }
let!(:exercice) { create :exercice, etablissement: dossier.etablissement }
subject { dossier.reset! }
- it { expect(dossier.entreprise).not_to be_nil }
it { expect(dossier.etablissement).not_to be_nil }
it { expect(dossier.etablissement.exercices).not_to be_empty }
it { expect(dossier.etablissement.exercices.size).to eq 1 }
- it { expect(dossier.entreprise.rna_information).not_to be_nil }
it { expect(dossier.autorisation_donnees).to be_truthy }
- it { expect { subject }.to change(RNAInformation, :count).by(-1) }
it { expect { subject }.to change(Exercice, :count).by(-1) }
-
- it { expect { subject }.to change(Entreprise, :count).by(-1) }
it { expect { subject }.to change(Etablissement, :count).by(-1) }
context 'when method reset! is call' do
@@ -349,7 +343,6 @@ describe Dossier do
dossier.reload
end
- it { expect(dossier.entreprise).to be_nil }
it { expect(dossier.etablissement).to be_nil }
it { expect(dossier.autorisation_donnees).to be_falsey }
end
@@ -628,7 +621,12 @@ describe Dossier do
end
it "send an email when the dossier is created for the very first time" do
- expect { Dossier.create(procedure: procedure, state: "brouillon", user: user) }.to change(ActionMailer::Base.deliveries, :size).from(0).to(1)
+ ActiveJob::Base.queue_adapter = :test
+ expect do
+ perform_enqueued_jobs do
+ Dossier.create(procedure: procedure, state: "brouillon", user: user)
+ end
+ end.to change(ActionMailer::Base.deliveries, :size).from(0).to(1)
mail = ActionMailer::Base.deliveries.last
expect(mail.subject).to eq("Retrouvez votre brouillon pour la démarche : #{procedure.libelle}")
@@ -766,7 +764,7 @@ describe Dossier do
it { expect(dossier.get_value('self', 'created_at')).to eq(dossier.created_at) }
it { expect(dossier.get_value('user', 'email')).to eq(user.email) }
it { expect(dossier.get_value('france_connect_information', 'gender')).to eq(user.france_connect_information.gender) }
- it { expect(dossier.get_value('entreprise', 'siren')).to eq(dossier.entreprise.siren) }
+ it { expect(dossier.get_value('entreprise', 'siren')).to eq(dossier.etablissement.entreprise_siren) }
it { expect(dossier.get_value('etablissement', 'siret')).to eq(dossier.etablissement.siret) }
it { expect(dossier.get_value('type_de_champ', @champ_public.type_de_champ.id.to_s)).to eq(dossier.champs.first.value) }
it { expect(dossier.get_value('type_de_champ_private', @champ_private.type_de_champ.id.to_s)).to eq(dossier.champs_private.first.value) }
@@ -834,7 +832,7 @@ describe Dossier do
subject { dossier.owner_name }
context 'when there is no entreprise or individual' do
- let(:dossier) { create(:dossier, individual: nil, entreprise: nil, procedure: procedure) }
+ let(:dossier) { create(:dossier, individual: nil, procedure: procedure) }
it { is_expected.to be_nil }
end
@@ -842,7 +840,7 @@ describe Dossier do
context 'when there is entreprise' do
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) }
- it { is_expected.to eq(dossier.entreprise.raison_sociale) }
+ it { is_expected.to eq(dossier.etablissement.entreprise_raison_sociale) }
end
context 'when there is an individual' do
diff --git a/spec/models/entreprise_spec.rb b/spec/models/entreprise_spec.rb
deleted file mode 100644
index 0a901fb3e..000000000
--- a/spec/models/entreprise_spec.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'spec_helper'
-
-describe Entreprise do
-end
diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb
index 5ed0b43ce..1ea1f2af5 100644
--- a/spec/models/gestionnaire_spec.rb
+++ b/spec/models/gestionnaire_spec.rb
@@ -145,14 +145,14 @@ describe Gestionnaire, type: :model do
after { Timecop.return }
context 'when no procedure published was active last week' do
- let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published_at: Time.now) }
+ let!(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire2], libelle: 'procedure') }
context 'when the gestionnaire has no notifications' do
it { is_expected.to eq(nil) }
end
end
context 'when a procedure published was active' do
- let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published_at: Time.now) }
+ let!(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire2], libelle: 'procedure') }
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
before :each do
@@ -163,7 +163,7 @@ describe Gestionnaire, type: :model do
end
context 'when a procedure not published was active with no notifications' do
- let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published_at: nil) }
+ let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure') }
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
before :each do
diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb
index bb861cacb..15efdf5e2 100644
--- a/spec/models/procedure_spec.rb
+++ b/spec/models/procedure_spec.rb
@@ -229,39 +229,27 @@ describe Procedure do
end
describe 'active' do
- let(:procedure) { create(:procedure, published_at: published_at, archived_at: archived_at) }
+ let(:procedure) { create(:procedure) }
subject { Procedure.active(procedure.id) }
context 'when procedure is in draft status and not archived' do
- let(:published_at) { nil }
- let(:archived_at) { nil }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end
context 'when procedure is published and not archived' do
- let(:published_at) { Time.now }
- let(:archived_at) { nil }
+ let(:procedure) { create(:procedure, :published) }
it { is_expected.to be_truthy }
end
context 'when procedure is published and archived' do
- let(:published_at) { Time.now }
- let(:archived_at) { Time.now }
- it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
- end
-
- context 'when procedure is in draft status and archived' do
- let(:published_at) { nil }
- let(:archived_at) { Time.now }
+ let(:procedure) { create(:procedure, :archived) }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end
end
describe 'clone' do
- let(:archived_at) { nil }
- let(:published_at) { nil }
let!(:service) { create(:service) }
- let(:procedure) { create(:procedure, archived_at: archived_at, published_at: published_at, received_mail: received_mail, service: service) }
+ let(:procedure) { create(:procedure, received_mail: received_mail, service: service) }
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
let!(:type_de_champ_2) { create(:type_de_champ_drop_down_list, procedure: procedure, order_place: 2) }
@@ -350,11 +338,13 @@ describe Procedure do
end
describe 'procedure status is reset' do
- let(:archived_at) { Time.now }
- let(:published_at) { Time.now }
+ let(:procedure) { create(:procedure, :archived, received_mail: received_mail, service: service) }
+
it 'Not published nor archived' do
expect(subject.archived_at).to be_nil
expect(subject.published_at).to be_nil
+ expect(subject.test_started_at).to be_nil
+ expect(subject.aasm_state).to eq "brouillon"
expect(subject.path).to be_nil
end
end
@@ -569,12 +559,12 @@ describe Procedure do
{ "label" => 'Civilité (FC)', "table" => 'france_connect_information', "column" => 'gender' },
{ "label" => 'Prénom (FC)', "table" => 'france_connect_information', "column" => 'given_name' },
{ "label" => 'Nom (FC)', "table" => 'france_connect_information', "column" => 'family_name' },
- { "label" => 'SIREN', "table" => 'entreprise', "column" => 'siren' },
- { "label" => 'Forme juridique', "table" => 'entreprise', "column" => 'forme_juridique' },
- { "label" => 'Nom commercial', "table" => 'entreprise', "column" => 'nom_commercial' },
- { "label" => 'Raison sociale', "table" => 'entreprise', "column" => 'raison_sociale' },
- { "label" => 'SIRET siège social', "table" => 'entreprise', "column" => 'siret_siege_social' },
- { "label" => 'Date de création', "table" => 'entreprise', "column" => 'date_creation' },
+ { "label" => 'SIREN', "table" => 'etablissement', "column" => 'entreprise_siren' },
+ { "label" => 'Forme juridique', "table" => 'etablissement', "column" => 'entreprise_forme_juridique' },
+ { "label" => 'Nom commercial', "table" => 'etablissement', "column" => 'entreprise_nom_commercial' },
+ { "label" => 'Raison sociale', "table" => 'etablissement', "column" => 'entreprise_raison_sociale' },
+ { "label" => 'SIRET siège social', "table" => 'etablissement', "column" => 'entreprise_siret_siege_social' },
+ { "label" => 'Date de création', "table" => 'etablissement', "column" => 'entreprise_date_creation' },
{ "label" => 'SIRET', "table" => 'etablissement', "column" => 'siret' },
{ "label" => 'Libellé NAF', "table" => 'etablissement', "column" => 'libelle_naf' },
{ "label" => 'Code postal', "table" => 'etablissement', "column" => 'code_postal' },
diff --git a/spec/models/rna_information_spec.rb b/spec/models/rna_information_spec.rb
deleted file mode 100644
index 89537c245..000000000
--- a/spec/models/rna_information_spec.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'spec_helper'
-
-describe RNAInformation do
-end
diff --git a/spec/models/search_spec.rb b/spec/models/search_spec.rb
index 047af5819..93365ae3e 100644
--- a/spec/models/search_spec.rb
+++ b/spec/models/search_spec.rb
@@ -28,9 +28,9 @@ describe Search do
let!(:dossier_3) { create(:dossier, state: 'en_construction', procedure: procedure_2, user: create(:user, email: 'peace@clap.fr')) }
let!(:dossier_archived) { create(:dossier, state: 'en_construction', procedure: procedure_1, archived: true, user: create(:user, email: 'brouillonArchived@clap.fr')) }
- let!(:etablissement_1) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Academy', dossier: dossier_1), dossier: dossier_1, siret: '41636169600051') }
- let!(:etablissement_2) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'Plop octo', dossier: dossier_2), dossier: dossier_2, siret: '41816602300012') }
- let!(:etablissement_3) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Technology', dossier: dossier_3), dossier: dossier_3, siret: '41816609600051') }
+ let!(:etablissement_1) { create(:etablissement, entreprise_raison_sociale: 'OCTO Academy', dossier: dossier_1, siret: '41636169600051') }
+ let!(:etablissement_2) { create(:etablissement, entreprise_raison_sociale: 'Plop octo', dossier: dossier_2, siret: '41816602300012') }
+ let!(:etablissement_3) { create(:etablissement, entreprise_raison_sociale: 'OCTO Technology', dossier: dossier_3, siret: '41816609600051') }
describe 'search is empty' do
let(:terms) { '' }
diff --git a/spec/views/new_gestionnaire/dossiers/show.html.haml_spec.rb b/spec/views/new_gestionnaire/dossiers/show.html.haml_spec.rb
index 4ea0f1caa..2f230fd11 100644
--- a/spec/views/new_gestionnaire/dossiers/show.html.haml_spec.rb
+++ b/spec/views/new_gestionnaire/dossiers/show.html.haml_spec.rb
@@ -15,7 +15,7 @@ describe 'new_gestionnaire/dossiers/show.html.haml', type: :view do
context "when dossier was created by an etablissement" do
let(:etablissement) { create(:etablissement) }
- it { expect(rendered).to include(etablissement.entreprise_raison_sociale_or_name) }
+ it { expect(rendered).to include(etablissement.entreprise_raison_sociale) }
it { expect(rendered).to include(etablissement.entreprise_siret_siege_social) }
it { expect(rendered).to include(etablissement.entreprise_forme_juridique) }