refactor(export): improuve specs
This commit is contained in:
parent
39364961ab
commit
244dcfcc23
13 changed files with 268 additions and 265 deletions
|
@ -33,6 +33,10 @@ class Champs::PaysChamp < Champs::TextChamp
|
|||
end
|
||||
end
|
||||
|
||||
def blank?
|
||||
value.blank? && external_id.blank?
|
||||
end
|
||||
|
||||
def code
|
||||
external_id || APIGeoService.country_code(value)
|
||||
end
|
||||
|
|
|
@ -142,10 +142,7 @@ describe Champ do
|
|||
end
|
||||
|
||||
describe 'for_export' do
|
||||
let(:type_de_champ) { create(:type_de_champ) }
|
||||
let(:champ) { type_de_champ.champ.build(value: value) }
|
||||
|
||||
before { champ.save }
|
||||
let(:champ) { create(:champ_text, value: value) }
|
||||
|
||||
context 'when type_de_champ is text' do
|
||||
let(:value) { '123' }
|
||||
|
@ -154,14 +151,14 @@ describe Champ do
|
|||
end
|
||||
|
||||
context 'when type_de_champ is textarea' do
|
||||
let(:type_de_champ) { create(:type_de_champ_textarea) }
|
||||
let(:champ) { create(:champ_textarea, value: value) }
|
||||
let(:value) { '<b>gras<b>' }
|
||||
|
||||
it { expect(champ.for_export).to eq('gras') }
|
||||
end
|
||||
|
||||
context 'when type_de_champ is yes_no' do
|
||||
let(:type_de_champ) { create(:type_de_champ_yes_no) }
|
||||
let(:champ) { create(:champ_yes_no, value: value) }
|
||||
|
||||
context 'if yes' do
|
||||
let(:value) { 'true' }
|
||||
|
@ -182,249 +179,242 @@ describe Champ do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#search_terms' do
|
||||
let(:champ) { type_de_champ.champ.build(value: value) }
|
||||
subject { champ.search_terms }
|
||||
|
||||
context 'for adresse champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_address) }
|
||||
let(:value) { "10 rue du Pinson qui Piaille" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for checkbox champ' do
|
||||
let(:libelle) { 'majeur' }
|
||||
let(:type_de_champ) { build(:type_de_champ_checkbox, libelle: libelle) }
|
||||
|
||||
context 'when the box is checked' do
|
||||
let(:value) { 'true' }
|
||||
|
||||
it { is_expected.to eq([libelle]) }
|
||||
end
|
||||
|
||||
context 'when the box is unchecked' do
|
||||
let(:value) { 'false' }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
context 'for civilite champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_civilite) }
|
||||
let(:value) { "M." }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for date champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_date) }
|
||||
let(:value) { "2018-07-30" }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for date time champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_datetime) }
|
||||
let(:value) { "2018-04-29 09:00" }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for département champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_departements) }
|
||||
let(:value) { "69" }
|
||||
|
||||
it { is_expected.to eq(['69 – Rhône']) }
|
||||
end
|
||||
|
||||
context 'for dossier link champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_dossier_link) }
|
||||
let(:value) { "9103132886" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for drop down list champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_dossier_link) }
|
||||
let(:value) { "HLM" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for email champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_email) }
|
||||
let(:value) { "machin@example.com" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for explication champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_explication) }
|
||||
let(:value) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for header section champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_header_section) }
|
||||
let(:value) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for linked drop down list champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list) }
|
||||
let(:champ) { type_de_champ.champ.build(primary_value: "hello", secondary_value: "world") }
|
||||
|
||||
it { is_expected.to eq(["hello", "world"]) }
|
||||
end
|
||||
|
||||
context 'for multiple drop down list champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list) }
|
||||
|
||||
context 'when there are multiple values selected' do
|
||||
let(:value) { JSON.generate(['goodbye', 'cruel', 'world']) }
|
||||
|
||||
it { is_expected.to eq(["goodbye", "cruel", "world"]) }
|
||||
end
|
||||
|
||||
context 'when there is no value selected' do
|
||||
let(:value) { nil }
|
||||
|
||||
it { is_expected.to eq([]) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'for number champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_number) }
|
||||
let(:value) { "1234" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for pays champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_pays) }
|
||||
let(:value) { "FR" }
|
||||
|
||||
it { is_expected.to eq(['France']) }
|
||||
end
|
||||
|
||||
context 'for phone champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_phone) }
|
||||
let(:value) { "06 06 06 06 06" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for pièce justificative champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_piece_justificative) }
|
||||
let(:value) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for region champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_regions) }
|
||||
let(:value) { "11" }
|
||||
|
||||
it { is_expected.to eq(['Île-de-France']) }
|
||||
end
|
||||
|
||||
context 'for siret champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_siret) }
|
||||
|
||||
context 'when there is an etablissement' do
|
||||
let(:etablissement) do
|
||||
build(
|
||||
:etablissement,
|
||||
siret: "35130347400024",
|
||||
siege_social: true,
|
||||
naf: "9004Z",
|
||||
libelle_naf: "Gestion de salles de spectacles",
|
||||
adresse: "MAISON JEUNES CULTURE FABRIQUE\r\n98 RUE DE PARIS\r\n59200 TOURCOING\r\nFRANCE\r\n",
|
||||
numero_voie: "98",
|
||||
type_voie: "RUE",
|
||||
nom_voie: "DE PARIS",
|
||||
code_postal: "59200",
|
||||
localite: "TOURCOING",
|
||||
code_insee_localite: "59599",
|
||||
entreprise_siren: "351303474",
|
||||
entreprise_numero_tva_intracommunautaire: "FR02351303474",
|
||||
entreprise_forme_juridique: "Association déclarée ",
|
||||
entreprise_forme_juridique_code: "9220",
|
||||
entreprise_nom_commercial: "",
|
||||
entreprise_raison_sociale: "MAISON DES JEUNES ET DE LA CULTURE DE LA FABRIQUE",
|
||||
entreprise_siret_siege_social: "35130347400024",
|
||||
entreprise_nom: 'Martin',
|
||||
entreprise_prenom: 'Guillaume',
|
||||
entreprise_code_effectif_entreprise: "12",
|
||||
entreprise_date_creation: "1989-07-09",
|
||||
association_rna: "W595004053",
|
||||
association_titre: "MAISON DES JEUNES ET DE LA CULTURE DE LA FABRIQUE",
|
||||
association_objet: "Création, gestion et animation de la Maison des Jeunes et de la Culture de la Fabrique, qui constitue un élément essentiel de la vie sociale et culturelle d'un territoire de vie : pays, agglomération, ville, communauté de communes, village, quartier ...",
|
||||
association_date_creation: "1962-05-23",
|
||||
association_date_declaration: "2016-12-02",
|
||||
association_date_publication: "1962-05-31"
|
||||
)
|
||||
end
|
||||
let(:champ) { type_de_champ.champ.build(value: etablissement.siret, etablissement: etablissement) }
|
||||
|
||||
it { is_expected.to eq([etablissement.entreprise_siren, etablissement.entreprise_numero_tva_intracommunautaire, etablissement.entreprise_forme_juridique, etablissement.entreprise_forme_juridique_code, etablissement.entreprise_nom_commercial, etablissement.entreprise_raison_sociale, etablissement.entreprise_siret_siege_social, etablissement.entreprise_nom, etablissement.entreprise_prenom, etablissement.association_rna, etablissement.association_titre, etablissement.association_objet, etablissement.siret, etablissement.enseigne, etablissement.naf, etablissement.libelle_naf, etablissement.adresse, etablissement.code_postal, etablissement.localite, etablissement.code_insee_localite]) }
|
||||
end
|
||||
|
||||
context 'when there is no etablissement' do
|
||||
let(:siret) { "35130347400024" }
|
||||
let(:champ) { type_de_champ.champ.build(value: siret) }
|
||||
|
||||
it { is_expected.to eq([siret]) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'for text champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_text) }
|
||||
let(:value) { "Blah" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for text area champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_textarea) }
|
||||
let(:value) { "Bla\nBlah de bla." }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for yes/no champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_yes_no, libelle: libelle) }
|
||||
let(:libelle) { 'avec enfant à charge' }
|
||||
|
||||
context 'when the box is checked' do
|
||||
let(:value) { "true" }
|
||||
|
||||
it { is_expected.to eq([libelle]) }
|
||||
end
|
||||
|
||||
context 'when the box is unchecked' do
|
||||
let(:value) { "false" }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when type_de_champ is multiple_drop_down_list' do
|
||||
let(:type_de_champ) { create(:type_de_champ_multiple_drop_down_list) }
|
||||
let(:champ) { create(:champ_multiple_drop_down_list, value:) }
|
||||
let(:value) { '["Crétinier", "Mousserie"]' }
|
||||
|
||||
it { expect(champ.for_export).to eq('Crétinier, Mousserie') }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#search_terms' do
|
||||
subject { champ.search_terms }
|
||||
|
||||
context 'for adresse champ' do
|
||||
let(:champ) { create(:champ_address, value:) }
|
||||
let(:value) { "10 rue du Pinson qui Piaille" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for checkbox champ' do
|
||||
let(:libelle) { champ.libelle }
|
||||
let(:champ) { create(:champ_checkbox, value:) }
|
||||
|
||||
context 'when the box is checked' do
|
||||
let(:value) { 'true' }
|
||||
|
||||
it { is_expected.to eq([libelle]) }
|
||||
end
|
||||
|
||||
context 'when the box is unchecked' do
|
||||
let(:value) { 'false' }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
context 'for civilite champ' do
|
||||
let(:champ) { create(:champ_civilite, value:) }
|
||||
let(:value) { "M." }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for date champ' do
|
||||
let(:champ) { create(:champ_date, value:) }
|
||||
let(:value) { "2018-07-30" }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for date time champ' do
|
||||
let(:champ) { create(:champ_datetime, value:) }
|
||||
let(:value) { "2018-04-29 09:00" }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for département champ' do
|
||||
let(:champ) { create(:champ_departements, value:) }
|
||||
let(:value) { "69" }
|
||||
|
||||
it { is_expected.to eq(['69 – Rhône']) }
|
||||
end
|
||||
|
||||
context 'for dossier link champ' do
|
||||
let(:champ) { create(:champ_dossier_link, value:) }
|
||||
let(:value) { "9103132886" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for drop down list champ' do
|
||||
let(:champ) { create(:champ_dossier_link, value:) }
|
||||
let(:value) { "HLM" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for email champ' do
|
||||
let(:champ) { build(:champ_email, value:) }
|
||||
let(:value) { "machin@example.com" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for explication champ' do
|
||||
let(:champ) { build(:champ_explication) }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for header section champ' do
|
||||
let(:champ) { build(:champ_header_section) }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for linked drop down list champ' do
|
||||
let(:champ) { create(:champ_linked_drop_down_list, primary_value: "hello", secondary_value: "world") }
|
||||
|
||||
it { is_expected.to eq(["hello", "world"]) }
|
||||
end
|
||||
|
||||
context 'for multiple drop down list champ' do
|
||||
let(:champ) { build(:champ_multiple_drop_down_list, value:) }
|
||||
|
||||
context 'when there are multiple values selected' do
|
||||
let(:value) { JSON.generate(['goodbye', 'cruel', 'world']) }
|
||||
|
||||
it { is_expected.to eq(["goodbye", "cruel", "world"]) }
|
||||
end
|
||||
|
||||
context 'when there is no value selected' do
|
||||
let(:value) { nil }
|
||||
|
||||
it { is_expected.to eq([]) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'for number champ' do
|
||||
let(:champ) { build(:champ_number, value:) }
|
||||
let(:value) { "1234" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for pays champ' do
|
||||
let(:champ) { build(:champ_pays, value:) }
|
||||
let(:value) { "FR" }
|
||||
|
||||
it { is_expected.to eq(['France']) }
|
||||
end
|
||||
|
||||
context 'for phone champ' do
|
||||
let(:champ) { build(:champ_phone, value:) }
|
||||
let(:value) { "06 06 06 06 06" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for pièce justificative champ' do
|
||||
let(:champ) { build(:champ_piece_justificative, value:) }
|
||||
let(:value) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for region champ' do
|
||||
let(:champ) { build(:champ_regions, value:) }
|
||||
let(:value) { "11" }
|
||||
|
||||
it { is_expected.to eq(['Île-de-France']) }
|
||||
end
|
||||
|
||||
context 'for siret champ' do
|
||||
context 'when there is an etablissement' do
|
||||
let(:etablissement) do
|
||||
build(
|
||||
:etablissement,
|
||||
siret: "35130347400024",
|
||||
siege_social: true,
|
||||
naf: "9004Z",
|
||||
libelle_naf: "Gestion de salles de spectacles",
|
||||
adresse: "MAISON JEUNES CULTURE FABRIQUE\r\n98 RUE DE PARIS\r\n59200 TOURCOING\r\nFRANCE\r\n",
|
||||
numero_voie: "98",
|
||||
type_voie: "RUE",
|
||||
nom_voie: "DE PARIS",
|
||||
code_postal: "59200",
|
||||
localite: "TOURCOING",
|
||||
code_insee_localite: "59599",
|
||||
entreprise_siren: "351303474",
|
||||
entreprise_numero_tva_intracommunautaire: "FR02351303474",
|
||||
entreprise_forme_juridique: "Association déclarée ",
|
||||
entreprise_forme_juridique_code: "9220",
|
||||
entreprise_nom_commercial: "",
|
||||
entreprise_raison_sociale: "MAISON DES JEUNES ET DE LA CULTURE DE LA FABRIQUE",
|
||||
entreprise_siret_siege_social: "35130347400024",
|
||||
entreprise_nom: 'Martin',
|
||||
entreprise_prenom: 'Guillaume',
|
||||
entreprise_code_effectif_entreprise: "12",
|
||||
entreprise_date_creation: "1989-07-09",
|
||||
association_rna: "W595004053",
|
||||
association_titre: "MAISON DES JEUNES ET DE LA CULTURE DE LA FABRIQUE",
|
||||
association_objet: "Création, gestion et animation de la Maison des Jeunes et de la Culture de la Fabrique, qui constitue un élément essentiel de la vie sociale et culturelle d'un territoire de vie : pays, agglomération, ville, communauté de communes, village, quartier ...",
|
||||
association_date_creation: "1962-05-23",
|
||||
association_date_declaration: "2016-12-02",
|
||||
association_date_publication: "1962-05-31"
|
||||
)
|
||||
end
|
||||
let(:champ) { create(:champ_siret, value: etablissement.siret, etablissement:) }
|
||||
|
||||
it { is_expected.to eq([etablissement.entreprise_siren, etablissement.entreprise_numero_tva_intracommunautaire, etablissement.entreprise_forme_juridique, etablissement.entreprise_forme_juridique_code, etablissement.entreprise_nom_commercial, etablissement.entreprise_raison_sociale, etablissement.entreprise_siret_siege_social, etablissement.entreprise_nom, etablissement.entreprise_prenom, etablissement.association_rna, etablissement.association_titre, etablissement.association_objet, etablissement.siret, etablissement.enseigne, etablissement.naf, etablissement.libelle_naf, etablissement.adresse, etablissement.code_postal, etablissement.localite, etablissement.code_insee_localite]) }
|
||||
end
|
||||
|
||||
context 'when there is no etablissement' do
|
||||
let(:champ) { create(:champ_siret, value:, etablissement: nil) }
|
||||
let(:value) { "35130347400024" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'for text champ' do
|
||||
let(:champ) { build(:champ_text, value:) }
|
||||
let(:value) { "Blah" }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for text area champ' do
|
||||
let(:champ) { build(:champ_textarea, value:) }
|
||||
let(:value) { "Bla\nBlah de bla." }
|
||||
|
||||
it { is_expected.to eq([value]) }
|
||||
end
|
||||
|
||||
context 'for yes/no champ' do
|
||||
let(:champ) { build(:champ_yes_no, value:) }
|
||||
let(:libelle) { champ.libelle }
|
||||
|
||||
context 'when the box is checked' do
|
||||
let(:value) { "true" }
|
||||
|
||||
it { is_expected.to eq([libelle]) }
|
||||
end
|
||||
|
||||
context 'when the box is unchecked' do
|
||||
let(:value) { "false" }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#enqueue_virus_scan' do
|
||||
context 'when type_champ is type_de_champ_piece_justificative' do
|
||||
let(:type_de_champ) { create(:type_de_champ_piece_justificative) }
|
||||
let(:champ) { build(:champ_piece_justificative, type_de_champ: type_de_champ) }
|
||||
let(:champ) { build(:champ_piece_justificative) }
|
||||
|
||||
context 'and there is a blob' do
|
||||
before do
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
describe Champs::AddressChamp do
|
||||
let(:champ) { Champs::AddressChamp.new(value: value, data: data, type_de_champ: create(:type_de_champ_address)) }
|
||||
let(:champ) { build(:champ_address, value:, data:) }
|
||||
let(:value) { '' }
|
||||
let(:data) { nil }
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
describe Champs::CarteChamp do
|
||||
let(:champ) { Champs::CarteChamp.new(geo_areas: geo_areas, type_de_champ: create(:type_de_champ_carte)) }
|
||||
let(:champ) { build(:champ_carte, geo_areas:) }
|
||||
let(:value) { '' }
|
||||
let(:coordinates) { [[[2.3859214782714844, 48.87442541960633], [2.3850631713867183, 48.87273183590832], [2.3809432983398438, 48.87081237174292], [2.3859214782714844, 48.87442541960633]]] }
|
||||
let(:geo_json) do
|
||||
|
|
|
@ -61,7 +61,7 @@ describe Champs::DepartementChamp, type: :model do
|
|||
end
|
||||
|
||||
describe 'value' do
|
||||
let(:champ) { described_class.new }
|
||||
let(:champ) { build(:champ_departements, value: nil) }
|
||||
|
||||
it 'with code having 2 chars' do
|
||||
champ.value = '01'
|
||||
|
|
|
@ -144,16 +144,19 @@ describe Champs::EpciChamp, type: :model do
|
|||
end
|
||||
|
||||
describe 'value' do
|
||||
let(:champ) { described_class.new }
|
||||
let(:champ) { build(:champ_epci, external_id: nil, value: nil) }
|
||||
let(:epci) { APIGeoService.epcis('01').first }
|
||||
|
||||
it 'with departement and code' do
|
||||
champ.code_departement = '01'
|
||||
champ.value = '200042935'
|
||||
expect(champ.external_id).to eq('200042935')
|
||||
expect(champ.value).to eq('CA Haut - Bugey Agglomération')
|
||||
expect(champ.selected).to eq('200042935')
|
||||
expect(champ.code).to eq('200042935')
|
||||
champ.value = epci[:code]
|
||||
expect(champ.blank?).to be_falsey
|
||||
expect(champ.external_id).to eq(epci[:code])
|
||||
expect(champ.value).to eq(epci[:name])
|
||||
expect(champ.selected).to eq(epci[:code])
|
||||
expect(champ.code).to eq(epci[:code])
|
||||
expect(champ.departement?).to be_truthy
|
||||
expect(champ.to_s).to eq('CA Haut - Bugey Agglomération')
|
||||
expect(champ.to_s).to eq(epci[:name])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
describe Champs::LinkedDropDownListChamp do
|
||||
describe '#unpack_value' do
|
||||
let(:champ) { described_class.new(value: '["tata", "tutu"]') }
|
||||
let(:champ) { build(:champ_linked_drop_down_list, value: '["tata", "tutu"]') }
|
||||
|
||||
it { expect(champ.primary_value).to eq('tata') }
|
||||
it { expect(champ.secondary_value).to eq('tutu') }
|
||||
end
|
||||
|
||||
describe '#pack_value' do
|
||||
let(:champ) { described_class.new(primary_value: 'tata', secondary_value: 'tutu') }
|
||||
let(:champ) { build(:champ_linked_drop_down_list, primary_value: 'tata', secondary_value: 'tutu') }
|
||||
|
||||
before { champ.save }
|
||||
|
||||
|
@ -15,7 +15,7 @@ describe Champs::LinkedDropDownListChamp do
|
|||
end
|
||||
|
||||
describe '#primary_value=' do
|
||||
let!(:champ) { described_class.new(primary_value: 'tata', secondary_value: 'tutu') }
|
||||
let!(:champ) { build(:champ_linked_drop_down_list, primary_value: 'tata', secondary_value: 'tutu') }
|
||||
|
||||
before { champ.primary_value = '' }
|
||||
|
||||
|
@ -23,7 +23,7 @@ describe Champs::LinkedDropDownListChamp do
|
|||
end
|
||||
|
||||
describe '#to_s' do
|
||||
let(:champ) { described_class.new(primary_value: primary_value, secondary_value: secondary_value) }
|
||||
let(:champ) { build(:champ_linked_drop_down_list, value: [primary_value, secondary_value].to_json) }
|
||||
let(:primary_value) { nil }
|
||||
let(:secondary_value) { nil }
|
||||
|
||||
|
@ -48,22 +48,28 @@ describe Champs::LinkedDropDownListChamp do
|
|||
end
|
||||
|
||||
describe 'for_export' do
|
||||
let(:champ) { build(:champ_linked_drop_down_list, value:) }
|
||||
let(:value) { [primary_value, secondary_value].to_json }
|
||||
let(:primary_value) { nil }
|
||||
let(:secondary_value) { nil }
|
||||
|
||||
subject { champ.for_export }
|
||||
|
||||
context 'with no value' do
|
||||
let(:champ) { described_class.new }
|
||||
let(:value) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'with primary value' do
|
||||
let(:champ) { described_class.new(primary_value: 'primary') }
|
||||
let(:primary_value) { 'primary' }
|
||||
|
||||
it { is_expected.to eq('primary;') }
|
||||
end
|
||||
|
||||
context 'with secondary value' do
|
||||
let(:champ) { described_class.new(primary_value: 'primary', secondary_value: 'secondary') }
|
||||
let(:primary_value) { 'primary' }
|
||||
let(:secondary_value) { 'secondary' }
|
||||
|
||||
it { is_expected.to eq('primary;secondary') }
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
describe Champs::PaysChamp, type: :model do
|
||||
let(:champ) { described_class.new }
|
||||
let(:champ) { build(:champ_pays, value: nil) }
|
||||
|
||||
describe 'value' do
|
||||
it 'with code' do
|
||||
|
|
|
@ -47,7 +47,7 @@ describe Champs::PieceJustificativeChamp do
|
|||
|
||||
context 'without attached file' do
|
||||
before { champ_pj.piece_justificative_file.purge }
|
||||
it { is_expected.to eq('') }
|
||||
it { is_expected.to eq(nil) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
describe Champs::PoleEmploiChamp, type: :model do
|
||||
let(:champ) { described_class.new }
|
||||
let(:champ) { build(:champ_pole_emploi) }
|
||||
|
||||
describe 'identifiant' do
|
||||
before do
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
describe Champs::RegionChamp, type: :model do
|
||||
describe 'validations' do
|
||||
describe 'external link' do
|
||||
let(:champ) { build(:champ_regions, external_id: external_id) }
|
||||
let(:champ) { build(:champ_regions, value: nil, external_id: external_id) }
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
context 'when nil' do
|
||||
let(:external_id) { nil }
|
||||
|
@ -29,7 +29,7 @@ describe Champs::RegionChamp, type: :model do
|
|||
end
|
||||
|
||||
describe 'value' do
|
||||
let(:champ) { create(:champ_regions) }
|
||||
let(:champ) { create(:champ_regions, value: nil) }
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
before { champ.update_columns(value: value) }
|
||||
|
@ -61,7 +61,7 @@ describe Champs::RegionChamp, type: :model do
|
|||
end
|
||||
|
||||
describe 'value' do
|
||||
let(:champ) { described_class.new }
|
||||
let(:champ) { build(:champ_regions, value: nil) }
|
||||
|
||||
it 'with code' do
|
||||
champ.value = '01'
|
||||
|
|
|
@ -104,7 +104,7 @@ describe ChampSerializer do
|
|||
|
||||
context 'when type champ is siret' do
|
||||
let(:etablissement) { create(:etablissement) }
|
||||
let(:champ) { create(:type_de_champ_siret).champ.create(etablissement: etablissement, value: etablissement.siret) }
|
||||
let(:champ) { create(:champ_siret, etablissement:, value: etablissement.siret) }
|
||||
|
||||
it {
|
||||
is_expected.to include(value: etablissement.siret)
|
||||
|
|
|
@ -214,7 +214,7 @@ describe DossierProjectionService do
|
|||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s }
|
||||
|
||||
before { dossier.champs_public.first.update(data: { 'label' => '18 a la bonne rue', 'departement' => 'd' }) }
|
||||
before { dossier.champs_public.first.update(value: '18 a la bonne rue', data: { 'label' => '18 a la bonne rue', 'departement' => 'd' }) }
|
||||
|
||||
it { is_expected.to eq('18 a la bonne rue') }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue