Add iban type de champ
This commit is contained in:
parent
a7e4720d0d
commit
cb4e91c405
15 changed files with 72 additions and 1 deletions
1
Gemfile
1
Gemfile
|
@ -42,6 +42,7 @@ gem 'groupdate'
|
||||||
gem 'haml-rails'
|
gem 'haml-rails'
|
||||||
gem 'hashie'
|
gem 'hashie'
|
||||||
gem 'http_accept_language'
|
gem 'http_accept_language'
|
||||||
|
gem 'iban-tools'
|
||||||
gem 'jquery-rails' # Use jquery as the JavaScript library
|
gem 'jquery-rails' # Use jquery as the JavaScript library
|
||||||
gem 'jwt'
|
gem 'jwt'
|
||||||
gem 'kaminari', '1.2.1' # Pagination
|
gem 'kaminari', '1.2.1' # Pagination
|
||||||
|
|
|
@ -341,6 +341,7 @@ GEM
|
||||||
httpclient (2.8.3)
|
httpclient (2.8.3)
|
||||||
i18n (1.8.5)
|
i18n (1.8.5)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
|
iban-tools (1.1.0)
|
||||||
ice_nine (0.11.2)
|
ice_nine (0.11.2)
|
||||||
ipaddress (0.8.3)
|
ipaddress (0.8.3)
|
||||||
jaro_winkler (1.5.4)
|
jaro_winkler (1.5.4)
|
||||||
|
@ -813,6 +814,7 @@ DEPENDENCIES
|
||||||
haml-rails
|
haml-rails
|
||||||
hashie
|
hashie
|
||||||
http_accept_language
|
http_accept_language
|
||||||
|
iban-tools
|
||||||
jquery-rails
|
jquery-rails
|
||||||
jwt
|
jwt
|
||||||
kaminari (= 1.2.1)
|
kaminari (= 1.2.1)
|
||||||
|
|
|
@ -1272,6 +1272,11 @@ enum TypeDeChamp {
|
||||||
"""
|
"""
|
||||||
header_section
|
header_section
|
||||||
|
|
||||||
|
"""
|
||||||
|
Iban
|
||||||
|
"""
|
||||||
|
iban
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Nombre entier
|
Nombre entier
|
||||||
"""
|
"""
|
||||||
|
|
19
app/models/champs/iban_champ.rb
Normal file
19
app/models/champs/iban_champ.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: champs
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# private :boolean default(FALSE), not null
|
||||||
|
# row :integer
|
||||||
|
# type :string
|
||||||
|
# value :string
|
||||||
|
# created_at :datetime
|
||||||
|
# updated_at :datetime
|
||||||
|
# dossier_id :integer
|
||||||
|
# etablissement_id :integer
|
||||||
|
# parent_id :bigint
|
||||||
|
# type_de_champ_id :integer
|
||||||
|
#
|
||||||
|
class Champs::IbanChamp < Champ
|
||||||
|
validates_with IbanValidator
|
||||||
|
end
|
|
@ -46,7 +46,8 @@ class TypeDeChamp < ApplicationRecord
|
||||||
siret: 'siret',
|
siret: 'siret',
|
||||||
carte: 'carte',
|
carte: 'carte',
|
||||||
repetition: 'repetition',
|
repetition: 'repetition',
|
||||||
titre_identite: 'titre_identite'
|
titre_identite: 'titre_identite',
|
||||||
|
iban: 'iban'
|
||||||
}
|
}
|
||||||
|
|
||||||
belongs_to :revision, class_name: 'ProcedureRevision', optional: true
|
belongs_to :revision, class_name: 'ProcedureRevision', optional: true
|
||||||
|
|
2
app/models/types_de_champ/iban_type_de_champ.rb
Normal file
2
app/models/types_de_champ/iban_type_de_champ.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
class TypesDeChamp::IbanTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||||
|
end
|
11
app/validators/iban_validator.rb
Normal file
11
app/validators/iban_validator.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
require 'iban-tools'
|
||||||
|
|
||||||
|
class IbanValidator < ActiveModel::Validator
|
||||||
|
def validate(record)
|
||||||
|
if record.value.present?
|
||||||
|
unless IBANTools::IBAN.valid?(record.value)
|
||||||
|
record.errors.add :iban, record.errors.generate_message(:value, :invalid)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
1
app/views/shared/champs/iban/_show.html.haml
Normal file
1
app/views/shared/champs/iban/_show.html.haml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
%p= champ.blank? ? 'Iban non fourni' : champ
|
|
@ -30,6 +30,8 @@
|
||||||
= render partial: "shared/champs/piece_justificative/show", locals: { champ: c }
|
= render partial: "shared/champs/piece_justificative/show", locals: { champ: c }
|
||||||
- when TypeDeChamp.type_champs.fetch(:siret)
|
- when TypeDeChamp.type_champs.fetch(:siret)
|
||||||
= render partial: "shared/champs/siret/show", locals: { champ: c, profile: profile }
|
= render partial: "shared/champs/siret/show", locals: { champ: c, profile: profile }
|
||||||
|
- when TypeDeChamp.type_champs.fetch(:iban)
|
||||||
|
= render partial: "shared/champs/iban/show", locals: { champ: c }
|
||||||
- when TypeDeChamp.type_champs.fetch(:textarea)
|
- when TypeDeChamp.type_champs.fetch(:textarea)
|
||||||
= render partial: "shared/champs/textarea/show", locals: { champ: c }
|
= render partial: "shared/champs/textarea/show", locals: { champ: c }
|
||||||
- when TypeDeChamp.type_champs.fetch(:date)
|
- when TypeDeChamp.type_champs.fetch(:date)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
= form.text_field :value,
|
||||||
|
placeholder: "27 caractères au format FR7630006000011234567890189",
|
||||||
|
required: champ.mandatory?,
|
||||||
|
aria: { describedby: describedby_id(champ) }
|
|
@ -34,3 +34,4 @@ fr:
|
||||||
carte: 'Carte'
|
carte: 'Carte'
|
||||||
repetition: 'Bloc répétable'
|
repetition: 'Bloc répétable'
|
||||||
titre_identite: 'Titre identité'
|
titre_identite: 'Titre identité'
|
||||||
|
iban: 'Iban'
|
||||||
|
|
|
@ -155,6 +155,10 @@ FactoryBot.define do
|
||||||
type_de_champ { association :type_de_champ_carte, procedure: dossier.procedure }
|
type_de_champ { association :type_de_champ_carte, procedure: dossier.procedure }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :champ_iban, class: 'Champs::IbanChamp' do
|
||||||
|
type_de_champ { association :type_de_champ_iban, procedure: dossier.procedure }
|
||||||
|
end
|
||||||
|
|
||||||
factory :champ_siret, class: 'Champs::SiretChamp' do
|
factory :champ_siret, class: 'Champs::SiretChamp' do
|
||||||
association :type_de_champ, factory: [:type_de_champ_siret]
|
association :type_de_champ, factory: [:type_de_champ_siret]
|
||||||
association :etablissement, factory: [:etablissement]
|
association :etablissement, factory: [:etablissement]
|
||||||
|
|
|
@ -139,6 +139,9 @@ FactoryBot.define do
|
||||||
factory :type_de_champ_siret do
|
factory :type_de_champ_siret do
|
||||||
type_champ { TypeDeChamp.type_champs.fetch(:siret) }
|
type_champ { TypeDeChamp.type_champs.fetch(:siret) }
|
||||||
end
|
end
|
||||||
|
factory :type_de_champ_iban do
|
||||||
|
type_champ { TypeDeChamp.type_champs.fetch(:iban) }
|
||||||
|
end
|
||||||
factory :type_de_champ_carte do
|
factory :type_de_champ_carte do
|
||||||
type_champ { TypeDeChamp.type_champs.fetch(:carte) }
|
type_champ { TypeDeChamp.type_champs.fetch(:carte) }
|
||||||
end
|
end
|
||||||
|
|
12
spec/models/champs/iban_champ_spec.rb
Normal file
12
spec/models/champs/iban_champ_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
describe Champs::IbanChamp do
|
||||||
|
describe '#valid?' do
|
||||||
|
it do
|
||||||
|
expect(build(:champ_iban, value: nil)).to be_valid
|
||||||
|
expect(build(:champ_iban, value: "FR35 KDSQFDJQSMFDQMFDQ")).to_not be_valid
|
||||||
|
expect(build(:champ_iban, value: "FR7630006000011234567890189")).to be_valid
|
||||||
|
expect(build(:champ_iban, value: "FR76 3000 6000 0112 3456 7890 189")).to be_valid
|
||||||
|
expect(build(:champ_iban, value: "FR76 3000 6000 0112 3456 7890 189DSF")).to_not be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -74,6 +74,7 @@ describe ProcedureExportService do
|
||||||
"siret",
|
"siret",
|
||||||
"carte",
|
"carte",
|
||||||
"titre_identite",
|
"titre_identite",
|
||||||
|
"iban",
|
||||||
"text"
|
"text"
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
@ -158,6 +159,7 @@ describe ProcedureExportService do
|
||||||
"siret",
|
"siret",
|
||||||
"carte",
|
"carte",
|
||||||
"titre_identite",
|
"titre_identite",
|
||||||
|
"iban",
|
||||||
"text"
|
"text"
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
@ -238,6 +240,7 @@ describe ProcedureExportService do
|
||||||
"siret",
|
"siret",
|
||||||
"carte",
|
"carte",
|
||||||
"titre_identite",
|
"titre_identite",
|
||||||
|
"iban",
|
||||||
"text"
|
"text"
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue