Merge remote-tracking branch 'upstream/dev'

This commit is contained in:
Paul Chavard 2018-05-28 15:22:30 +02:00
commit 4eabfde56d
85 changed files with 425 additions and 421 deletions

View file

@ -1,11 +1,11 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'rails', '~> 5.2.0' gem 'rails'
# Use SCSS for stylesheets # Use SCSS for stylesheets
gem 'sass-rails' gem 'sass-rails'
# Use Uglifier as compressor for JavaScript assets # 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 # See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby gem 'therubyracer', platforms: :ruby
@ -42,6 +42,7 @@ gem 'unicode_utils'
# Gestion des comptes utilisateurs # Gestion des comptes utilisateurs
gem 'devise' gem 'devise'
gem 'devise-async'
gem 'openid_connect' gem 'openid_connect'
gem 'omniauth-github' gem 'omniauth-github'
@ -133,7 +134,7 @@ group :test do
gem 'timecop' gem 'timecop'
gem 'guard' gem 'guard'
gem 'guard-rspec', require: false gem 'guard-rspec', require: false
gem 'guard-livereload', '~> 2.4', require: false gem 'guard-livereload', require: false
gem 'vcr' gem 'vcr'
gem 'rails-controller-testing' gem 'rails-controller-testing'
end end

View file

@ -175,6 +175,9 @@ GEM
railties (>= 4.1.0, < 6.0) railties (>= 4.1.0, < 6.0)
responders responders
warden (~> 1.2.3) warden (~> 1.2.3)
devise-async (1.0.0)
activejob (>= 5.0)
devise (>= 4.0)
diff-lcs (1.3) diff-lcs (1.3)
domain_name (0.5.20170404) domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
@ -195,7 +198,7 @@ GEM
erubis (2.7.0) erubis (2.7.0)
ethon (0.11.0) ethon (0.11.0)
ffi (>= 1.3.0) ffi (>= 1.3.0)
eventmachine (1.2.5) eventmachine (1.2.7)
excon (0.60.0) excon (0.60.0)
execjs (2.7.0) execjs (2.7.0)
factory_bot (4.8.2) factory_bot (4.8.2)
@ -458,7 +461,7 @@ GEM
loofah (2.2.2) loofah (2.2.2)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
lumberjack (1.0.12) lumberjack (1.0.13)
mail (2.7.0) mail (2.7.0)
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
mailjet (1.5.4) mailjet (1.5.4)
@ -803,6 +806,7 @@ DEPENDENCIES
delayed_job_active_record delayed_job_active_record
delayed_job_web! delayed_job_web!
devise devise
devise-async
dotenv-rails dotenv-rails
draper draper
factory_bot factory_bot
@ -811,7 +815,7 @@ DEPENDENCIES
fog-openstack fog-openstack
font-awesome-rails font-awesome-rails
guard guard
guard-livereload (~> 2.4) guard-livereload
guard-rspec guard-rspec
haml-lint haml-lint
haml-rails haml-rails
@ -835,7 +839,7 @@ DEPENDENCIES
pry-byebug pry-byebug
rack-handlers rack-handlers
rack-mini-profiler rack-mini-profiler
rails (~> 5.2.0) rails
rails-controller-testing rails-controller-testing
rbnacl-libsodium rbnacl-libsodium
rest-client rest-client
@ -861,7 +865,7 @@ DEPENDENCIES
timecop timecop
turbolinks turbolinks
typhoeus typhoeus
uglifier (>= 1.3.0) uglifier
unicode_utils unicode_utils
unicorn unicorn
vcr vcr

View file

@ -50,7 +50,7 @@ class Admin::GestionnairesController < AdminController
@gestionnaire.invite! @gestionnaire.invite!
if User.exists?(email: @gestionnaire.email) if User.exists?(email: @gestionnaire.email)
GestionnaireMailer.user_to_gestionnaire(@gestionnaire.email).deliver_now! GestionnaireMailer.user_to_gestionnaire(@gestionnaire.email).deliver_later
else else
User.create(email: email, password: password) User.create(email: email, password: password)
end end

View file

@ -13,9 +13,9 @@ class InvitesController < ApplicationController
if invite.valid? if invite.valid?
if invite.user.present? if invite.user.present?
InviteMailer.invite_user(invite).deliver_now! InviteMailer.invite_user(invite).deliver_later
else else
InviteMailer.invite_guest(invite).deliver_now! InviteMailer.invite_guest(invite).deliver_later
end end
flash.notice = "Invitation envoyée (#{invite.email})" flash.notice = "Invitation envoyée (#{invite.email})"

View file

@ -91,24 +91,21 @@ module NewGestionnaire
case params[:process_action] case params[:process_action]
when "refuser" when "refuser"
dossier.refuse! dossier.refuse!
notice = "Dossier considéré comme refusé." dossier.save
template = procedure.refused_mail_template flash.notice = "Dossier considéré comme refusé."
NotificationMailer.send_refused_notification(dossier).deliver_later
when "classer_sans_suite" when "classer_sans_suite"
dossier.sans_suite! dossier.sans_suite!
notice = "Dossier considéré comme sans suite." dossier.save
template = procedure.without_continuation_mail_template flash.notice = "Dossier considéré comme sans suite."
NotificationMailer.send_without_continuation_notification(dossier).deliver_later
when "accepter" when "accepter"
dossier.accepte! dossier.accepte!
dossier.attestation = dossier.build_attestation dossier.attestation = dossier.build_attestation
notice = "Dossier traité avec succès."
template = procedure.closed_mail_template
end
dossier.save dossier.save
flash.notice = "Dossier traité avec succès."
flash.notice = notice NotificationMailer.send_closed_notification(dossier).deliver_later
end
NotificationMailer.send_notification(dossier, template).deliver_now!
redirect_to gestionnaire_dossier_path(procedure, dossier) redirect_to gestionnaire_dossier_path(procedure, dossier)
end end

View file

@ -234,18 +234,22 @@ module NewGestionnaire
.includes(relation) .includes(relation)
.where("champs.type_de_champ_id = ?", filter['column'].to_i) .where("champs.type_de_champ_id = ?", filter['column'].to_i)
.where("champs.value LIKE ?", "%#{filter['value']}%") .where("champs.value LIKE ?", "%#{filter['value']}%")
when 'entreprise'
when 'user', 'etablissement', 'entreprise' table = 'etablissement'
if filter['column'] == 'date_creation' if filter['column'] == 'date_creation'
date = filter['value'].to_date rescue nil date = filter['value'].to_date rescue nil
dossiers dossiers
.includes(filter['table']) .includes(table)
.where("#{filter['table'].pluralize}.#{filter['column']} = ?", date) .where("#{table.pluralize}.entreprise_#{filter['column']} = ?", date)
else else
dossiers
.includes(table)
.where("#{table.pluralize}.entreprise_#{filter['column']} LIKE ?", "%#{filter['value']}%")
end
when 'user', 'etablissement'
dossiers dossiers
.includes(filter['table']) .includes(filter['table'])
.where("#{filter['table'].pluralize}.#{filter['column']} LIKE ?", "%#{filter['value']}%") .where("#{filter['table'].pluralize}.#{filter['column']} LIKE ?", "%#{filter['value']}%")
end
end.pluck(:id) end.pluck(:id)
end.reduce(:&) end.reduce(:&)
end end

View file

@ -71,7 +71,7 @@ module NewUser
render :modifier render :modifier
elsif @dossier.brouillon? elsif @dossier.brouillon?
@dossier.en_construction! @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) redirect_to merci_dossier_path(@dossier)
elsif owns_dossier? elsif owns_dossier?
redirect_to users_dossier_recapitulatif_path(@dossier) redirect_to users_dossier_recapitulatif_path(@dossier)

View file

@ -55,7 +55,7 @@ class Users::DescriptionController < UsersController
if dossier.brouillon? if dossier.brouillon?
dossier.en_construction! dossier.en_construction!
# TODO move to model # TODO move to model
NotificationMailer.send_notification(dossier, procedure.initiated_mail_template).deliver_now! NotificationMailer.send_initiated_notification(dossier).deliver_later
end end
flash.notice = 'Félicitations, votre demande a bien été enregistrée.' flash.notice = 'Félicitations, votre demande a bien été enregistrée.'
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: dossier.id) redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: dossier.id)
@ -130,7 +130,7 @@ class Users::DescriptionController < UsersController
@dossier ||= current_user_dossier @dossier ||= current_user_dossier
if (@dossier.procedure.for_individual? && @dossier.individual.nil?) || 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)) redirect_to url_for(users_dossier_path(@dossier.id))
end end
end end

View file

@ -112,7 +112,7 @@ class Users::DossiersController < UsersController
update_current_user_siret!(siret) 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? if etablissement_attributes.present?
etablissement_attributes = ActionController::Parameters.new(etablissement_attributes).permit! etablissement_attributes = ActionController::Parameters.new(etablissement_attributes).permit!

View file

@ -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

View file

@ -1,3 +0,0 @@
class EtablissementDecorator < Draper::Decorator
delegate_all
end

View file

@ -13,10 +13,6 @@ class DossierFacades
@dossier.ordered_champs @dossier.ordered_champs
end end
def entreprise
@dossier.entreprise.decorate if @dossier.entreprise.present? && @dossier.entreprise.siren.present?
end
def etablissement def etablissement
@dossier.etablissement @dossier.etablissement
end end

View file

@ -2,10 +2,4 @@ module ChampHelper
def is_not_header_nor_explication?(champ) def is_not_header_nor_explication?(champ)
!['header_section', 'explication'].include?(champ.type_champ) !['header_section', 'explication'].include?(champ.type_champ)
end end
def html_formatted_description(description)
html_formatted = simple_format(description)
with_links = html_formatted.gsub(URI.regexp, '<a target="_blank" href="\0">\0</a>')
sanitize(with_links, attributes: %w(href target))
end
end end

View file

@ -2,4 +2,35 @@ module EtablissementHelper
def pretty_currency(capital_social) def pretty_currency(capital_social)
number_to_currency(capital_social, locale: :fr) number_to_currency(capital_social, locale: :fr)
end 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 end

View file

@ -0,0 +1,7 @@
module StringToHtmlHelper
def string_to_html(str)
html_formatted = simple_format(str)
with_links = html_formatted.gsub(URI.regexp, '<a target="_blank" href="\0">\0</a>')
sanitize(with_links, attributes: %w(href target))
end
end

View file

@ -2,12 +2,9 @@ class EtablissementUpdateJob < ApplicationJob
queue_as :default queue_as :default
def perform(dossier, siret) 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 etablissement_attributes.present?
if dossier.entreprise.present?
dossier.entreprise.destroy
end
if dossier.etablissement.present? if dossier.etablissement.present?
dossier.etablissement.destroy dossier.etablissement.destroy
end end

View file

@ -24,6 +24,6 @@ class FindDubiousProceduresJob < ApplicationJob
.group_by(&:procedure_id) .group_by(&:procedure_id)
.map { |_procedure_id, tdcs| [tdcs[0].procedure, tdcs] } .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
end end

View file

@ -9,7 +9,7 @@ class ApiEntreprise::EntrepriseAdapter < ApiEntreprise::Adapter
def process_params def process_params
params = data_source[:entreprise].slice(*attr_to_fetch) params = data_source[:entreprise].slice(*attr_to_fetch)
params[:date_creation] = Time.at(params[:date_creation]).to_datetime params[:date_creation] = Time.at(params[:date_creation]).to_datetime
params params.transform_keys { |k| :"entreprise_#{k}" }
end end
def attr_to_fetch def attr_to_fetch

View file

@ -9,7 +9,7 @@ class ApiEntreprise::RNAAdapter < ApiEntreprise::Adapter
if data_source[:association][:id].present? if data_source[:association][:id].present?
params = data_source[:association].slice(*attr_to_fetch) params = data_source[:association].slice(*attr_to_fetch)
params[:rna] = data_source[:association][:id] params[:rna] = data_source[:association][:id]
params params.transform_keys { |k| :"association_#{k}" }
else else
{} {}
end end

View file

@ -8,15 +8,6 @@ class NotificationMailer < ApplicationMailer
send_notification(dossier, dossier.procedure.received_mail_template) send_notification(dossier, dossier.procedure.received_mail_template)
end 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) def send_draft_notification(dossier)
vars_mailer(dossier) vars_mailer(dossier)
@ -25,12 +16,41 @@ class NotificationMailer < ApplicationMailer
mail(subject: @subject) mail(subject: @subject)
end 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) def new_answer(dossier)
send_mail dossier, "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}" send_mail dossier, "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}"
end end
private 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 def create_commentaire_for_notification
Commentaire.create( Commentaire.create(
dossier: @dossier, dossier: @dossier,

View file

@ -2,7 +2,7 @@ class Administrateur < ApplicationRecord
include CredentialsSyncableConcern include CredentialsSyncableConcern
include EmailSanitizableConcern include EmailSanitizableConcern
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable, :async,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
has_and_belongs_to_many :gestionnaires has_and_belongs_to_many :gestionnaires
@ -51,7 +51,7 @@ class Administrateur < ApplicationRecord
reset_password_token = set_reset_password_token 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 reset_password_token
end end

View file

@ -1,7 +1,7 @@
class Administration < ApplicationRecord class Administration < ApplicationRecord
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :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) def self.from_omniauth(params)
find_by(email: params["info"]["email"]) find_by(email: params["info"]["email"])
@ -17,7 +17,7 @@ class Administration < ApplicationRecord
}) })
if administrateur.save if administrateur.save
AdministrationMailer.new_admin_email(administrateur, self).deliver_now! AdministrationMailer.new_admin_email(administrateur, self).deliver_later
administrateur.invite! administrateur.invite!
User.create({ User.create({
email: email, email: email,

View file

@ -34,7 +34,7 @@ class Avis < ApplicationRecord
private private
def notify_gestionnaire def notify_gestionnaire
AvisMailer.avis_invitation(self).deliver_now AvisMailer.avis_invitation(self).deliver_later
end end
def try_to_assign_gestionnaire def try_to_assign_gestionnaire

View file

@ -42,7 +42,7 @@ class Commentaire < ApplicationRecord
end end
def notify_user def notify_user
NotificationMailer.new_answer(dossier).deliver_now! NotificationMailer.new_answer(dossier).deliver_later
end end
def is_virus_free? def is_virus_free?

View file

@ -107,7 +107,7 @@ module TagsSubstitutionConcern
{ {
libelle: 'adresse', libelle: 'adresse',
description: '', description: '',
lambda: -> (e) { e&.etablissement&.inline_adresse }, target: :inline_adresse,
available_for_states: Dossier::SOUMIS available_for_states: Dossier::SOUMIS
} }
] ]
@ -187,7 +187,7 @@ module TagsSubstitutionConcern
tags_and_datas = [ tags_and_datas = [
[dossier_tags, dossier], [dossier_tags, dossier],
[INDIVIDUAL_TAGS, dossier.individual], [INDIVIDUAL_TAGS, dossier.individual],
[ENTREPRISE_TAGS, dossier.entreprise] [ENTREPRISE_TAGS, dossier.etablissement&.entreprise]
] ]
tags_and_datas tags_and_datas

View file

@ -14,7 +14,6 @@ class Dossier < ApplicationRecord
SOUMIS = EN_CONSTRUCTION_OU_INSTRUCTION + TERMINE SOUMIS = EN_CONSTRUCTION_OU_INSTRUCTION + TERMINE
has_one :etablissement, dependent: :destroy has_one :etablissement, dependent: :destroy
has_one :entreprise, dependent: :destroy
has_one :individual, dependent: :destroy has_one :individual, dependent: :destroy
has_one :attestation has_one :attestation
has_many :cerfa, dependent: :destroy has_many :cerfa, dependent: :destroy
@ -56,7 +55,7 @@ class Dossier < ApplicationRecord
scope :en_construction, -> { not_archived.state_en_construction } scope :en_construction, -> { not_archived.state_en_construction }
scope :en_instruction, -> { not_archived.state_en_instruction } scope :en_instruction, -> { not_archived.state_en_instruction }
scope :termine, -> { not_archived.state_termine } 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 :en_cours, -> { not_archived.state_en_construction_ou_instruction }
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) } scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
scope :followed_by, -> (gestionnaire) { joins(:follows).where(follows: { gestionnaire: gestionnaire }) } scope :followed_by, -> (gestionnaire) { joins(:follows).where(follows: { gestionnaire: gestionnaire }) }
@ -64,8 +63,7 @@ class Dossier < ApplicationRecord
accepts_nested_attributes_for :individual accepts_nested_attributes_for :individual
delegate :siren, to: :entreprise delegate :siret, :siren, to: :etablissement, allow_nil: true
delegate :siret, to: :etablissement, allow_nil: true
delegate :types_de_piece_justificative, to: :procedure delegate :types_de_piece_justificative, to: :procedure
delegate :types_de_champ, to: :procedure delegate :types_de_champ, to: :procedure
delegate :france_connect_information, to: :user delegate :france_connect_information, to: :user
@ -220,7 +218,7 @@ class Dossier < ApplicationRecord
when 'france_connect_information' when 'france_connect_information'
self.user.france_connect_information&.send(column) self.user.france_connect_information&.send(column)
when 'entreprise' when 'entreprise'
self.entreprise&.send(column) self.etablissement&.send(:"entreprise_#{column}")
when 'etablissement' when 'etablissement'
self.etablissement&.send(column) self.etablissement&.send(column)
when 'type_de_champ' when 'type_de_champ'
@ -235,8 +233,8 @@ class Dossier < ApplicationRecord
end end
def owner_name def owner_name
if entreprise.present? if etablissement.present?
entreprise.raison_sociale etablissement.entreprise_raison_sociale
elsif individual.present? elsif individual.present?
"#{individual.nom} #{individual.prenom}" "#{individual.nom} #{individual.prenom}"
end end
@ -298,8 +296,8 @@ class Dossier < ApplicationRecord
def export_etablissement_data def export_etablissement_data
if etablissement.present? if etablissement.present?
etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.transform_keys { |k| "etablissement.#{k}".parameterize.underscore.to_sym } etablissement_attr = EtablissementCsvSerializer.new(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 } entreprise_attr = EntrepriseSerializer.new(etablissement.entreprise).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym }
else else
etablissement_attr = EtablissementSerializer.new(Etablissement.new).attributes.transform_keys { |k| "etablissement.#{k}".parameterize.underscore.to_sym } 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 } 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 def send_draft_notification_email
if brouillon? if brouillon?
NotificationMailer.send_draft_notification(self).deliver_now! NotificationMailer.send_draft_notification(self).deliver_later
end end
end end

View file

@ -1,16 +1,20 @@
class Entreprise < ApplicationRecord class Entreprise < Hashie::Dash
belongs_to :dossier def read_attribute_for_serialization(attribute)
has_one :etablissement self[attribute]
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 ||= ''
end 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 end

View file

@ -1,18 +1,20 @@
class Etablissement < ApplicationRecord class Etablissement < ApplicationRecord
belongs_to :dossier belongs_to :dossier
belongs_to :entreprise, dependent: :destroy
has_one :champ, class_name: 'Champs::SiretChamp' has_one :champ, class_name: 'Champs::SiretChamp'
has_many :exercices, dependent: :destroy has_many :exercices, dependent: :destroy
accepts_nested_attributes_for :exercices accepts_nested_attributes_for :exercices
accepts_nested_attributes_for :entreprise, update_only: true
validates :siret, presence: true validates :siret, presence: true
validates :dossier_id, uniqueness: { allow_nil: true } validates :dossier_id, uniqueness: { allow_nil: true }
validate :validate_signature validate :validate_signature
def siren
entreprise_siren
end
def geo_adresse def geo_adresse
[numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ') [numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ')
end end
@ -22,10 +24,6 @@ class Etablissement < ApplicationRecord
"#{numero_voie} #{type_voie} #{nom_voie}, #{complement_adresse}, #{code_postal} #{localite}".squeeze(' ') "#{numero_voie} #{type_voie} #{nom_voie}, #{complement_adresse}, #{code_postal} #{localite}".squeeze(' ')
end end
def titre
entreprise_raison_sociale || association_titre
end
def verify def verify
SignatureService.verify(signature, message_for_signature) SignatureService.verify(signature, message_for_signature)
end end
@ -36,29 +34,26 @@ class Etablissement < ApplicationRecord
attr_accessor :signature attr_accessor :signature
def entreprise_raison_sociale_or_name def association?
entreprise_raison_sociale.presence || "#{entreprise_nom} #{entreprise_prenom}" association_rna.present?
end end
def entreprise_effectif def entreprise
{ Entreprise.new(
'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).", siren: entreprise_siren,
'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)", capital_social: entreprise_capital_social,
'01' => '1 ou 2 salariés', numero_tva_intracommunautaire: entreprise_numero_tva_intracommunautaire,
'02' => '3 à 5 salariés', forme_juridique: entreprise_forme_juridique,
'03' => '6 à 9 salariés', forme_juridique_code: entreprise_forme_juridique_code,
'11' => '10 à 19 salariés', nom_commercial: entreprise_nom_commercial,
'12' => '20 à 49 salariés', raison_sociale: entreprise_raison_sociale,
'21' => '50 à 99 salariés', siret_siege_social: entreprise_siret_siege_social,
'22' => '100 à 199 salariés', code_effectif_entreprise: entreprise_code_effectif_entreprise,
'31' => '200 à 249 salariés', date_creation: entreprise_date_creation,
'32' => '250 à 499 salariés', nom: entreprise_nom,
'41' => '500 à 999 salariés', prenom: entreprise_prenom,
'42' => '1 000 à 1 999 salariés', inline_adresse: inline_adresse
'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]
end end
private private

View file

@ -2,8 +2,4 @@ class Exercice < ApplicationRecord
belongs_to :etablissement belongs_to :etablissement
validates :ca, presence: true, allow_blank: false, allow_nil: false validates :ca, presence: true, allow_blank: false, allow_nil: false
def date_fin_exercice
super || dateFinExercice
end
end end

View file

@ -2,7 +2,7 @@ class Gestionnaire < ApplicationRecord
include CredentialsSyncableConcern include CredentialsSyncableConcern
include EmailSanitizableConcern include EmailSanitizableConcern
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable, :async,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
has_and_belongs_to_many :administrateurs has_and_belongs_to_many :administrateurs
@ -147,7 +147,7 @@ class Gestionnaire < ApplicationRecord
def invite! def invite!
reset_password_token = set_reset_password_token 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 end
private private

View file

@ -34,10 +34,10 @@ class Procedure < ApplicationRecord
mount_uploader :logo, ProcedureLogoUploader mount_uploader :logo, ProcedureLogoUploader
default_scope { where(hidden_at: nil) } default_scope { where(hidden_at: nil) }
scope :brouillons, -> { where(published_at: nil).where(archived_at: nil) } scope :brouillons, -> { where(aasm_state: :brouillon) }
scope :publiees, -> { where.not(published_at: nil).where(archived_at: nil) } scope :publiees, -> { where(aasm_state: :publiee) }
scope :archivees, -> { where.not(archived_at: nil) } scope :archivees, -> { where(aasm_state: :archivee) }
scope :publiees_ou_archivees, -> { where.not(published_at: nil) } scope :publiees_ou_archivees, -> { where(aasm_state: [:publiee, :archivee]) }
scope :by_libelle, -> { order(libelle: :asc) } scope :by_libelle, -> { order(libelle: :asc) }
scope :created_during, -> (range) { where(created_at: range) } scope :created_during, -> (range) { where(created_at: range) }
scope :cloned_from_library, -> { where(cloned_from_library: true) } 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: :drop_down_list,
types_de_champ_private: :drop_down_list types_de_champ_private: :drop_down_list
}) })
procedure.aasm_state = :brouillon
procedure.test_started_at = nil
procedure.archived_at = nil procedure.archived_at = nil
procedure.published_at = nil procedure.published_at = nil
procedure.logo_secure_token = nil procedure.logo_secure_token = nil
@ -285,12 +287,12 @@ class Procedure < ApplicationRecord
if !for_individual || (for_individual && individual_with_siret) if !for_individual || (for_individual && individual_with_siret)
fields << [ fields << [
field_hash('SIREN', 'entreprise', 'siren'), field_hash('SIREN', 'etablissement', 'entreprise_siren'),
field_hash('Forme juridique', 'entreprise', 'forme_juridique'), field_hash('Forme juridique', 'etablissement', 'entreprise_forme_juridique'),
field_hash('Nom commercial', 'entreprise', 'nom_commercial'), field_hash('Nom commercial', 'etablissement', 'entreprise_nom_commercial'),
field_hash('Raison sociale', 'entreprise', 'raison_sociale'), field_hash('Raison sociale', 'etablissement', 'entreprise_raison_sociale'),
field_hash('SIRET siège social', 'entreprise', 'siret_siege_social'), field_hash('SIRET siège social', 'etablissement', 'entreprise_siret_siege_social'),
field_hash('Date de création', 'entreprise', 'date_creation') field_hash('Date de création', 'etablissement', 'entreprise_date_creation')
] ]
fields << [ fields << [

View file

@ -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

View file

@ -9,7 +9,7 @@ class User < ApplicationRecord
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable, :async,
:recoverable, :rememberable, :trackable, :validatable, :confirmable :recoverable, :rememberable, :trackable, :validatable, :confirmable
has_many :dossiers, dependent: :destroy has_many :dossiers, dependent: :destroy

View file

@ -34,6 +34,10 @@ class DossierSerializer < ActiveModel::Serializer
object.user.try(:email) object.user.try(:email)
end end
def entreprise
object.etablissement&.entreprise
end
def state def state
case object.state case object.state
when 'en_construction' when 'en_construction'

View file

@ -11,4 +11,8 @@ class EntrepriseSerializer < ActiveModel::Serializer
:date_creation, :date_creation,
:nom, :nom,
:prenom :prenom
def date_creation
object.date_creation ? object.date_creation.to_datetime : nil
end
end end

View file

@ -1,5 +1,5 @@
class ApiEntrepriseService 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 etablissement_params = ApiEntreprise::EtablissementAdapter.new(siret, procedure_id).to_params
entreprise_params = ApiEntreprise::EntrepriseAdapter.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 association_params = ApiEntreprise::RNAAdapter.new(siret, procedure_id).to_params
exercices_params = ApiEntreprise::ExercicesAdapter.new(siret, procedure_id).to_params exercices_params = ApiEntreprise::ExercicesAdapter.new(siret, procedure_id).to_params
params = etablissement_params etablissement_params
.merge(entreprise_params.transform_keys { |k| "entreprise_#{k}" }) .merge(entreprise_params)
.merge(association_params.transform_keys { |k| "association_#{k}" }) .merge(association_params)
.merge(exercices_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
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 end

View file

@ -68,7 +68,7 @@
%h4.text-info %h4.text-info
= procedure.libelle = procedure.libelle
= h sanitize(procedure.description) = h string_to_html(procedure.description)
.champs.col-xs-6.col-md-3 .champs.col-xs-6.col-md-3
%h4.text-info %h4.text-info

View file

@ -16,7 +16,7 @@
.col-lg-4.col-md-4.col-sm-4.col-xs-4.action .col-lg-4.col-md-4.col-sm-4.col-xs-4.action
Renseigner un SIRET Renseigner un SIRET
- if @facade.entreprise.present? - if @facade.etablissement.present?
.default-data-block .default-data-block
.row.show-block.infos#infos_entreprise .row.show-block.infos#infos_entreprise
.header .header

View file

@ -1,6 +1,6 @@
.col-md-12.col-sm-12.col-xs-12.col-xs-12 .col-md-12.col-sm-12.col-xs-12.col-xs-12
%h4 %h4
= @facade.entreprise.raison_sociale_or_name = raison_sociale_or_name(@facade.etablissement)
.row.split-row .row.split-row
.col-xs-12.split-hr .col-xs-12.split-hr
.row .row
@ -9,13 +9,13 @@
.row .row
.col-xs-4.entreprise-label Siret : .col-xs-4.entreprise-label Siret :
.col-xs-8.entreprise-info= @facade.etablissement.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 .row
.col-xs-4.entreprise-label SIRET siège social : .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 .row
.col-xs-4.entreprise-label Forme juridique : .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 .row
.col-xs-4.entreprise-label Libellé naf : .col-xs-4.entreprise-label Libellé naf :
.col-xs-8.entreprise-info= @facade.etablissement.libelle_naf .col-xs-8.entreprise-info= @facade.etablissement.libelle_naf
@ -24,16 +24,16 @@
.col-xs-8.entreprise-info= @facade.etablissement.naf .col-xs-8.entreprise-info= @facade.etablissement.naf
.row .row
.col-xs-4.entreprise-label Date de création : .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 .row
.col-xs-4.entreprise-label Effectif organisation : .col-xs-4.entreprise-label Effectif organisation :
.col-xs-8.entreprise-info= @facade.entreprise.effectif .col-xs-8.entreprise-info= effectif(@facade.etablissement)
.row .row
.col-xs-4.entreprise-label Code effectif : .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 .row
.col-xs-4.entreprise-label Numéro TVA intracommunautaire : .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 .row
.col-xs-4.entreprise-label Adresse : .col-xs-4.entreprise-label Adresse :
@ -42,7 +42,7 @@
= line = line
.row .row
.col-xs-4.entreprise-label Capital social : .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 .row
.col-xs-4.entreprise-label Exercices : .col-xs-4.entreprise-label Exercices :
@ -55,5 +55,5 @@
.row.split-row .row.split-row
.col-xs-12.split-hr .col-xs-12.split-hr
- if @facade.entreprise.rna_information.present? - if @facade.etablissement.association?
= render partial: '/dossiers/infos_rna' = render partial: '/dossiers/infos_rna'

View file

@ -2,21 +2,21 @@
.col-lg-6.col-md-6.col-sm-6.col-xs-6 .col-lg-6.col-md-6.col-sm-6.col-xs-6
%dl.dl-horizontal %dl.dl-horizontal
%dt Association ID : %dt Association ID :
%dd.text-success= @facade.entreprise.rna_information.association_id %dd.text-success= @facade.etablissement.association_rna
%dt Titre : %dt Titre :
%dd= @facade.entreprise.rna_information.titre %dd= @facade.etablissement.association_titre
%dt Objet : %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 .col-lg-6.col-md-6.col-sm-6.col-xs-6
%dl.dl-horizontal %dl.dl-horizontal
%dt Date création : %dt Date création :
%dd= @facade.entreprise.rna_information.date_creation %dd= @facade.etablissement.association_date_creation&.strftime("%d/%m/%Y")
%dt Capital publication : %dt Capital publication :
%dd= @facade.entreprise.rna_information.date_publication %dd= @facade.etablissement.association_date_publication&.strftime("%d/%m/%Y")
%dt Capital déclaration : %dt Capital déclaration :
%dd= @facade.entreprise.rna_information.date_declaration %dd= @facade.etablissement.association_date_declaration&.strftime("%d/%m/%Y")

View file

@ -1,7 +1,7 @@
.col-xs-3.center .col-xs-3.center
%h3 Ma procédure %h3 Ma procédure
#logos.center{ class: (@facade.entreprise.nil? ? '' : 'mask') } #logos.center{ class: (@facade.etablissement.nil? ? '' : 'mask') }
- if @facade.procedure.euro_flag - if @facade.procedure.euro_flag
#euro_flag.flag #euro_flag.flag
= image_tag('drapeau_europe.png') = image_tag('drapeau_europe.png')
@ -15,8 +15,8 @@
%h2#titre-procedure.text-info %h2#titre-procedure.text-info
= @facade.procedure.libelle = @facade.procedure.libelle
#description_procedure{ style: 'width: 95%;', class: (@facade.entreprise.nil? ? '' : 'mask') } #description_procedure{ style: 'width: 95%;', class: (@facade.etablissement.nil? ? '' : 'mask') }
= h simple_format(@facade.procedure.description) = h string_to_html(@facade.procedure.description)
- if @facade.procedure.lien_site_web.present? - if @facade.procedure.lien_site_web.present?
.center .center

View file

@ -2,7 +2,7 @@
%h3 %h3
Mes informations Mes informations
%br %br
- if @facade.entreprise.present? - if @facade.etablissement.present?
.center{ style: 'margin-left: -5%;' } .center{ style: 'margin-left: -5%;' }
Vous êtes authentifié avec le SIRET Vous êtes authentifié avec le SIRET
@ -14,7 +14,7 @@
.etape.etapes-informations.col-xs-9 .etape.etapes-informations.col-xs-9
.row .row
- if @facade.entreprise.nil? - if @facade.etablissement.nil?
#new_siret{ style: 'margin-left: 20%; margin-top: 5%;' } #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_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 .form-group.form-group-lg

View file

@ -2,13 +2,13 @@
%tbody %tbody
%tr %tr
%th.libelle Dénomination : %th.libelle Dénomination :
%td= etablissement.entreprise_raison_sociale_or_name %td= raison_sociale_or_name(etablissement)
%tr %tr
%th.libelle SIRET : %th.libelle SIRET :
%td= etablissement.entreprise_siret_siege_social %td= etablissement.entreprise.siret_siege_social
%tr %tr
%th.libelle Forme juridique : %th.libelle Forme juridique :
%td= sanitize(etablissement.entreprise_forme_juridique) %td= sanitize(etablissement.entreprise.forme_juridique)
%tr %tr
%th.libelle Libellé NAF : %th.libelle Libellé NAF :
%td= etablissement.libelle_naf %td= etablissement.libelle_naf
@ -17,16 +17,16 @@
%td= etablissement.naf %td= etablissement.naf
%tr %tr
%th.libelle Date de création : %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 %tr
%th.libelle Effectif de l'organisation : %th.libelle Effectif de l'organisation :
%td= etablissement.entreprise_effectif %td= effectif(etablissement)
%tr %tr
%th.libelle Code effectif : %th.libelle Code effectif :
%td= etablissement.entreprise_code_effectif_entreprise %td= etablissement.entreprise.code_effectif_entreprise
%tr %tr
%th.libelle Numéro de TVA intracommunautaire : %th.libelle Numéro de TVA intracommunautaire :
%td= etablissement.entreprise_numero_tva_intracommunautaire %td= etablissement.entreprise.numero_tva_intracommunautaire
%tr %tr
%th.libelle Adresse : %th.libelle Adresse :
%td %td
@ -35,7 +35,7 @@
%br %br
%tr %tr
%th.libelle Capital social : %th.libelle Capital social :
%td= pretty_currency(etablissement.entreprise_capital_social) %td= pretty_currency(etablissement.entreprise.capital_social)
%tr %tr
%th.libelle Exercices : %th.libelle Exercices :
%td %td
@ -43,7 +43,7 @@
= "#{exercice.date_fin_exercice.year} : " = "#{exercice.date_fin_exercice.year} : "
= pretty_currency(exercice.ca) = pretty_currency(exercice.ca)
%br %br
- if etablissement.association_rna.present? - if etablissement.association?
%tr %tr
%th.libelle Numéro RNA : %th.libelle Numéro RNA :
%td= etablissement.association_rna %td= etablissement.association_rna

View file

@ -9,7 +9,7 @@
%h2.procedure-title %h2.procedure-title
= @dossier.procedure.libelle = @dossier.procedure.libelle
.procedure-description .procedure-description
= h simple_format(@dossier.procedure.description) = h string_to_html(@dossier.procedure.description)
.column .column
= form_for @dossier.individual, url: update_identite_dossier_path(@dossier), html: { class: "form" } do |f| = form_for @dossier.individual, url: update_identite_dossier_path(@dossier), html: { class: "form" } do |f|

View file

@ -8,4 +8,4 @@
= "modifié le #{champ.updated_at.strftime('%d/%m/%Y à %H:%M')}" = "modifié le #{champ.updated_at.strftime('%d/%m/%Y à %H:%M')}"
- if champ.description.present? - if champ.description.present?
%span.notice= html_formatted_description(champ.description) %span.notice= string_to_html(champ.description)

View file

@ -1,6 +1,6 @@
.etablissement-titre .etablissement-titre
= etablissement.titre = raison_sociale_or_name(etablissement)
= etablissement.entreprise_forme_juridique = etablissement.entreprise_forme_juridique
- if etablissement.entreprise_capital_social.present? - if etablissement.entreprise_capital_social.present?
au capital social de au capital social de
= number_to_currency(etablissement.entreprise_capital_social) = pretty_currency(etablissement.entreprise_capital_social)

View file

@ -1,3 +1,3 @@
%h2.explication-libelle= champ.libelle %h2.explication-libelle= champ.libelle
.explication .explication
= html_formatted_description(champ.description) = string_to_html(champ.description)

View file

@ -13,7 +13,7 @@
%h2#titre-procedure.text-info %h2#titre-procedure.text-info
= @dossier.procedure.libelle = @dossier.procedure.libelle
%p.procedure-description %p.procedure-description
= h sanitize(@dossier.procedure.description) = h string_to_html(@dossier.procedure.description)
- else - else
#logo_procedure.flag #logo_procedure.flag

View file

@ -6,7 +6,7 @@
= @procedure.libelle = @procedure.libelle
%div %div
= simple_format(@procedure.description) = h string_to_html(@procedure.description)
%br %br
= form_tag(url_for({ controller: :dossiers, action: :create }), class: 'form-inline', method: 'POST') do |f| = form_tag(url_for({ controller: :dossiers, action: :create }), class: 'form-inline', method: 'POST') do |f|

View file

@ -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

View file

@ -609,15 +609,13 @@ ActiveRecord::Schema.define(version: 2018_05_22_142109) do
create_view "searches", sql_definition: <<-SQL create_view "searches", sql_definition: <<-SQL
SELECT dossiers.id AS dossier_id, 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 (((((((((((((((((((((((((((((((((((((((((((((((((((((((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 FROM ((((((((dossiers
JOIN users ON ((users.id = dossiers.user_id))) JOIN users ON ((users.id = dossiers.user_id)))
LEFT JOIN france_connect_informations ON ((france_connect_informations.user_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 cerfas ON ((cerfas.dossier_id = dossiers.id)))
LEFT JOIN champs ON ((champs.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 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 etablissements ON ((etablissements.dossier_id = dossiers.id)))
LEFT JOIN individuals ON ((individuals.dossier_id = dossiers.id))) LEFT JOIN individuals ON ((individuals.dossier_id = dossiers.id)))
LEFT JOIN pieces_justificatives ON ((pieces_justificatives.dossier_id = dossiers.id))); LEFT JOIN pieces_justificatives ON ((pieces_justificatives.dossier_id = dossiers.id)));

41
db/views/searches_v03.sql Normal file
View file

@ -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

View file

@ -71,7 +71,7 @@ describe Admin::GestionnairesController, type: :controller do
describe 'Email Notification' do describe 'Email Notification' do
it { it {
expect(GestionnaireMailer).not_to receive(:new_gestionnaire) expect(GestionnaireMailer).not_to receive(:new_gestionnaire)
expect(GestionnaireMailer).not_to receive(:deliver_now!) expect(GestionnaireMailer).not_to receive(:deliver_later)
subject subject
} }
end end
@ -87,7 +87,7 @@ describe Admin::GestionnairesController, type: :controller do
it 'Notification email is not send' do it 'Notification email is not send' do
expect(GestionnaireMailer).not_to receive(:new_gestionnaire) expect(GestionnaireMailer).not_to receive(:new_gestionnaire)
expect(GestionnaireMailer).not_to receive(:deliver_now!) expect(GestionnaireMailer).not_to receive(:deliver_later)
end end
end end
@ -104,7 +104,7 @@ describe Admin::GestionnairesController, type: :controller do
describe 'Email notification' do describe 'Email notification' do
it 'is not sent when email already exists' do it 'is not sent when email already exists' do
expect(GestionnaireMailer).not_to receive(:new_gestionnaire) expect(GestionnaireMailer).not_to receive(:new_gestionnaire)
expect(GestionnaireMailer).not_to receive(:deliver_now!) expect(GestionnaireMailer).not_to receive(:deliver_later)
subject subject
end end

View file

@ -173,7 +173,7 @@ describe API::V1::DossiersController do
it { expect(subject[:raison_sociale]).to eq('GRTGAZ') } it { expect(subject[:raison_sociale]).to eq('GRTGAZ') }
it { expect(subject[:siret_siege_social]).to eq('44011762001530') } it { expect(subject[:siret_siege_social]).to eq('44011762001530') }
it { expect(subject[:code_effectif_entreprise]).to eq('51') } 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) } it { expect(subject.keys).to match_array(field_list) }
end end

View file

@ -131,7 +131,7 @@ describe InvitesController, type: :controller do
context 'when user does not exist' do context 'when user does not exist' do
it 'send email' do it 'send email' do
expect(InviteMailer).to receive(:invite_guest).and_return(InviteMailer) expect(InviteMailer).to receive(:invite_guest).and_return(InviteMailer)
expect(InviteMailer).to receive(:deliver_now!) expect(InviteMailer).to receive(:deliver_later)
subject subject
end end
@ -144,7 +144,7 @@ describe InvitesController, type: :controller do
it 'send email' do it 'send email' do
expect(InviteMailer).to receive(:invite_user).and_return(InviteMailer) expect(InviteMailer).to receive(:invite_user).and_return(InviteMailer)
expect(InviteMailer).to receive(:deliver_now!) expect(InviteMailer).to receive(:deliver_later)
subject subject
end end

View file

@ -18,9 +18,9 @@ describe Manager::AdministrateursController, type: :controller do
it 'alert new mail are send' do it 'alert new mail are send' do
expect(AdministrationMailer).to receive(:new_admin_email).and_return(AdministrationMailer) 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(:invite_admin).and_return(AdministrationMailer)
expect(AdministrationMailer).to receive(:deliver_now!) expect(AdministrationMailer).to receive(:deliver_later)
subject subject
end end
end end

View file

@ -151,9 +151,9 @@ describe NewGestionnaire::DossiersController, type: :controller do
end end
it 'Notification email is sent' do it 'Notification email is sent' do
expect(NotificationMailer).to receive(:send_notification) expect(NotificationMailer).to receive(:send_refused_notification)
.with(dossier, kind_of(Mails::RefusedMail)).and_return(NotificationMailer) .with(dossier).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!) expect(NotificationMailer).to receive(:deliver_later)
subject subject
end end
@ -177,9 +177,9 @@ describe NewGestionnaire::DossiersController, type: :controller do
end end
it 'Notification email is sent' do it 'Notification email is sent' do
expect(NotificationMailer).to receive(:send_notification) expect(NotificationMailer).to receive(:send_without_continuation_notification)
.with(dossier, kind_of(Mails::WithoutContinuationMail)).and_return(NotificationMailer) .with(dossier).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!) expect(NotificationMailer).to receive(:deliver_later)
subject subject
end end
@ -192,11 +192,11 @@ describe NewGestionnaire::DossiersController, type: :controller do
dossier.en_instruction! dossier.en_instruction!
sign_in gestionnaire sign_in gestionnaire
expect(NotificationMailer).to receive(:send_notification) expect(NotificationMailer).to receive(:send_closed_notification)
.with(dossier, kind_of(Mails::ClosedMail)) .with(dossier)
.and_return(NotificationMailer) .and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!) expect(NotificationMailer).to receive(:deliver_later)
end end
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id } } subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id } }

View file

@ -221,14 +221,14 @@ describe NewUser::DossiersController, type: :controller do
it 'sends an email only on the first #update' do it 'sends an email only on the first #update' do
delivery = double 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) .and_return(delivery)
subject subject
expect(NotificationMailer).not_to receive(:send_notification) expect(NotificationMailer).not_to receive(:send_initiated_notification)
subject subject
end end
@ -246,7 +246,7 @@ describe NewUser::DossiersController, type: :controller do
it { expect(flash.alert).to eq(['nop']) } it { expect(flash.alert).to eq(['nop']) }
it 'does not send an email' do it 'does not send an email' do
expect(NotificationMailer).not_to receive(:send_notification) expect(NotificationMailer).not_to receive(:send_received_notification)
subject subject
end end

View file

@ -12,7 +12,6 @@ RSpec.describe Users::CarteController, type: :controller do
let(:invite_by_user) { create :user, email: 'invite@plop.com' } let(:invite_by_user) { create :user, email: 'invite@plop.com' }
let(:dossier_with_no_carto) { create(:dossier) } let(:dossier_with_no_carto) { create(:dossier) }
let!(:entreprise) { create(:entreprise, dossier: dossier) }
let!(:etablissement) { create(:etablissement, dossier: dossier) } let!(:etablissement) { create(:etablissement, dossier: dossier) }
let(:bad_dossier_id) { Dossier.count + 1000 } let(:bad_dossier_id) { Dossier.count + 1000 }
let(:adresse) { etablissement.geo_adresse } let(:adresse) { etablissement.geo_adresse }

View file

@ -16,7 +16,7 @@ shared_examples 'description_controller_spec' do
context 'when all is ok' do context 'when all is ok' do
before do before do
dossier.entreprise = create :entreprise dossier.etablissement = create(:etablissement)
get :show, params: { dossier_id: dossier_id } get :show, params: { dossier_id: dossier_id }
end end
@ -85,8 +85,8 @@ shared_examples 'description_controller_spec' do
describe 'before action check_starter_dossier_informations' do describe 'before action check_starter_dossier_informations' do
subject { get :show, params: { dossier_id: dossier_id } } subject { get :show, params: { dossier_id: dossier_id } }
context 'when dossier does not have an enterprise datas' do context 'when dossier does not have an etablissement datas' do
it { expect(dossier.entreprise).to be_nil } it { expect(dossier.etablissement).to be_nil }
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" } it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
end end
@ -132,9 +132,12 @@ shared_examples 'description_controller_spec' do
after { Timecop.return } after { Timecop.return }
it 'sets the state of the dossier before sending the mail' do it 'sets the state of the dossier before sending the mail' do
expect_any_instance_of(Mails::InitiatedMail) sender = double("notification sender")
.to receive(:subject_for_dossier) allow(sender).to receive(:deliver_later)
expect(NotificationMailer)
.to receive(:send_initiated_notification)
.with(have_attributes(en_construction_at: DateTime.now)) .with(have_attributes(en_construction_at: DateTime.now))
.and_return(sender)
submit_dossier submit_dossier
end end

View file

@ -24,7 +24,7 @@ describe Users::Dossiers::CommentairesController, type: :controller do
it 'should notify user' do it 'should notify user' do
expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer) expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!) expect(NotificationMailer).to receive(:deliver_later)
subject subject
end end

View file

@ -212,15 +212,6 @@ describe Users::DossiersController, type: :controller do
expect { subject }.to change { Dossier.count }.by(0) expect { subject }.to change { Dossier.count }.by(0)
end 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 it "links dossier to user" do
subject subject
expect(Dossier.last.user).to eq(user) expect(Dossier.last.user).to eq(user)
@ -237,7 +228,7 @@ describe Users::DossiersController, type: :controller do
it 'links etablissement to entreprise' do it 'links etablissement to entreprise' do
subject subject
expect(Etablissement.last.entreprise).to eq(Entreprise.last) expect(Etablissement.last.entreprise).to be_truthy
end end
it 'creates exercices for dossier' do it 'creates exercices for dossier' do
@ -267,8 +258,9 @@ describe Users::DossiersController, type: :controller do
let(:rna_status) { 404 } let(:rna_status) { 404 }
let(:rna_body) { '' } let(:rna_body) { '' }
it 'not creates rna information for entreprise' do it 'not creates association information for etablissement' do
expect { subject }.to change { RNAInformation.count }.by(0) subject
expect(Dossier.last.etablissement.association?).to be_falsey
end end
end end
@ -277,12 +269,8 @@ describe Users::DossiersController, type: :controller do
let(:rna_body) { File.read('spec/support/files/rna.json') } let(:rna_body) { File.read('spec/support/files/rna.json') }
it 'creates rna information for entreprise' do it 'creates rna information for entreprise' do
expect { subject }.to change { RNAInformation.count }.by(1)
end
it 'links rna informations to entreprise' do
subject subject
expect(RNAInformation.last.entreprise).to eq(Entreprise.last) expect(Dossier.last.etablissement.association?).to be_truthy
end end
end end
end end

View file

@ -15,8 +15,9 @@ describe Users::RegistrationsController, type: :controller do
context 'when user is correct' do context 'when user is correct' do
it 'sends confirmation instruction' do it 'sends confirmation instruction' do
expect(DeviseUserMailer).to receive(:confirmation_instructions).and_return(DeviseUserMailer) message = double()
expect(DeviseUserMailer).to receive(:deliver) expect(DeviseUserMailer).to receive(:confirmation_instructions).and_return(message)
expect(message).to receive(:deliver_later)
subject subject
end end

View file

@ -199,7 +199,7 @@ describe Users::SessionsController, type: :controller do
end end
context 'when procedure is not published' do context 'when procedure is not published' do
let(:procedure) { create :procedure, published_at: nil } let(:procedure) { create :procedure }
before do before do
session["user_return_to"] = "?procedure_id=#{procedure.id}" session["user_return_to"] = "?procedure_id=#{procedure.id}"
end end
@ -209,7 +209,7 @@ describe Users::SessionsController, type: :controller do
end end
context 'when procedure_id exist' do context 'when procedure_id exist' do
let(:procedure) { create :procedure, published_at: Time.now } let(:procedure) { create :procedure, :published }
before do before do
session["user_return_to"] = "?procedure_id=#{procedure.id}" session["user_return_to"] = "?procedure_id=#{procedure.id}"

View file

@ -14,8 +14,6 @@ FactoryBot.define do
trait :with_entreprise do trait :with_entreprise do
after(:build) do |dossier, _evaluator| after(:build) do |dossier, _evaluator|
etablissement = create(:etablissement) etablissement = create(:etablissement)
entreprise = create(:entreprise, etablissement: etablissement)
dossier.entreprise = entreprise
dossier.etablissement = etablissement dossier.etablissement = etablissement
end end
end end

View file

@ -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

View file

@ -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

View file

@ -1,6 +1,8 @@
require 'spec_helper' require 'spec_helper'
feature 'The gestionnaire part' do feature 'The gestionnaire part' do
include ActiveJob::TestHelper
let(:password) { 'secret_password' } let(:password) { 'secret_password' }
let!(:gestionnaire) { create(:gestionnaire, password: password) } let!(:gestionnaire) { create(:gestionnaire, password: password) }
@ -56,6 +58,7 @@ feature 'The gestionnaire part' do
scenario 'A gestionnaire can use avis' do scenario 'A gestionnaire can use avis' do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
ActiveJob::Base.queue_adapter = :test
log_in(gestionnaire.email, password) 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)) expect(page).to have_current_path(avis_gestionnaire_dossier_path(procedure, dossier))
expert_email = 'expert@tps.com' expert_email = 'expert@tps.com'
perform_enqueued_jobs do
ask_confidential_avis(expert_email, 'a good introduction') ask_confidential_avis(expert_email, 'a good introduction')
end
log_out log_out

View file

@ -1,29 +1,29 @@
require 'spec_helper' RSpec.describe EtablissementHelper, type: :helper do
describe EntrepriseDecorator do
let(:code_effectif) { '00' } let(:code_effectif) { '00' }
let(:raison_sociale) { 'GRTGaz' } let(:raison_sociale) { 'GRTGaz' }
let(:nom) { 'mon nom' } let(:nom) { 'mon nom' }
let(:prenom) { 'mon prenom' } let(:prenom) { 'mon prenom' }
let(:entreprise_params) do let(:entreprise_params) do
{ {
capital_social: 123_000, entreprise_capital_social: 123_000,
code_effectif_entreprise: code_effectif, entreprise_code_effectif_entreprise: code_effectif,
raison_sociale: raison_sociale, entreprise_raison_sociale: raison_sociale,
nom: nom, entreprise_nom: nom,
prenom: prenom entreprise_prenom: prenom
} }
end end
let(:entreprise) { create(:entreprise, entreprise_params) } let(:etablissement) { create(:etablissement, entreprise_params) }
subject { entreprise.decorate }
describe '#raison_sociale_or_name' do describe '#raison_sociale_or_name' do
subject { super().raison_sociale_or_name } subject { raison_sociale_or_name(etablissement) }
context 'when raison_sociale exist' do context 'when raison_sociale exist' do
let(:raison_sociale) { 'ma super raison_sociale' } let(:raison_sociale) { 'ma super raison_sociale' }
it 'display raison_sociale' do it 'display raison_sociale' do
expect(subject).to eq(raison_sociale) expect(subject).to eq(raison_sociale)
end end
end end
context 'when raison_sociale is nil' do context 'when raison_sociale is nil' do
let(:raison_sociale) { nil } let(:raison_sociale) { nil }
it 'display nom and prenom' do it 'display nom and prenom' do
@ -33,20 +33,22 @@ describe EntrepriseDecorator do
end end
describe '#effectif' do describe '#effectif' do
subject { super().effectif } subject { effectif(etablissement) }
context 'when code_effectif is 00' do context 'when code_effectif is 00' do
let(:code_effectif) { '01' } let(:code_effectif) { '01' }
it { is_expected.to eq('1 ou 2 salariés') } it { is_expected.to eq('1 ou 2 salariés') }
end end
context 'when code_effectif is 32' do context 'when code_effectif is 32' do
let(:code_effectif) { '32' } let(:code_effectif) { '32' }
it { is_expected.to eq('250 à 499 salariés') } it { is_expected.to eq('250 à 499 salariés') }
end end
end end
describe '#pretty_capital_social' do describe '#pretty_currency' do
it 'pretty display capital_social' do subject { pretty_currency(etablissement.entreprise_capital_social) }
expect(subject.pretty_capital_social).to eq('123 000,00 €')
end it { is_expected.to eq('123 000,00 €') }
end end
end end

View file

@ -1,6 +1,6 @@
RSpec.describe ChampHelper, type: :helper do RSpec.describe StringToHtmlHelper, type: :helper do
describe "#html_formatted_description" do describe "#string_to_html" do
subject { html_formatted_description(description) } subject { string_to_html(description) }
context "with some simple texte" do context "with some simple texte" do
let(:description) { "1er ligne \n 2ieme ligne" } let(:description) { "1er ligne \n 2ieme ligne" }

View file

@ -2,7 +2,7 @@ require 'rails_helper'
RSpec.describe FindDubiousProceduresJob, type: :job do RSpec.describe FindDubiousProceduresJob, type: :job do
describe 'perform' 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(:procedure) { create(:procedure) }
let(:allowed_tdc) { create(:type_de_champ, libelle: 'fournir') } let(:allowed_tdc) { create(:type_de_champ, libelle: 'fournir') }

View file

@ -17,51 +17,51 @@ describe ApiEntreprise::EntrepriseAdapter do
context 'Attributs Entreprises' do context 'Attributs Entreprises' do
it 'L\'entreprise contient bien un siren' do it 'L\'entreprise contient bien un siren' do
expect(subject[:siren]).to eq(siren) expect(subject[:entreprise_siren]).to eq(siren)
end end
it 'L\'entreprise contient bien un capital_social' do 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 end
it 'L\'entreprise contient bien un numero_tva_intracommunautaire' do 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 end
it 'L\'entreprise contient bien une forme_juridique' do 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 end
it 'L\'entreprise contient bien un forme_juridique_code' do 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 end
it 'L\'entreprise contient bien un nom_commercial' do 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 end
it 'L\'entreprise contient bien une raison_sociale' do 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 end
it 'L\'entreprise contient bien un siret_siege_social' do 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 end
it 'L\'entreprise contient bien un code_effectif_entreprise' do 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 end
it 'L\'entreprise contient bien une date_creation' do 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 end
it 'L\'entreprise contient bien un nom' do it 'L\'entreprise contient bien un nom' do
expect(subject[:nom]).to eq('test_nom') expect(subject[:entreprise_nom]).to eq('test_nom')
end end
it 'L\'entreprise contient bien un prenom' do 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 end
end end

View file

@ -25,16 +25,16 @@ describe ApiEntreprise::RNAAdapter do
it { expect(subject).to be_an_instance_of(Hash) } it { expect(subject).to be_an_instance_of(Hash) }
describe 'Attributs Associations' do 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
end end

View file

@ -18,7 +18,19 @@ RSpec.describe NotificationMailer, type: :mailer do
describe '.send_notification' do describe '.send_notification' do
let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') } 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
# Were testing the (private) method `NotificationMailer#send_notification`.
#
# The standard trick to test a private method would be to `send(:send_notification`, but doesnt 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.subject).to eq(email_template.subject_for_dossier) }
it { expect(subject.body).to eq(email_template.body_for_dossier) } it { expect(subject.body).to eq(email_template.body_for_dossier) }

View file

@ -1,6 +1,6 @@
class NotificationMailerPreview < ActionMailer::Preview class NotificationMailerPreview < ActionMailer::Preview
def send_notification def send_notification
NotificationMailer.send_notification(Dossier.last, Dossier.last.procedure.initiated_mail_template) NotificationMailer.send_initiated_notification(Dossier.last)
end end
def send_draft_notification def send_draft_notification

View file

@ -98,11 +98,10 @@ describe AttestationTemplate, type: :model do
end end
let(:for_individual) { false } let(:for_individual) { false }
let(:individual) { nil } let(:individual) { nil }
let(:etablissement) { nil } let(:etablissement) { create(:etablissement) }
let(:entreprise) { create(:entreprise, etablissement: etablissement) }
let(:types_de_champ) { [] } let(:types_de_champ) { [] }
let(:types_de_champ_private) { [] } 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_title) { 'title' }
let(:template_body) { 'body' } let(:template_body) { 'body' }
let(:attestation_template) do let(:attestation_template) do

View file

@ -90,7 +90,7 @@ RSpec.describe Avis, type: :model do
describe '#notify_gestionnaire' do describe '#notify_gestionnaire' do
context 'when an avis is created' do context 'when an avis is created' do
before 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) allow(AvisMailer).to receive(:avis_invitation).and_return(avis_invitation_double)
Avis.create(claimant: claimant, email: 'email@l.com') Avis.create(claimant: claimant, email: 'email@l.com')
end end

View file

@ -30,9 +30,8 @@ describe TagsSubstitutionConcern, type: :model do
describe 'replace_tags' do describe 'replace_tags' do
let(:individual) { nil } let(:individual) { nil }
let(:etablissement) { nil } let(:etablissement) { create(:etablissement) }
let(:entreprise) { create(:entreprise, etablissement: etablissement) } let!(:dossier) { create(:dossier, procedure: procedure, individual: individual, etablissement: etablissement) }
let!(:dossier) { create(:dossier, procedure: procedure, individual: individual, entreprise: entreprise) }
before { Timecop.freeze(Time.now) } before { Timecop.freeze(Time.now) }
@ -61,7 +60,7 @@ describe TagsSubstitutionConcern, type: :model do
let(:etablissement) { create(:etablissement) } let(:etablissement) { create(:etablissement) }
let(:expected_text) do 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 end
it { is_expected.to eq(expected_text) } it { is_expected.to eq(expected_text) }

View file

@ -1,6 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe Dossier do describe Dossier do
include ActiveJob::TestHelper
let(:user) { create(:user) } let(:user) { create(:user) }
describe "without_followers scope" do describe "without_followers scope" do
@ -27,8 +29,6 @@ describe Dossier do
describe 'methods' do describe 'methods' do
let(:dossier) { create(:dossier, :with_entreprise, user: user) } let(:dossier) { create(:dossier, :with_entreprise, user: user) }
let(:entreprise) { dossier.entreprise }
let(:etablissement) { dossier.etablissement } let(:etablissement) { dossier.etablissement }
subject { dossier } subject { dossier }
@ -200,7 +200,7 @@ describe Dossier do
it { expect(subject[:entreprise_raison_sociale]).to eq('GRTGAZ') } it { expect(subject[:entreprise_raison_sociale]).to eq('GRTGAZ') }
it { expect(subject[:entreprise_siret_siege_social]).to eq('44011762001530') } it { expect(subject[:entreprise_siret_siege_social]).to eq('44011762001530') }
it { expect(subject[:entreprise_code_effectif_entreprise]).to eq('51') } 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_nom]).to be_nil }
it { expect(subject[:entreprise_prenom]).to be_nil } it { expect(subject[:entreprise_prenom]).to be_nil }
@ -311,7 +311,7 @@ describe Dossier do
"GRTGAZ", "GRTGAZ",
"44011762001530", "44011762001530",
"51", "51",
dossier.entreprise.date_creation, "1990-04-24T00:00:00+00:00",
nil, nil,
nil nil
] ]
@ -325,22 +325,16 @@ describe Dossier do
describe '#reset!' do describe '#reset!' do
let!(:dossier) { create :dossier, :with_entreprise, autorisation_donnees: true } 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 } let!(:exercice) { create :exercice, etablissement: dossier.etablissement }
subject { dossier.reset! } subject { dossier.reset! }
it { expect(dossier.entreprise).not_to be_nil }
it { expect(dossier.etablissement).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).not_to be_empty }
it { expect(dossier.etablissement.exercices.size).to eq 1 } 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(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(Exercice, :count).by(-1) }
it { expect { subject }.to change(Entreprise, :count).by(-1) }
it { expect { subject }.to change(Etablissement, :count).by(-1) } it { expect { subject }.to change(Etablissement, :count).by(-1) }
context 'when method reset! is call' do context 'when method reset! is call' do
@ -349,7 +343,6 @@ describe Dossier do
dossier.reload dossier.reload
end end
it { expect(dossier.entreprise).to be_nil }
it { expect(dossier.etablissement).to be_nil } it { expect(dossier.etablissement).to be_nil }
it { expect(dossier.autorisation_donnees).to be_falsey } it { expect(dossier.autorisation_donnees).to be_falsey }
end end
@ -628,7 +621,12 @@ describe Dossier do
end end
it "send an email when the dossier is created for the very first time" do 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 mail = ActionMailer::Base.deliveries.last
expect(mail.subject).to eq("Retrouvez votre brouillon pour la démarche : #{procedure.libelle}") 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('self', 'created_at')).to eq(dossier.created_at) }
it { expect(dossier.get_value('user', 'email')).to eq(user.email) } 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('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('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', @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) } 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 } subject { dossier.owner_name }
context 'when there is no entreprise or individual' do 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 } it { is_expected.to be_nil }
end end
@ -842,7 +840,7 @@ describe Dossier do
context 'when there is entreprise' do context 'when there is entreprise' do
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) } 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 end
context 'when there is an individual' do context 'when there is an individual' do

View file

@ -1,4 +0,0 @@
require 'spec_helper'
describe Entreprise do
end

View file

@ -145,14 +145,14 @@ describe Gestionnaire, type: :model do
after { Timecop.return } after { Timecop.return }
context 'when no procedure published was active last week' do 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 context 'when the gestionnaire has no notifications' do
it { is_expected.to eq(nil) } it { is_expected.to eq(nil) }
end end
end end
context 'when a procedure published was active' do 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) } let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
before :each do before :each do
@ -163,7 +163,7 @@ describe Gestionnaire, type: :model do
end end
context 'when a procedure not published was active with no notifications' do 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) } let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
before :each do before :each do

View file

@ -229,39 +229,27 @@ describe Procedure do
end end
describe 'active' do describe 'active' do
let(:procedure) { create(:procedure, published_at: published_at, archived_at: archived_at) } let(:procedure) { create(:procedure) }
subject { Procedure.active(procedure.id) } subject { Procedure.active(procedure.id) }
context 'when procedure is in draft status and not archived' do 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) } it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end end
context 'when procedure is published and not archived' do context 'when procedure is published and not archived' do
let(:published_at) { Time.now } let(:procedure) { create(:procedure, :published) }
let(:archived_at) { nil }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
context 'when procedure is published and archived' do context 'when procedure is published and archived' do
let(:published_at) { Time.now } let(:procedure) { create(:procedure, :archived) }
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 }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end end
end end
describe 'clone' do describe 'clone' do
let(:archived_at) { nil }
let(:published_at) { nil }
let!(:service) { create(:service) } 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_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_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) } 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 end
describe 'procedure status is reset' do describe 'procedure status is reset' do
let(:archived_at) { Time.now } let(:procedure) { create(:procedure, :archived, received_mail: received_mail, service: service) }
let(:published_at) { Time.now }
it 'Not published nor archived' do it 'Not published nor archived' do
expect(subject.archived_at).to be_nil expect(subject.archived_at).to be_nil
expect(subject.published_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 expect(subject.path).to be_nil
end end
end end
@ -569,12 +559,12 @@ describe Procedure do
{ "label" => 'Civilité (FC)', "table" => 'france_connect_information', "column" => 'gender' }, { "label" => 'Civilité (FC)', "table" => 'france_connect_information', "column" => 'gender' },
{ "label" => 'Prénom (FC)', "table" => 'france_connect_information', "column" => 'given_name' }, { "label" => 'Prénom (FC)', "table" => 'france_connect_information', "column" => 'given_name' },
{ "label" => 'Nom (FC)', "table" => 'france_connect_information', "column" => 'family_name' }, { "label" => 'Nom (FC)', "table" => 'france_connect_information', "column" => 'family_name' },
{ "label" => 'SIREN', "table" => 'entreprise', "column" => 'siren' }, { "label" => 'SIREN', "table" => 'etablissement', "column" => 'entreprise_siren' },
{ "label" => 'Forme juridique', "table" => 'entreprise', "column" => 'forme_juridique' }, { "label" => 'Forme juridique', "table" => 'etablissement', "column" => 'entreprise_forme_juridique' },
{ "label" => 'Nom commercial', "table" => 'entreprise', "column" => 'nom_commercial' }, { "label" => 'Nom commercial', "table" => 'etablissement', "column" => 'entreprise_nom_commercial' },
{ "label" => 'Raison sociale', "table" => 'entreprise', "column" => 'raison_sociale' }, { "label" => 'Raison sociale', "table" => 'etablissement', "column" => 'entreprise_raison_sociale' },
{ "label" => 'SIRET siège social', "table" => 'entreprise', "column" => 'siret_siege_social' }, { "label" => 'SIRET siège social', "table" => 'etablissement', "column" => 'entreprise_siret_siege_social' },
{ "label" => 'Date de création', "table" => 'entreprise', "column" => 'date_creation' }, { "label" => 'Date de création', "table" => 'etablissement', "column" => 'entreprise_date_creation' },
{ "label" => 'SIRET', "table" => 'etablissement', "column" => 'siret' }, { "label" => 'SIRET', "table" => 'etablissement', "column" => 'siret' },
{ "label" => 'Libellé NAF', "table" => 'etablissement', "column" => 'libelle_naf' }, { "label" => 'Libellé NAF', "table" => 'etablissement', "column" => 'libelle_naf' },
{ "label" => 'Code postal', "table" => 'etablissement', "column" => 'code_postal' }, { "label" => 'Code postal', "table" => 'etablissement', "column" => 'code_postal' },

View file

@ -1,4 +0,0 @@
require 'spec_helper'
describe RNAInformation do
end

View file

@ -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_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!(: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_1) { create(:etablissement, entreprise_raison_sociale: 'OCTO Academy', 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_2) { create(:etablissement, entreprise_raison_sociale: 'Plop octo', 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_3) { create(:etablissement, entreprise_raison_sociale: 'OCTO Technology', dossier: dossier_3, siret: '41816609600051') }
describe 'search is empty' do describe 'search is empty' do
let(:terms) { '' } let(:terms) { '' }

View file

@ -15,7 +15,7 @@ describe 'new_gestionnaire/dossiers/show.html.haml', type: :view do
context "when dossier was created by an etablissement" do context "when dossier was created by an etablissement" do
let(:etablissement) { create(:etablissement) } 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_siret_siege_social) }
it { expect(rendered).to include(etablissement.entreprise_forme_juridique) } it { expect(rendered).to include(etablissement.entreprise_forme_juridique) }