Merge branch 'main' into feature/prefill_repetible

This commit is contained in:
Damien Le Thiec 2023-02-15 11:07:56 +01:00
commit 2533ca50d4
35 changed files with 932 additions and 47 deletions

View file

@ -60,7 +60,7 @@ class Dossiers::MessageComponent < ApplicationComponent
t('.deleted_body')
else
body_formatted = commentaire.sent_by_system? ? commentaire.body : simple_format(commentaire.body)
sanitize(body_formatted)
sanitize(body_formatted, commentaire.sent_by_system? ? { scrubber: Sanitizers::MailScrubber.new } : {})
end
end

View file

@ -79,7 +79,7 @@
= form.check_box :collapsible_explanation_enabled, class: "small-margin small", id: dom_id(type_de_champ, :collapsible_explanation_enabled)
- if form.object.collapsible_explanation_enabled?
= form.label :collapsible_explanation_text, for: dom_id(type_de_champ, :collapsible_explanation_text) do
= "Text à afficher quand l'utiliser a choisi de l'afficher"
= "Texte à afficher quand l'utiliser a choisi de l'afficher"
= form.text_area :collapsible_explanation_text, class: "small-margin small", id: dom_id(type_de_champ, :collapsible_explanation_text)

View file

@ -25,8 +25,6 @@ class PrefillDescriptionsController < ApplicationController
end
def prefill_description_params
params.require(:procedure).permit(selected_type_de_champ_ids: [])
rescue ActionController::ParameterMissing
{ selected_type_de_champ_ids: [] }
params.require(:type_de_champ).permit(:selected_type_de_champ_ids)
end
end

View file

@ -41,9 +41,11 @@ export function PointInput() {
type="button"
className="button mr-1"
onClick={getCurrentPosition}
title="Localiser votre position"
title="Afficher votre position sur la carte"
>
<span className="sr-only">Localiser votre position</span>
<span className="sr-only">
Afficher votre position sur la carte
</span>
<LocationMarkerIcon className="icon-size-big" aria-hidden />
</button>
) : null}

View file

@ -0,0 +1,24 @@
class Migrations::NormalizeDepartementsWithEmptyExternalIdJob < ApplicationJob
def perform(ids)
Champs::DepartementChamp.where(id: ids).find_each do |champ|
next unless champ.external_id == ''
if champ.value.nil?
champ.update_columns(external_id: nil)
elsif champ.value == ''
champ.update_columns(external_id: nil, value: nil)
elsif champ.value == '85'
champ.update_columns(external_id: '85', value: 'Vendée')
elsif champ.value.present?
match = champ.value.match(/^(\w{2,3}) - (.+)/)
if match
code = match[1]
name = APIGeoService.departement_name(code)
champ.update_columns(external_id: code, value: name)
else
champ.update_columns(external_id: APIGeoService.departement_code(champ.value))
end
end
end
end
end

View file

@ -0,0 +1,22 @@
class Migrations::NormalizeDepartementsWithNilExternalIdJob < ApplicationJob
def perform(ids)
Champs::DepartementChamp.where(id: ids).find_each do |champ|
next unless champ.external_id.nil?
if champ.value == ''
champ.update_columns(value: nil)
elsif champ.value == '85'
champ.update_columns(external_id: '85', value: 'Vendée')
elsif champ.value.present?
match = champ.value.match(/^(\w{2,3}) - (.+)/)
if match
code = match[1]
name = APIGeoService.departement_name(code)
champ.update_columns(external_id: code, value: name)
else
champ.update_columns(external_id: APIGeoService.departement_code(champ.value))
end
end
end
end
end

View file

@ -0,0 +1,15 @@
class Migrations::NormalizeDepartementsWithPresentExternalIdJob < ApplicationJob
def perform(ids)
Champs::DepartementChamp.where(id: ids).find_each do |champ|
next if champ.external_id.blank?
if champ.value.blank?
champ.update_columns(value: APIGeoService.departement_name(champ.external_id))
elsif (match = champ.value.match(/^(\w{2,3}) - (.+)/))
code = match[1]
name = APIGeoService.departement_name(code)
champ.update_columns(external_id: code, value: name)
end
end
end
end

View file

@ -7,6 +7,7 @@
#
class NotificationMailer < ApplicationMailer
include ActionView::Helpers::SanitizeHelper
include ActionView::Helpers::TextHelper
before_action :set_dossier
before_action :set_services_publics_plus, only: :send_notification
@ -67,7 +68,7 @@ class NotificationMailer < ApplicationMailer
mail_template = @dossier.procedure.mail_template_for(params[:state])
@email = @dossier.user_email_for(:notification)
@subject = mail_template.subject_for_dossier(@dossier)
@subject = truncate(mail_template.subject_for_dossier(@dossier), length: 100)
@body = mail_template.body_for_dossier(@dossier)
@actions = mail_template.actions_for_dossier(@dossier)
@attachment = mail_template.attachment_for_dossier(@dossier)

View file

@ -21,6 +21,9 @@
# type_de_champ_id :integer
#
class Champs::DepartementChamp < Champs::TextChamp
validate :value_in_departement_names, unless: -> { value.nil? }
validate :external_id_in_departement_codes, unless: -> { external_id.nil? }
def for_export
[name, code]
end
@ -65,6 +68,9 @@ class Champs::DepartementChamp < Champs::TextChamp
elsif code.blank?
self.external_id = nil
super(nil)
else
self.external_id = APIGeoService.departement_code(code)
super(code)
end
end
@ -73,4 +79,16 @@ class Champs::DepartementChamp < Champs::TextChamp
def formatted_value
blank? ? "" : "#{code} #{name}"
end
def value_in_departement_names
return if value.in?(APIGeoService.departements.pluck(:name))
errors.add(:value, :not_in_departement_names)
end
def external_id_in_departement_codes
return if external_id.in?(APIGeoService.departements.pluck(:code))
errors.add(:external_id, :not_in_departement_codes)
end
end

View file

@ -10,7 +10,7 @@ module MailTemplateConcern
end
def subject_for_dossier(dossier)
replace_tags(subject, dossier)
replace_tags(subject, dossier).presence || replace_tags(self.class::DEFAULT_SUBJECT, dossier)
end
def body_for_dossier(dossier)

View file

@ -11,7 +11,7 @@ class PrefillDescription < SimpleDelegator
end
def update(attributes)
@selected_type_de_champ_ids = attributes[:selected_type_de_champ_ids].presence || []
@selected_type_de_champ_ids = attributes[:selected_type_de_champ_ids]&.split(' ') || []
end
def types_de_champ

View file

@ -40,7 +40,8 @@ class PrefillParams
TypeDeChamp.type_champs.fetch(:yes_no),
TypeDeChamp.type_champs.fetch(:checkbox),
TypeDeChamp.type_champs.fetch(:pays),
TypeDeChamp.type_champs.fetch(:regions)
TypeDeChamp.type_champs.fetch(:regions),
TypeDeChamp.type_champs.fetch(:departements)
]
attr_reader :champ, :value

View file

@ -270,7 +270,8 @@ class TypeDeChamp < ApplicationRecord
TypeDeChamp.type_champs.fetch(:checkbox),
TypeDeChamp.type_champs.fetch(:drop_down_list),
TypeDeChamp.type_champs.fetch(:regions),
TypeDeChamp.type_champs.fetch(:repetition)
TypeDeChamp.type_champs.fetch(:repetition),
TypeDeChamp.type_champs.fetch(:departements)
])
end

View file

@ -0,0 +1,11 @@
class TypesDeChamp::PrefillDepartementTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp
def possible_values
departements.map { |departement| "#{departement[:code]} (#{departement[:name]})" }
end
private
def departements
@departements ||= APIGeoService.departements.sort_by { |departement| departement[:code] }
end
end

View file

@ -3,10 +3,6 @@ class TypesDeChamp::PrefillPaysTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp
countries.map { |country| "#{country[:code]} (#{country[:name]})" }
end
def example_value
countries.pick(:code)
end
private
def countries

View file

@ -14,6 +14,8 @@ class TypesDeChamp::PrefillTypeDeChamp < SimpleDelegator
TypesDeChamp::PrefillRegionTypeDeChamp.new(type_de_champ)
when TypeDeChamp.type_champs.fetch(:repetition)
TypesDeChamp::PrefillRepetitionTypeDeChamp.new(type_de_champ)
when TypeDeChamp.type_champs.fetch(:departements)
TypesDeChamp::PrefillDepartementTypeDeChamp.new(type_de_champ)
else
new(type_de_champ)
end

View file

@ -72,7 +72,7 @@
= render partial: 'layouts/search_dossiers_form', locals: { search_endpoint: recherche_dossiers_path }
- has_header = [is_instructeur_context, is_expert_context, is_user_context]
#burger-menu.fr-header__menu.fr-modal{ "aria-label" => t('layouts.header.label_modal') }
#burger-menu.fr-header__menu.fr-modal
.fr-container
%button#burger_button.fr-btn--close.fr-btn{ "aria-controls" => "burger-menu", :title => t('close_modal', scope: [:layouts, :header]) }= t('close_modal', scope: [:layouts, :header])
.fr-header__menu-links

View file

@ -7,14 +7,12 @@
.card
.card-title.flex.justify-between.align-center
= type_de_champ.libelle
= form_for prefill_description, url: prefill_description_path(prefill_description.path), data: { turbo: true } do |f|
= form_for type_de_champ, url: prefill_description_path(prefill_description.path), data: { turbo: true } do |f|
- if prefill_description.include?(type_de_champ.id)
- (prefill_description.selected_type_de_champ_ids - [type_de_champ.id.to_s]).each do |id|
= f.hidden_field :selected_type_de_champ_ids, value: id, multiple: true
= f.hidden_field :selected_type_de_champ_ids, value: (prefill_description.selected_type_de_champ_ids - [type_de_champ.id.to_s])
= f.submit t("views.prefill_descriptions.edit.champ_remove"), class: 'fr-btn fr-btn--secondary fr-btn--md'
- elsif prefillable
- (prefill_description.selected_type_de_champ_ids + [type_de_champ.id.to_s]).each do |id|
= f.hidden_field :selected_type_de_champ_ids, value: id, multiple: true
- elsif prefillable && !prefill_description.include?(type_de_champ.id)
= f.hidden_field :selected_type_de_champ_ids, value: (prefill_description.selected_type_de_champ_ids + [type_de_champ.id.to_s])
= f.submit t("views.prefill_descriptions.edit.champ_add"), class: 'fr-btn fr-btn--md'
- else
%button.fr-btn.fr-btn--secondary{ disabled: true }

View file

@ -68,7 +68,6 @@ en:
are_you_new: First time on %{app_name}?
my_account: My account
header:
label_modal: "Burger menu"
close_modal: 'Close'
back: "Back"
back_title: "Revenir sur le site de mon administration"
@ -130,6 +129,7 @@ en:
yes_no_html: '"true" for Yes, "false" pour No'
checkbox_html: '"true" to check, "false" to uncheck'
pays_html: An <a href="https://en.wikipedia.org/wiki/ISO_3166-2" target="_blank">ISO 3166-2 country code</a>
departements_html: A <a href="https://fr.wikipedia.org/wiki/Num%C3%A9rotation_des_d%C3%A9partements_fran%C3%A7ais" target="_blank">department number</a>
regions_html: An <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank">INSEE region code</a>
drop_down_list_html: A choice among those selected when the procedure was created
date_html: ISO8601 date
@ -147,6 +147,7 @@ en:
iban: FR7611315000011234567890138
yes_no: "true"
pays: "FR"
departements: "56"
regions: "53"
date: "2023-02-01"
datetime: "2023-02-01T10:30"
@ -397,6 +398,19 @@ en:
zone: This procedure is run by
champs:
value: Value
default_mail_attributes: &default_mail_attributes
hints:
subject: The generated subject will be truncated if it exceeds 100 characters.
mails/closed_mail:
<< : *default_mail_attributes
mails/initiated_mail:
<< : *default_mail_attributes
mails/received_mail:
<< : *default_mail_attributes
mails/refused_mail:
<< : *default_mail_attributes
mails/without_continuation_mail:
<< : *default_mail_attributes
errors:
messages:
@ -464,6 +478,12 @@ en:
not_in_region_names: "must be a valid region name"
external_id:
not_in_region_codes: "must be a valid region code"
"champs/departement_champ":
attributes:
value:
not_in_departement_names: "must be a valid department name"
external_id:
not_in_departement_codes: "must be a valid department code"
errors:
format: "Field « %{attribute} » %{message}"
messages:

View file

@ -59,7 +59,6 @@ fr:
are_you_new: Vous êtes nouveau sur %{app_name} ?
my_account: Mon compte
header:
label_modal: "Menu en-tête de page"
close_modal: 'Fermer'
back: "Revenir en arrière"
back_title: "Revenir sur le site de mon administration"
@ -121,6 +120,7 @@ fr:
yes_no_html: '"true" pour Oui, "false" pour Non'
checkbox_html: '"true" pour coché, "false" pour décoché'
pays_html: Un <a href="https://en.wikipedia.org/wiki/ISO_3166-2" target="_blank">code pays ISO 3166-2</a>
departements_html: Un <a href="https://fr.wikipedia.org/wiki/Num%C3%A9rotation_des_d%C3%A9partements_fran%C3%A7ais" target="_blank">numéro de département</a>
regions_html: Un <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank">code INSEE de région</a>
drop_down_list_html: Un choix parmi ceux sélectionnés à la création de la procédure
datetime_html: Datetime au format ISO8601
@ -139,6 +139,7 @@ fr:
yes_no: "true"
civilite: "M."
pays: "FR"
departements: "56"
regions: "53"
date: "2023-02-01"
datetime: "2023-02-01T10:30"
@ -394,6 +395,19 @@ fr:
zone: La démarche est mise en œuvre par
champs:
value: Valeur du champ
default_mail_attributes: &default_mail_attributes
hints:
subject: "Lobjet généré sera tronqué sil dépasse 100 caractères."
mails/closed_mail:
<< : *default_mail_attributes
mails/initiated_mail:
<< : *default_mail_attributes
mails/received_mail:
<< : *default_mail_attributes
mails/refused_mail:
<< : *default_mail_attributes
mails/without_continuation_mail:
<< : *default_mail_attributes
errors:
messages:
@ -459,6 +473,12 @@ fr:
not_in_region_names: "doit être un nom de région valide"
external_id:
not_in_region_codes: "doit être un code de région valide"
"champs/departement_champ":
attributes:
value:
not_in_departement_names: "doit être un nom de département valide"
external_id:
not_in_departement_codes: "doit être un code de département valide"
errors:
format: "Le champ « %{attribute} » %{message}"
messages:

View file

@ -0,0 +1,55 @@
namespace :after_party do
desc 'Deployment task: normalize_regions'
task normalize_regions: :environment do
puts "Running deploy task 'normalize_regions'"
scope_external_id_nil = Champs::RegionChamp.where(external_id: nil)
scope_external_id_empty = Champs::RegionChamp.where(external_id: '')
scope_external_id_present = Champs::RegionChamp.where.not(external_id: [nil, ''])
progress = ProgressReport.new(scope_external_id_nil.count + scope_external_id_empty.count + scope_external_id_present.count)
scope_external_id_nil.find_each do |champ|
progress.inc
if champ.value == ''
champ.update_columns(value: nil)
elsif champ.value == "Provence-Alpes-Côte d'Azur"
champ.update_columns(external_id: "93", value: "Provence-Alpes-Côte dAzur")
elsif champ.present?
champ.update_columns(external_id: APIGeoService.region_code(champ.value))
end
end
scope_external_id_empty.find_each do |champ|
progress.inc
if champ.value.nil?
champ.update_columns(external_id: nil)
elsif champ.value == ''
champ.update_columns(external_id: nil, value: nil)
elsif champ.value == "Provence-Alpes-Côte d'Azur"
champ.update_columns(external_id: "93", value: "Provence-Alpes-Côte dAzur")
elsif champ.present?
champ.update_columns(external_id: APIGeoService.region_code(champ.value))
end
end
scope_external_id_present.find_each do |champ|
progress.inc
if champ.value.blank?
champ.update_columns(value: APIGeoService.region_name(champ.external_id))
elsif champ.value == "Provence-Alpes-Côte d'Azur"
champ.update_columns(external_id: "93", value: "Provence-Alpes-Côte dAzur")
end
end
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -0,0 +1,32 @@
namespace :after_party do
desc 'Deployment task: normalize_departements'
task normalize_departements: :environment do
puts "Running deploy task 'normalize_departements'"
scope_external_id_nil = Champs::DepartementChamp.where(external_id: nil)
scope_external_id_empty = Champs::DepartementChamp.where(external_id: '')
scope_external_id_present = Champs::DepartementChamp.where.not(external_id: [nil, ''])
progress = ProgressReport.new(scope_external_id_nil.count + scope_external_id_empty.count + scope_external_id_present.count)
normalize_asynchronously(scope_external_id_nil, progress, Migrations::NormalizeDepartementsWithNilExternalIdJob)
normalize_asynchronously(scope_external_id_empty, progress, Migrations::NormalizeDepartementsWithEmptyExternalIdJob)
normalize_asynchronously(scope_external_id_present, progress, Migrations::NormalizeDepartementsWithPresentExternalIdJob)
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
private
def normalize_asynchronously(scope, progress, job)
scope.pluck(:id).in_groups_of(10_000, false) do |champ_ids|
job.perform_later(champ_ids)
progress.inc(champ_ids.count)
end
end
end

View file

@ -4,6 +4,13 @@ describe API::V1::DossiersController do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, administrateur: admin) }
let(:wrong_procedure) { create(:procedure) }
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
end
it { expect(described_class).to be < APIController }
describe 'GET index (with bearer token)' do
@ -258,7 +265,7 @@ describe API::V1::DossiersController do
end
end
describe 'departement' do
describe 'departement', vcr: { cassette_name: 'api_geo_departements' } do
let(:procedure) { create(:procedure, :with_departement, administrateur: admin) }
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure: procedure) }

View file

@ -42,7 +42,6 @@ describe API::V2::GraphqlController do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
allow(APIGeoService).to receive(:departement_name).with('01').and_return('Ain')
instructeur.assign_to_procedure(procedure)
end
@ -397,7 +396,7 @@ describe API::V2::GraphqlController do
dossier
end
context "for individual", vcr: { cassette_name: 'api_geo_regions' } do
context "for individual", vcr: { cassette_name: 'api_geo_all' } do
let(:procedure) { create(:procedure, :published, :for_individual, :with_service, :with_all_champs, :with_all_annotations, administrateurs: [admin]) }
let(:query) do
"{

View file

@ -55,14 +55,14 @@ describe PrefillDescriptionsController, type: :controller do
let(:type_de_champ2) { create(:type_de_champ_text, procedure: procedure) }
subject(:update_request) do
patch :update, params: { path: procedure.path, procedure: params }, format: :turbo_stream
patch :update, params: { path: procedure.path, type_de_champ: params }, format: :turbo_stream
end
before { update_request }
context 'when adding a type_de_champ_id' do
let(:type_de_champ_to_add) { create(:type_de_champ_text, procedure: procedure) }
let(:params) { { selected_type_de_champ_ids: [type_de_champ.id, type_de_champ_to_add.id] } }
let(:params) { { selected_type_de_champ_ids: [type_de_champ.id, type_de_champ_to_add.id].join(' ') } }
it { expect(response).to render_template(:update) }
@ -91,7 +91,7 @@ describe PrefillDescriptionsController, type: :controller do
context 'when removing a type_de_champ_id' do
let(:type_de_champ_to_remove) { type_de_champ2 }
let(:params) { { selected_type_de_champ_ids: [type_de_champ] } }
let(:params) { { selected_type_de_champ_ids: type_de_champ } }
it { expect(response).to render_template(:update) }
@ -121,7 +121,7 @@ describe PrefillDescriptionsController, type: :controller do
context 'when removing the last type de champ' do
let(:type_de_champ_to_remove) { type_de_champ }
let(:params) { { selected_type_de_champ_ids: [] } }
let(:params) { { selected_type_de_champ_ids: '' } }
it { expect(response).to render_template(:update) }

View file

@ -0,0 +1,139 @@
describe '20230207144243_normalize_regions', vcr: { cassette_name: 'api_geo_regions' } do
let(:champ) { create(:champ_regions) }
let(:rake_task) { Rake::Task['after_party:normalize_regions'] }
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
subject(:run_task) { rake_task.invoke }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
end
after { rake_task.reenable }
shared_examples "a non-changer" do |external_id, value|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.not_to change { champ.reload.external_id } }
it { expect { run_task }.not_to change { champ.reload.value } }
end
shared_examples "an external_id nullifier" do |external_id, value|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.to change { champ.reload.external_id }.from(external_id).to(nil) }
it { expect { run_task }.not_to change { champ.reload.value } }
end
shared_examples "a value nullifier" do |external_id, value|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.not_to change { champ.reload.external_id } }
it { expect { run_task }.to change { champ.reload.value }.from(value).to(nil) }
end
shared_examples "an external_id and value nullifier" do |external_id, value|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.to change { champ.reload.external_id }.from(external_id).to(nil) }
it { expect { run_task }.to change { champ.reload.value }.from(value).to(nil) }
end
shared_examples "an external_id updater" do |external_id, value, expected_external_id|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.to change { champ.reload.external_id }.from(external_id).to(expected_external_id) }
it { expect { run_task }.not_to change { champ.reload.value } }
end
shared_examples "a result checker" do |external_id, value, expected_external_id, expected_value|
before do
champ.update_columns(external_id:, value:)
run_task
end
it { expect(champ.reload.external_id).to eq(expected_external_id) }
it { expect(champ.reload.value).to eq(expected_value) }
end
shared_examples "a value updater" do |external_id, value, expected_value|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.not_to change { champ.reload.external_id } }
it { expect { run_task }.to change { champ.reload.value }.from(value).to(expected_value) }
end
it_behaves_like "a non-changer", nil, nil
it_behaves_like "an external_id nullifier", '', nil
it_behaves_like "a value nullifier", nil, ''
it_behaves_like "an external_id and value nullifier", '', ''
it_behaves_like "an external_id updater", nil, 'Auvergne-Rhône-Alpes', '84'
it_behaves_like "an external_id updater", '', 'Auvergne-Rhône-Alpes', '84'
it_behaves_like "a value updater", '11', nil, 'Île-de-France'
# Integrity data check:
it_behaves_like "a result checker", "84", "Auvergne-Rhône-Alpes", "84", "Auvergne-Rhône-Alpes"
it_behaves_like "a result checker", nil, "Auvergne-Rhône-Alpes", "84", "Auvergne-Rhône-Alpes"
it_behaves_like "a result checker", '', "Auvergne-Rhône-Alpes", "84", "Auvergne-Rhône-Alpes"
it_behaves_like "a result checker", "27", "Bourgogne-Franche-Comté", "27", "Bourgogne-Franche-Comté"
it_behaves_like "a result checker", nil, "Bourgogne-Franche-Comté", "27", "Bourgogne-Franche-Comté"
it_behaves_like "a result checker", '', "Bourgogne-Franche-Comté", "27", "Bourgogne-Franche-Comté"
it_behaves_like "a result checker", "53", "Bretagne", "53", "Bretagne"
it_behaves_like "a result checker", nil, "Bretagne", "53", "Bretagne"
it_behaves_like "a result checker", '', "Bretagne", "53", "Bretagne"
it_behaves_like "a result checker", "24", "Centre-Val de Loire", "24", "Centre-Val de Loire"
it_behaves_like "a result checker", nil, "Centre-Val de Loire", "24", "Centre-Val de Loire"
it_behaves_like "a result checker", '', "Centre-Val de Loire", "24", "Centre-Val de Loire"
it_behaves_like "a result checker", "94", "Corse", "94", "Corse"
it_behaves_like "a result checker", nil, "Corse", "94", "Corse"
it_behaves_like "a result checker", '', "Corse", "94", "Corse"
it_behaves_like "a result checker", "44", "Grand Est", "44", "Grand Est"
it_behaves_like "a result checker", nil, "Grand Est", "44", "Grand Est"
it_behaves_like "a result checker", '', "Grand Est", "44", "Grand Est"
it_behaves_like "a result checker", "01", "Guadeloupe", "01", "Guadeloupe"
it_behaves_like "a result checker", nil, "Guadeloupe", "01", "Guadeloupe"
it_behaves_like "a result checker", '', "Guadeloupe", "01", "Guadeloupe"
it_behaves_like "a result checker", "03", "Guyane", "03", "Guyane"
it_behaves_like "a result checker", nil, "Guyane", "03", "Guyane"
it_behaves_like "a result checker", '', "Guyane", "03", "Guyane"
it_behaves_like "a result checker", "32", "Hauts-de-France", "32", "Hauts-de-France"
it_behaves_like "a result checker", nil, "Hauts-de-France", "32", "Hauts-de-France"
it_behaves_like "a result checker", '', "Hauts-de-France", "32", "Hauts-de-France"
it_behaves_like "a result checker", "04", "La Réunion", "04", "La Réunion"
it_behaves_like "a result checker", nil, "La Réunion", "04", "La Réunion"
it_behaves_like "a result checker", '', "La Réunion", "04", "La Réunion"
it_behaves_like "a result checker", "02", "Martinique", "02", "Martinique"
it_behaves_like "a result checker", nil, "Martinique", "02", "Martinique"
it_behaves_like "a result checker", '', "Martinique", "02", "Martinique"
it_behaves_like "a result checker", "06", "Mayotte", "06", "Mayotte"
it_behaves_like "a result checker", nil, "Mayotte", "06", "Mayotte"
it_behaves_like "a result checker", '', "Mayotte", "06", "Mayotte"
it_behaves_like "a result checker", "28", "Normandie", "28", "Normandie"
it_behaves_like "a result checker", nil, "Normandie", "28", "Normandie"
it_behaves_like "a result checker", '', "Normandie", "28", "Normandie"
it_behaves_like "a result checker", "75", "Nouvelle-Aquitaine", "75", "Nouvelle-Aquitaine"
it_behaves_like "a result checker", nil, "Nouvelle-Aquitaine", "75", "Nouvelle-Aquitaine"
it_behaves_like "a result checker", '', "Nouvelle-Aquitaine", "75", "Nouvelle-Aquitaine"
it_behaves_like "a result checker", "76", "Occitanie", "76", "Occitanie"
it_behaves_like "a result checker", nil, "Occitanie", "76", "Occitanie"
it_behaves_like "a result checker", '', "Occitanie", "76", "Occitanie"
it_behaves_like "a result checker", "52", "Pays de la Loire", "52", "Pays de la Loire"
it_behaves_like "a result checker", nil, "Pays de la Loire", "52", "Pays de la Loire"
it_behaves_like "a result checker", '', "Pays de la Loire", "52", "Pays de la Loire"
it_behaves_like "a result checker", "93", "Provence-Alpes-Côte d'Azur", "93", "Provence-Alpes-Côte dAzur"
it_behaves_like "a result checker", nil, "Provence-Alpes-Côte d'Azur", "93", "Provence-Alpes-Côte dAzur"
it_behaves_like "a result checker", '', "Provence-Alpes-Côte d'Azur", "93", "Provence-Alpes-Côte dAzur"
it_behaves_like "a result checker", "93", "Provence-Alpes-Côte dAzur", "93", "Provence-Alpes-Côte dAzur"
it_behaves_like "a result checker", "11", "Île-de-France", "11", "Île-de-France"
it_behaves_like "a result checker", "11", nil, "11", "Île-de-France"
it_behaves_like "a result checker", nil, "Île-de-France", "11", "Île-de-France"
it_behaves_like "a result checker", '', "Île-de-France", "11", "Île-de-France"
end

View file

@ -0,0 +1,409 @@
# frozen_string_literal: true
RSpec.describe '20230208084036_normalize_departements', vcr: { cassette_name: 'api_geo_departements' } do
let(:champ) { create(:champ_departements) }
let(:rake_task) { Rake::Task['after_party:normalize_departements'] }
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
subject(:run_task) { perform_enqueued_jobs { rake_task.invoke } }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
end
after { rake_task.reenable }
shared_examples "a non-changer" do |external_id, value|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.not_to change { champ.reload.external_id } }
it { expect { run_task }.not_to change { champ.reload.value } }
end
shared_examples "an external_id nullifier" do |external_id, value|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.to change { champ.reload.external_id }.from(external_id).to(nil) }
it { expect { run_task }.not_to change { champ.reload.value } }
end
shared_examples "a value nullifier" do |external_id, value|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.not_to change { champ.reload.external_id } }
it { expect { run_task }.to change { champ.reload.value }.from(value).to(nil) }
end
shared_examples "an external_id and value nullifier" do |external_id, value|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.to change { champ.reload.external_id }.from(external_id).to(nil) }
it { expect { run_task }.to change { champ.reload.value }.from(value).to(nil) }
end
shared_examples "an external_id updater" do |external_id, value, expected_external_id|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.to change { champ.reload.external_id }.from(external_id).to(expected_external_id) }
it { expect { run_task }.not_to change { champ.reload.value } }
end
shared_examples "a value updater" do |external_id, value, expected_value|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.not_to change { champ.reload.external_id } }
it { expect { run_task }.to change { champ.reload.value }.from(value).to(expected_value) }
end
shared_examples "an external_id and value updater" do |external_id, value, expected_external_id, expected_value|
before { champ.update_columns(external_id:, value:) }
it { expect { run_task }.to change { champ.reload.external_id }.from(external_id).to(expected_external_id) }
it { expect { run_task }.to change { champ.reload.value }.from(value).to(expected_value) }
end
shared_examples "a result checker" do |external_id, value, expected_external_id, expected_value|
before do
champ.update_columns(external_id:, value:)
run_task
end
it { expect(champ.reload.external_id).to eq(expected_external_id) }
it { expect(champ.reload.value).to eq(expected_value) }
end
it_behaves_like "a non-changer", nil, nil
it_behaves_like "an external_id nullifier", '', nil
it_behaves_like "a value nullifier", nil, ''
it_behaves_like "an external_id and value nullifier", '', ''
it_behaves_like "an external_id updater", nil, 'Ain', '01'
it_behaves_like "an external_id updater", '', 'Ain', '01'
it_behaves_like "a value updater", '01', nil, 'Ain'
it_behaves_like "a value updater", '01', '', 'Ain'
it_behaves_like "an external_id and value updater", nil, '01 - Ain', '01', 'Ain'
it_behaves_like "an external_id and value updater", '', '01 - Ain', '01', 'Ain'
# Integrity data check:
it_behaves_like "a result checker", "972", nil, "972", "Martinique"
it_behaves_like "a result checker", "92", nil, "92", "Hauts-de-Seine"
it_behaves_like "a result checker", "01", nil, "01", "Ain"
it_behaves_like "a result checker", "82", nil, "82", "Tarn-et-Garonne"
it_behaves_like "a result checker", "01", "01 - Ain", "01", "Ain"
it_behaves_like "a result checker", '', "01 - Ain", "01", "Ain"
it_behaves_like "a result checker", nil, "01 - Ain", "01", "Ain"
it_behaves_like "a result checker", "02", "02 - Aisne", "02", "Aisne"
it_behaves_like "a result checker", nil, "02 - Aisne", "02", "Aisne"
it_behaves_like "a result checker", '', "02 - Aisne", "02", "Aisne"
it_behaves_like "a result checker", "03", "03 - Allier", "03", "Allier"
it_behaves_like "a result checker", nil, "03 - Allier", "03", "Allier"
it_behaves_like "a result checker", '', "03 - Allier", "03", "Allier"
it_behaves_like "a result checker", "04", "04 - Alpes-de-Haute-Provence", "04", "Alpes-de-Haute-Provence"
it_behaves_like "a result checker", nil, "04 - Alpes-de-Haute-Provence", "04", "Alpes-de-Haute-Provence"
it_behaves_like "a result checker", '', "04 - Alpes-de-Haute-Provence", "04", "Alpes-de-Haute-Provence"
it_behaves_like "a result checker", "05", "05 - Hautes-Alpes", "05", "Hautes-Alpes"
it_behaves_like "a result checker", nil, "05 - Hautes-Alpes", "05", "Hautes-Alpes"
it_behaves_like "a result checker", '', "05 - Hautes-Alpes", "05", "Hautes-Alpes"
it_behaves_like "a result checker", nil, "06 - Alpes-Maritimes", "06", "Alpes-Maritimes"
it_behaves_like "a result checker", "06", "06 - Alpes-Maritimes", "06", "Alpes-Maritimes"
it_behaves_like "a result checker", '', "06 - Alpes-Maritimes", "06", "Alpes-Maritimes"
it_behaves_like "a result checker", "07", "07 - Ardèche", "07", "Ardèche"
it_behaves_like "a result checker", nil, "07 - Ardèche", "07", "Ardèche"
it_behaves_like "a result checker", '', "07 - Ardèche", "07", "Ardèche"
it_behaves_like "a result checker", "08", "08 - Ardennes", "08", "Ardennes"
it_behaves_like "a result checker", nil, "08 - Ardennes", "08", "Ardennes"
it_behaves_like "a result checker", '', "08 - Ardennes", "08", "Ardennes"
it_behaves_like "a result checker", "09", "09 - Ariège", "09", "Ariège"
it_behaves_like "a result checker", nil, "09 - Ariège", "09", "Ariège"
it_behaves_like "a result checker", '', "09 - Ariège", "09", "Ariège"
it_behaves_like "a result checker", nil, "10 - Aube", "10", "Aube"
it_behaves_like "a result checker", "10", "10 - Aube", "10", "Aube"
it_behaves_like "a result checker", '', "10 - Aube", "10", "Aube"
it_behaves_like "a result checker", "11", "11 - Aude", "11", "Aude"
it_behaves_like "a result checker", nil, "11 - Aude", "11", "Aude"
it_behaves_like "a result checker", '', "11 - Aude", "11", "Aude"
it_behaves_like "a result checker", "12", "12 - Aveyron", "12", "Aveyron"
it_behaves_like "a result checker", nil, "12 - Aveyron", "12", "Aveyron"
it_behaves_like "a result checker", '', "12 - Aveyron", "12", "Aveyron"
it_behaves_like "a result checker", "13", "13 - Bouches-du-Rhône", "13", "Bouches-du-Rhône"
it_behaves_like "a result checker", nil, "13 - Bouches-du-Rhône", "13", "Bouches-du-Rhône"
it_behaves_like "a result checker", '', "13 - Bouches-du-Rhône", "13", "Bouches-du-Rhône"
it_behaves_like "a result checker", "14", "14 - Calvados", "14", "Calvados"
it_behaves_like "a result checker", nil, "14 - Calvados", "14", "Calvados"
it_behaves_like "a result checker", '', "14 - Calvados", "14", "Calvados"
it_behaves_like "a result checker", "15", "15 - Cantal", "15", "Cantal"
it_behaves_like "a result checker", nil, "15 - Cantal", "15", "Cantal"
it_behaves_like "a result checker", '', "15 - Cantal", "15", "Cantal"
it_behaves_like "a result checker", "16", "16 - Charente", "16", "Charente"
it_behaves_like "a result checker", nil, "16 - Charente", "16", "Charente"
it_behaves_like "a result checker", '', "16 - Charente", "16", "Charente"
it_behaves_like "a result checker", "17", "17 - Charente-Maritime", "17", "Charente-Maritime"
it_behaves_like "a result checker", nil, "17 - Charente-Maritime", "17", "Charente-Maritime"
it_behaves_like "a result checker", '', "17 - Charente-Maritime", "17", "Charente-Maritime"
it_behaves_like "a result checker", "18", "18 - Cher", "18", "Cher"
it_behaves_like "a result checker", nil, "18 - Cher", "18", "Cher"
it_behaves_like "a result checker", '', "18 - Cher", "18", "Cher"
it_behaves_like "a result checker", "19", "19 - Corrèze", "19", "Corrèze"
it_behaves_like "a result checker", nil, "19 - Corrèze", "19", "Corrèze"
it_behaves_like "a result checker", '', "19 - Corrèze", "19", "Corrèze"
it_behaves_like "a result checker", "21", "21 - Côte-dOr", "21", "Côte-dOr"
it_behaves_like "a result checker", '', "21 - Côte-dOr", "21", "Côte-dOr"
it_behaves_like "a result checker", nil, "21 - Côte-dOr", "21", "Côte-dOr"
it_behaves_like "a result checker", "22", "22 - Côtes-dArmor", "22", "Côtes-dArmor"
it_behaves_like "a result checker", nil, "22 - Côtes-dArmor", "22", "Côtes-dArmor"
it_behaves_like "a result checker", '', "22 - Côtes-dArmor", "22", "Côtes-dArmor"
it_behaves_like "a result checker", "23", "23 - Creuse", "23", "Creuse"
it_behaves_like "a result checker", nil, "23 - Creuse", "23", "Creuse"
it_behaves_like "a result checker", '', "23 - Creuse", "23", "Creuse"
it_behaves_like "a result checker", "24", "24 - Dordogne", "24", "Dordogne"
it_behaves_like "a result checker", nil, "24 - Dordogne", "24", "Dordogne"
it_behaves_like "a result checker", '', "24 - Dordogne", "24", "Dordogne"
it_behaves_like "a result checker", "25", "25 - Doubs", "25", "Doubs"
it_behaves_like "a result checker", nil, "25 - Doubs", "25", "Doubs"
it_behaves_like "a result checker", '', "25 - Doubs", "25", "Doubs"
it_behaves_like "a result checker", "26", "26 - Drôme", "26", "Drôme"
it_behaves_like "a result checker", nil, "26 - Drôme", "26", "Drôme"
it_behaves_like "a result checker", '', "26 - Drôme", "26", "Drôme"
it_behaves_like "a result checker", "27", "27 - Eure", "27", "Eure"
it_behaves_like "a result checker", nil, "27 - Eure", "27", "Eure"
it_behaves_like "a result checker", '', "27 - Eure", "27", "Eure"
it_behaves_like "a result checker", "28", "28 - Eure-et-Loir", "28", "Eure-et-Loir"
it_behaves_like "a result checker", nil, "28 - Eure-et-Loir", "28", "Eure-et-Loir"
it_behaves_like "a result checker", '', "28 - Eure-et-Loir", "28", "Eure-et-Loir"
it_behaves_like "a result checker", "29", "29 - Finistère", "29", "Finistère"
it_behaves_like "a result checker", nil, "29 - Finistère", "29", "Finistère"
it_behaves_like "a result checker", '', "29 - Finistère", "29", "Finistère"
it_behaves_like "a result checker", "2A", "2A - Corse-du-Sud", "2A", "Corse-du-Sud"
it_behaves_like "a result checker", nil, "2A - Corse-du-Sud", "2A", "Corse-du-Sud"
it_behaves_like "a result checker", '', "2A - Corse-du-Sud", "2A", "Corse-du-Sud"
it_behaves_like "a result checker", "2B", "2B - Haute-Corse", "2B", "Haute-Corse"
it_behaves_like "a result checker", nil, "2B - Haute-Corse", "2B", "Haute-Corse"
it_behaves_like "a result checker", '', "2B - Haute-Corse", "2B", "Haute-Corse"
it_behaves_like "a result checker", "30", "30 - Gard", "30", "Gard"
it_behaves_like "a result checker", nil, "30 - Gard", "30", "Gard"
it_behaves_like "a result checker", '', "30 - Gard", "30", "Gard"
it_behaves_like "a result checker", "31", "31 - Haute-Garonne", "31", "Haute-Garonne"
it_behaves_like "a result checker", nil, "31 - Haute-Garonne", "31", "Haute-Garonne"
it_behaves_like "a result checker", '', "31 - Haute-Garonne", "31", "Haute-Garonne"
it_behaves_like "a result checker", "32", "32 - Gers", "32", "Gers"
it_behaves_like "a result checker", nil, "32 - Gers", "32", "Gers"
it_behaves_like "a result checker", '', "32 - Gers", "32", "Gers"
it_behaves_like "a result checker", "33", "33 - Gironde", "33", "Gironde"
it_behaves_like "a result checker", nil, "33 - Gironde", "33", "Gironde"
it_behaves_like "a result checker", '', "33 - Gironde", "33", "Gironde"
it_behaves_like "a result checker", "34", "34 - Hérault", "34", "Hérault"
it_behaves_like "a result checker", nil, "34 - Hérault", "34", "Hérault"
it_behaves_like "a result checker", '', "34 - Hérault", "34", "Hérault"
it_behaves_like "a result checker", "35", "35 - Ille-et-Vilaine", "35", "Ille-et-Vilaine"
it_behaves_like "a result checker", nil, "35 - Ille-et-Vilaine", "35", "Ille-et-Vilaine"
it_behaves_like "a result checker", '', "35 - Ille-et-Vilaine", "35", "Ille-et-Vilaine"
it_behaves_like "a result checker", "36", "36 - Indre", "36", "Indre"
it_behaves_like "a result checker", nil, "36 - Indre", "36", "Indre"
it_behaves_like "a result checker", '', "36 - Indre", "36", "Indre"
it_behaves_like "a result checker", "37", "37 - Indre-et-Loire", "37", "Indre-et-Loire"
it_behaves_like "a result checker", nil, "37 - Indre-et-Loire", "37", "Indre-et-Loire"
it_behaves_like "a result checker", '', "37 - Indre-et-Loire", "37", "Indre-et-Loire"
it_behaves_like "a result checker", "38", "38 - Isère", "38", "Isère"
it_behaves_like "a result checker", nil, "38 - Isère", "38", "Isère"
it_behaves_like "a result checker", '', "38 - Isère", "38", "Isère"
it_behaves_like "a result checker", "39", "39 - Jura", "39", "Jura"
it_behaves_like "a result checker", nil, "39 - Jura", "39", "Jura"
it_behaves_like "a result checker", '', "39 - Jura", "39", "Jura"
it_behaves_like "a result checker", "40", "40 - Landes", "40", "Landes"
it_behaves_like "a result checker", nil, "40 - Landes", "40", "Landes"
it_behaves_like "a result checker", '', "40 - Landes", "40", "Landes"
it_behaves_like "a result checker", "41", "41 - Loir-et-Cher", "41", "Loir-et-Cher"
it_behaves_like "a result checker", nil, "41 - Loir-et-Cher", "41", "Loir-et-Cher"
it_behaves_like "a result checker", '', "41 - Loir-et-Cher", "41", "Loir-et-Cher"
it_behaves_like "a result checker", "42", "42 - Loire", "42", "Loire"
it_behaves_like "a result checker", nil, "42 - Loire", "42", "Loire"
it_behaves_like "a result checker", '', "42 - Loire", "42", "Loire"
it_behaves_like "a result checker", "43", "43 - Haute-Loire", "43", "Haute-Loire"
it_behaves_like "a result checker", nil, "43 - Haute-Loire", "43", "Haute-Loire"
it_behaves_like "a result checker", '', "43 - Haute-Loire", "43", "Haute-Loire"
it_behaves_like "a result checker", "44", "44 - Loire-Atlantique", "44", "Loire-Atlantique"
it_behaves_like "a result checker", nil, "44 - Loire-Atlantique", "44", "Loire-Atlantique"
it_behaves_like "a result checker", '', "44 - Loire-Atlantique", "44", "Loire-Atlantique"
it_behaves_like "a result checker", "45", "45 - Loiret", "45", "Loiret"
it_behaves_like "a result checker", nil, "45 - Loiret", "45", "Loiret"
it_behaves_like "a result checker", '', "45 - Loiret", "45", "Loiret"
it_behaves_like "a result checker", "46", "46 - Lot", "46", "Lot"
it_behaves_like "a result checker", nil, "46 - Lot", "46", "Lot"
it_behaves_like "a result checker", '', "46 - Lot", "46", "Lot"
it_behaves_like "a result checker", "47", "47 - Lot-et-Garonne", "47", "Lot-et-Garonne"
it_behaves_like "a result checker", nil, "47 - Lot-et-Garonne", "47", "Lot-et-Garonne"
it_behaves_like "a result checker", '', "47 - Lot-et-Garonne", "47", "Lot-et-Garonne"
it_behaves_like "a result checker", "48", "48 - Lozère", "48", "Lozère"
it_behaves_like "a result checker", nil, "48 - Lozère", "48", "Lozère"
it_behaves_like "a result checker", '', "48 - Lozère", "48", "Lozère"
it_behaves_like "a result checker", "49", "49 - Maine-et-Loire", "49", "Maine-et-Loire"
it_behaves_like "a result checker", nil, "49 - Maine-et-Loire", "49", "Maine-et-Loire"
it_behaves_like "a result checker", '', "49 - Maine-et-Loire", "49", "Maine-et-Loire"
it_behaves_like "a result checker", "50", "50 - Manche", "50", "Manche"
it_behaves_like "a result checker", nil, "50 - Manche", "50", "Manche"
it_behaves_like "a result checker", '', "50 - Manche", "50", "Manche"
it_behaves_like "a result checker", "51", "51 - Marne", "51", "Marne"
it_behaves_like "a result checker", '', "51 - Marne", "51", "Marne"
it_behaves_like "a result checker", nil, "51 - Marne", "51", "Marne"
it_behaves_like "a result checker", "52", "52 - Haute-Marne", "52", "Haute-Marne"
it_behaves_like "a result checker", nil, "52 - Haute-Marne", "52", "Haute-Marne"
it_behaves_like "a result checker", '', "52 - Haute-Marne", "52", "Haute-Marne"
it_behaves_like "a result checker", "53", "53 - Mayenne", "53", "Mayenne"
it_behaves_like "a result checker", nil, "53 - Mayenne", "53", "Mayenne"
it_behaves_like "a result checker", '', "53 - Mayenne", "53", "Mayenne"
it_behaves_like "a result checker", "54", "54 - Meurthe-et-Moselle", "54", "Meurthe-et-Moselle"
it_behaves_like "a result checker", '', "54 - Meurthe-et-Moselle", "54", "Meurthe-et-Moselle"
it_behaves_like "a result checker", nil, "54 - Meurthe-et-Moselle", "54", "Meurthe-et-Moselle"
it_behaves_like "a result checker", nil, "55 - Meuse", "55", "Meuse"
it_behaves_like "a result checker", "55", "55 - Meuse", "55", "Meuse"
it_behaves_like "a result checker", '', "55 - Meuse", "55", "Meuse"
it_behaves_like "a result checker", "56", "56 - Morbihan", "56", "Morbihan"
it_behaves_like "a result checker", nil, "56 - Morbihan", "56", "Morbihan"
it_behaves_like "a result checker", '', "56 - Morbihan", "56", "Morbihan"
it_behaves_like "a result checker", "57", "57 - Moselle", "57", "Moselle"
it_behaves_like "a result checker", nil, "57 - Moselle", "57", "Moselle"
it_behaves_like "a result checker", '', "57 - Moselle", "57", "Moselle"
it_behaves_like "a result checker", "58", "58 - Nièvre", "58", "Nièvre"
it_behaves_like "a result checker", nil, "58 - Nièvre", "58", "Nièvre"
it_behaves_like "a result checker", '', "58 - Nièvre", "58", "Nièvre"
it_behaves_like "a result checker", "59", "59 - Nord", "59", "Nord"
it_behaves_like "a result checker", nil, "59 - Nord", "59", "Nord"
it_behaves_like "a result checker", '', "59 - Nord", "59", "Nord"
it_behaves_like "a result checker", "60", "60 - Oise", "60", "Oise"
it_behaves_like "a result checker", nil, "60 - Oise", "60", "Oise"
it_behaves_like "a result checker", '', "60 - Oise", "60", "Oise"
it_behaves_like "a result checker", "61", "61 - Orne", "61", "Orne"
it_behaves_like "a result checker", nil, "61 - Orne", "61", "Orne"
it_behaves_like "a result checker", '', "61 - Orne", "61", "Orne"
it_behaves_like "a result checker", nil, "62 - Pas-de-Calais", "62", "Pas-de-Calais"
it_behaves_like "a result checker", "62", "62 - Pas-de-Calais", "62", "Pas-de-Calais"
it_behaves_like "a result checker", '', "62 - Pas-de-Calais", "62", "Pas-de-Calais"
it_behaves_like "a result checker", "63", "63 - Puy-de-Dôme", "63", "Puy-de-Dôme"
it_behaves_like "a result checker", nil, "63 - Puy-de-Dôme", "63", "Puy-de-Dôme"
it_behaves_like "a result checker", '', "63 - Puy-de-Dôme", "63", "Puy-de-Dôme"
it_behaves_like "a result checker", "64", "64 - Pyrénées-Atlantiques", "64", "Pyrénées-Atlantiques"
it_behaves_like "a result checker", nil, "64 - Pyrénées-Atlantiques", "64", "Pyrénées-Atlantiques"
it_behaves_like "a result checker", '', "64 - Pyrénées-Atlantiques", "64", "Pyrénées-Atlantiques"
it_behaves_like "a result checker", "65", "65 - Hautes-Pyrénées", "65", "Hautes-Pyrénées"
it_behaves_like "a result checker", nil, "65 - Hautes-Pyrénées", "65", "Hautes-Pyrénées"
it_behaves_like "a result checker", '', "65 - Hautes-Pyrénées", "65", "Hautes-Pyrénées"
it_behaves_like "a result checker", "66", "66 - Pyrénées-Orientales", "66", "Pyrénées-Orientales"
it_behaves_like "a result checker", nil, "66 - Pyrénées-Orientales", "66", "Pyrénées-Orientales"
it_behaves_like "a result checker", '', "66 - Pyrénées-Orientales", "66", "Pyrénées-Orientales"
it_behaves_like "a result checker", "67", "67 - Bas-Rhin", "67", "Bas-Rhin"
it_behaves_like "a result checker", nil, "67 - Bas-Rhin", "67", "Bas-Rhin"
it_behaves_like "a result checker", '', "67 - Bas-Rhin", "67", "Bas-Rhin"
it_behaves_like "a result checker", "68", "68 - Haut-Rhin", "68", "Haut-Rhin"
it_behaves_like "a result checker", nil, "68 - Haut-Rhin", "68", "Haut-Rhin"
it_behaves_like "a result checker", '', "68 - Haut-Rhin", "68", "Haut-Rhin"
it_behaves_like "a result checker", "69", "69 - Rhône", "69", "Rhône"
it_behaves_like "a result checker", nil, "69 - Rhône", "69", "Rhône"
it_behaves_like "a result checker", '', "69 - Rhône", "69", "Rhône"
it_behaves_like "a result checker", "70", "70 - Haute-Saône", "70", "Haute-Saône"
it_behaves_like "a result checker", nil, "70 - Haute-Saône", "70", "Haute-Saône"
it_behaves_like "a result checker", '', "70 - Haute-Saône", "70", "Haute-Saône"
it_behaves_like "a result checker", "71", "71 - Saône-et-Loire", "71", "Saône-et-Loire"
it_behaves_like "a result checker", nil, "71 - Saône-et-Loire", "71", "Saône-et-Loire"
it_behaves_like "a result checker", '', "71 - Saône-et-Loire", "71", "Saône-et-Loire"
it_behaves_like "a result checker", "72", "72 - Sarthe", "72", "Sarthe"
it_behaves_like "a result checker", nil, "72 - Sarthe", "72", "Sarthe"
it_behaves_like "a result checker", '', "72 - Sarthe", "72", "Sarthe"
it_behaves_like "a result checker", "73", "73 - Savoie", "73", "Savoie"
it_behaves_like "a result checker", nil, "73 - Savoie", "73", "Savoie"
it_behaves_like "a result checker", '', "73 - Savoie", "73", "Savoie"
it_behaves_like "a result checker", "74", "74 - Haute-Savoie", "74", "Haute-Savoie"
it_behaves_like "a result checker", nil, "74 - Haute-Savoie", "74", "Haute-Savoie"
it_behaves_like "a result checker", '', "74 - Haute-Savoie", "74", "Haute-Savoie"
it_behaves_like "a result checker", "75", "75 - Paris", "75", "Paris"
it_behaves_like "a result checker", nil, "75 - Paris", "75", "Paris"
it_behaves_like "a result checker", '', "75 - Paris", "75", "Paris"
it_behaves_like "a result checker", "76", "76 - Seine-Maritime", "76", "Seine-Maritime"
it_behaves_like "a result checker", nil, "76 - Seine-Maritime", "76", "Seine-Maritime"
it_behaves_like "a result checker", '', "76 - Seine-Maritime", "76", "Seine-Maritime"
it_behaves_like "a result checker", "77", "77 - Seine-et-Marne", "77", "Seine-et-Marne"
it_behaves_like "a result checker", nil, "77 - Seine-et-Marne", "77", "Seine-et-Marne"
it_behaves_like "a result checker", '', "77 - Seine-et-Marne", "77", "Seine-et-Marne"
it_behaves_like "a result checker", "78", "78 - Yvelines", "78", "Yvelines"
it_behaves_like "a result checker", '', "78 - Yvelines", "78", "Yvelines"
it_behaves_like "a result checker", nil, "78 - Yvelines", "78", "Yvelines"
it_behaves_like "a result checker", "79", "79 - Deux-Sèvres", "79", "Deux-Sèvres"
it_behaves_like "a result checker", nil, "79 - Deux-Sèvres", "79", "Deux-Sèvres"
it_behaves_like "a result checker", '', "79 - Deux-Sèvres", "79", "Deux-Sèvres"
it_behaves_like "a result checker", "80", "80 - Somme", "80", "Somme"
it_behaves_like "a result checker", nil, "80 - Somme", "80", "Somme"
it_behaves_like "a result checker", '', "80 - Somme", "80", "Somme"
it_behaves_like "a result checker", "81", "81 - Tarn", "81", "Tarn"
it_behaves_like "a result checker", '', "81 - Tarn", "81", "Tarn"
it_behaves_like "a result checker", nil, "81 - Tarn", "81", "Tarn"
it_behaves_like "a result checker", "82", "82 - Tarn-et-Garonne", "82", "Tarn-et-Garonne"
it_behaves_like "a result checker", nil, "82 - Tarn-et-Garonne", "82", "Tarn-et-Garonne"
it_behaves_like "a result checker", '', "82 - Tarn-et-Garonne", "82", "Tarn-et-Garonne"
it_behaves_like "a result checker", "83", "83 - Var", "83", "Var"
it_behaves_like "a result checker", nil, "83 - Var", "83", "Var"
it_behaves_like "a result checker", '', "83 - Var", "83", "Var"
it_behaves_like "a result checker", "84", "84 - Vaucluse", "84", "Vaucluse"
it_behaves_like "a result checker", nil, "84 - Vaucluse", "84", "Vaucluse"
it_behaves_like "a result checker", '', "84 - Vaucluse", "84", "Vaucluse"
it_behaves_like "a result checker", nil, "85", "85", "Vendée"
it_behaves_like "a result checker", "85", "85 - Vendée", "85", "Vendée"
it_behaves_like "a result checker", nil, "85 - Vendée", "85", "Vendée"
it_behaves_like "a result checker", '', "85 - Vendée", "85", "Vendée"
it_behaves_like "a result checker", "86", "86 - Vienne", "86", "Vienne"
it_behaves_like "a result checker", nil, "86 - Vienne", "86", "Vienne"
it_behaves_like "a result checker", '', "86 - Vienne", "86", "Vienne"
it_behaves_like "a result checker", "87", "87 - Haute-Vienne", "87", "Haute-Vienne"
it_behaves_like "a result checker", nil, "87 - Haute-Vienne", "87", "Haute-Vienne"
it_behaves_like "a result checker", '', "87 - Haute-Vienne", "87", "Haute-Vienne"
it_behaves_like "a result checker", "88", "88 - Vosges", "88", "Vosges"
it_behaves_like "a result checker", nil, "88 - Vosges", "88", "Vosges"
it_behaves_like "a result checker", '', "88 - Vosges", "88", "Vosges"
it_behaves_like "a result checker", "89", "89 - Yonne", "89", "Yonne"
it_behaves_like "a result checker", nil, "89 - Yonne", "89", "Yonne"
it_behaves_like "a result checker", '', "89 - Yonne", "89", "Yonne"
it_behaves_like "a result checker", "90", "90 - Territoire de Belfort", "90", "Territoire de Belfort"
it_behaves_like "a result checker", nil, "90 - Territoire de Belfort", "90", "Territoire de Belfort"
it_behaves_like "a result checker", '', "90 - Territoire de Belfort", "90", "Territoire de Belfort"
it_behaves_like "a result checker", "91", "91 - Essonne", "91", "Essonne"
it_behaves_like "a result checker", nil, "91 - Essonne", "91", "Essonne"
it_behaves_like "a result checker", '', "91 - Essonne", "91", "Essonne"
it_behaves_like "a result checker", "92", "92 - Hauts-de-Seine", "92", "Hauts-de-Seine"
it_behaves_like "a result checker", nil, "92 - Hauts-de-Seine", "92", "Hauts-de-Seine"
it_behaves_like "a result checker", '', "92 - Hauts-de-Seine", "92", "Hauts-de-Seine"
it_behaves_like "a result checker", "93", "93 - Seine-Saint-Denis", "93", "Seine-Saint-Denis"
it_behaves_like "a result checker", nil, "93 - Seine-Saint-Denis", "93", "Seine-Saint-Denis"
it_behaves_like "a result checker", '', "93 - Seine-Saint-Denis", "93", "Seine-Saint-Denis"
it_behaves_like "a result checker", "94", "94 - Val-de-Marne", "94", "Val-de-Marne"
it_behaves_like "a result checker", nil, "94 - Val-de-Marne", "94", "Val-de-Marne"
it_behaves_like "a result checker", '', "94 - Val-de-Marne", "94", "Val-de-Marne"
it_behaves_like "a result checker", "95", "95 - Val-dOise", "95", "Val-dOise"
it_behaves_like "a result checker", '', "95 - Val-dOise", "95", "Val-dOise"
it_behaves_like "a result checker", nil, "95 - Val-dOise", "95", "Val-dOise"
it_behaves_like "a result checker", "971", "971 - Guadeloupe", "971", "Guadeloupe"
it_behaves_like "a result checker", nil, "971 - Guadeloupe", "971", "Guadeloupe"
it_behaves_like "a result checker", '', "971 - Guadeloupe", "971", "Guadeloupe"
it_behaves_like "a result checker", "972", "972 - Martinique", "972", "Martinique"
it_behaves_like "a result checker", nil, "972 - Martinique", "972", "Martinique"
it_behaves_like "a result checker", '', "972 - Martinique", "972", "Martinique"
it_behaves_like "a result checker", "973", "973 - Guyane", "973", "Guyane"
it_behaves_like "a result checker", nil, "973 - Guyane", "973", "Guyane"
it_behaves_like "a result checker", '', "973 - Guyane", "973", "Guyane"
it_behaves_like "a result checker", "974", "974 - La Réunion", "974", "La Réunion"
it_behaves_like "a result checker", nil, "974 - La Réunion", "974", "La Réunion"
it_behaves_like "a result checker", '', "974 - La Réunion", "974", "La Réunion"
it_behaves_like "a result checker", "976", "976 - Mayotte", "976", "Mayotte"
it_behaves_like "a result checker", nil, "976 - Mayotte", "976", "Mayotte"
it_behaves_like "a result checker", '', "976 - Mayotte", "976", "Mayotte"
it_behaves_like "a result checker", "99", "99 - Etranger", "99", "Etranger"
it_behaves_like "a result checker", nil, "99 - Etranger", "99", "Etranger"
it_behaves_like "a result checker", '', "99 - Etranger", "99", "Etranger"
it_behaves_like "a result checker", '', "99 - Étranger", "99", "Etranger"
it_behaves_like "a result checker", nil, "99 - Étranger", "99", "Etranger"
end

View file

@ -101,4 +101,27 @@ RSpec.describe NotificationMailer, type: :mailer do
end
end
end
describe 'subject length' do
let(:procedure) { create(:simple_procedure, libelle: "My super long title " + ("xo " * 100)) }
let(:dossier) { create(:dossier, :en_instruction, :with_individual, :with_service, user: user, procedure: procedure) }
let(:email_template) { create(:closed_mail, subject:, body: 'Your dossier was accepted. Thanks.') }
before do
dossier.procedure.closed_mail = email_template
end
subject(:mail) { described_class.send_accepte_notification(dossier) }
context "subject is too long" do
let(:subject) { 'Un long libellé --libellé démarche--' }
it { expect(mail.subject.length).to be <= 100 }
end
context "subject should fallback to default" do
let(:subject) { "" }
it { expect(mail.subject).to match(/^Votre dossier .+ a été accepté \(My super long title/) }
it { expect(mail.subject.length).to be <= 100 }
end
end
end

View file

@ -6,9 +6,69 @@ describe Champs::DepartementChamp, type: :model do
Rails.cache.clear
end
let(:champ) { described_class.new }
describe 'validations', vcr: { cassette_name: 'api_geo_departements' } do
describe 'external link' do
subject { build(:champ_departements, external_id: external_id) }
context 'when nil' do
let(:external_id) { nil }
it { is_expected.to be_valid }
end
context 'when blank' do
let(:external_id) { '' }
it { is_expected.not_to be_valid }
end
context 'when included in the departement codes' do
let(:external_id) { "01" }
it { is_expected.to be_valid }
end
context 'when not included in the departement codes' do
let(:external_id) { "totoro" }
it { is_expected.not_to be_valid }
end
end
describe 'value' do
subject { create(:champ_departements) }
before { subject.update_columns(value: value) }
context 'when nil' do
let(:value) { nil }
it { is_expected.to be_valid }
end
context 'when blank' do
let(:value) { '' }
it { is_expected.not_to be_valid }
end
context 'when included in the departement names' do
let(:value) { "Ain" }
it { is_expected.to be_valid }
end
context 'when not included in the departement names' do
let(:value) { "totoro" }
it { is_expected.not_to be_valid }
end
end
end
describe 'value', vcr: { cassette_name: 'api_geo_departements' } do
let(:champ) { described_class.new }
it 'with code having 2 chars' do
champ.value = '01'
expect(champ.external_id).to eq('01')

View file

@ -3,12 +3,10 @@ RSpec.describe PrefillDescription, type: :model do
describe '#update' do
let(:prefill_description) { described_class.new(build(:procedure)) }
let(:selected_type_de_champ_ids) { ["1", "2"] }
subject(:update) { prefill_description.update(attributes) }
let(:selected_type_de_champ_ids) { ['1', '2'] }
subject(:update) { prefill_description.update({ selected_type_de_champ_ids: selected_type_de_champ_ids.join(' ') }) }
context 'when selected_type_de_champ_ids are given' do
let(:attributes) { { selected_type_de_champ_ids: selected_type_de_champ_ids } }
it 'populate selected_type_de_champ_ids' do
expect { update }.to change { prefill_description.selected_type_de_champ_ids }.from([]).to(selected_type_de_champ_ids)
end
@ -57,7 +55,7 @@ RSpec.describe PrefillDescription, type: :model do
subject(:included) { prefill_description.include?(type_de_champ_id) }
context 'when the id has been added to the prefill_description' do
before { prefill_description.update(selected_type_de_champ_ids: ["1"]) }
before { prefill_description.update(selected_type_de_champ_ids: '1') }
it { expect(included).to eq(true) }
end
@ -73,7 +71,7 @@ RSpec.describe PrefillDescription, type: :model do
subject(:too_long) { prefill_description.link_too_long? }
before { prefill_description.update(selected_type_de_champ_ids: create_list(:type_de_champ_text, type_de_champs_count, procedure: procedure).map(&:id)) }
before { prefill_description.update(selected_type_de_champ_ids: create_list(:type_de_champ_text, type_de_champs_count, procedure: procedure).map(&:id)).join(' ') }
context 'when the prefill link is too long' do
let(:type_de_champs_count) { 65 }

View file

@ -1,5 +1,5 @@
RSpec.describe PrefillParams do
describe "#to_a", vcr: { cassette_name: 'api_geo_regions' } do
describe "#to_a", vcr: { cassette_name: 'api_geo_all' } do
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
let(:procedure) { create(:procedure, :published, types_de_champ_public:, types_de_champ_private:) }
@ -126,6 +126,7 @@ RSpec.describe PrefillParams do
it_behaves_like "a champ public value that is authorized", :checkbox, "false"
it_behaves_like "a champ public value that is authorized", :drop_down_list, "value"
it_behaves_like "a champ public value that is authorized", :regions, "03"
it_behaves_like "a champ public value that is authorized", :departements, "03"
context "when the public type de champ is authorized (repetition)" do
let(:types_de_champ_public) { [{ type: :repetition, children: [{ type: :text }] }] }
@ -158,6 +159,7 @@ RSpec.describe PrefillParams do
it_behaves_like "a champ private value that is authorized", :checkbox, "false"
it_behaves_like "a champ private value that is authorized", :drop_down_list, "value"
it_behaves_like "a champ private value that is authorized", :regions, "93"
it_behaves_like "a champ public value that is authorized", :departements, "03"
context "when the private type de champ is authorized (repetition)" do
let(:types_de_champ_private) { [{ type: :repetition, children: [{ type: :text }] }] }

View file

@ -251,6 +251,7 @@ describe TypeDeChamp do
it_behaves_like "a prefillable type de champ", :type_de_champ_drop_down_list
it_behaves_like "a prefillable type de champ", :type_de_champ_regions
it_behaves_like "a prefillable type de champ", :type_de_champ_repetition
it_behaves_like "a prefillable type de champ", :type_de_champ_departements
it_behaves_like "a non-prefillable type de champ", :type_de_champ_number
it_behaves_like "a non-prefillable type de champ", :type_de_champ_communes
@ -267,7 +268,6 @@ describe TypeDeChamp do
it_behaves_like "a non-prefillable type de champ", :type_de_champ_mesri
it_behaves_like "a non-prefillable type de champ", :type_de_champ_carte
it_behaves_like "a non-prefillable type de champ", :type_de_champ_address
it_behaves_like "a non-prefillable type de champ", :type_de_champ_departements
it_behaves_like "a non-prefillable type de champ", :type_de_champ_siret
it_behaves_like "a non-prefillable type de champ", :type_de_champ_rna
it_behaves_like "a non-prefillable type de champ", :type_de_champ_annuaire_education

View file

@ -0,0 +1,26 @@
# frozen_string_literal: true
RSpec.describe TypesDeChamp::PrefillDepartementTypeDeChamp, type: :model do
let(:type_de_champ) { build(:type_de_champ_departements) }
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
end
describe 'ancestors' do
subject { described_class.build(type_de_champ) }
it { is_expected.to be_kind_of(TypesDeChamp::PrefillTypeDeChamp) }
end
describe '#possible_values', vcr: { cassette_name: 'api_geo_departements' } do
let(:expected_values) {
APIGeoService.departements.sort_by { |departement| departement[:code] }.map { |departement| "#{departement[:code]} (#{departement[:name]})" }
}
subject(:possible_values) { described_class.new(type_de_champ).possible_values }
it { expect(possible_values).to match(expected_values) }
end
end

View file

@ -3,6 +3,12 @@ RSpec.describe TypesDeChamp::PrefillPaysTypeDeChamp, type: :model do
let(:procedure) { create(:procedure) }
let(:type_de_champ) { build(:type_de_champ_pays, procedure: procedure) }
describe 'ancestors' do
subject { described_class.build(type_de_champ) }
it { is_expected.to be_kind_of(TypesDeChamp::PrefillTypeDeChamp) }
end
describe '#possible_values' do
let(:expected_values) { "Un <a href=\"https://en.wikipedia.org/wiki/ISO_3166-2\" target=\"_blank\">code pays ISO 3166-2</a><br><a title=\"Toutes les valeurs possibles — Nouvel onglet\" target=\"_blank\" rel=\"noopener noreferrer\" href=\"/procedures/#{procedure.path}/prefill_type_de_champs/#{type_de_champ.id}\">Voir toutes les valeurs possibles</a>" }
subject(:possible_values) { described_class.new(type_de_champ).possible_values }
@ -13,10 +19,4 @@ RSpec.describe TypesDeChamp::PrefillPaysTypeDeChamp, type: :model do
expect(possible_values).to match(expected_values)
}
end
describe '#example_value' do
subject(:example_value) { described_class.new(type_de_champ).example_value }
it { expect(example_value).to eq(APIGeoService.countries.sort_by { |country| country[:code] }.first[:code]) }
end
end

View file

@ -31,6 +31,12 @@ RSpec.describe TypesDeChamp::PrefillTypeDeChamp, type: :model do
it { expect(built).to be_kind_of(TypesDeChamp::PrefillRepetitionTypeDeChamp) }
end
context 'when the type de champ is a departements' do
let(:type_de_champ) { build(:type_de_champ_departements) }
it { expect(built).to be_kind_of(TypesDeChamp::PrefillDepartementTypeDeChamp) }
end
context 'when any other type de champ' do
let(:type_de_champ) { build(:type_de_champ_date) }