Skip to content

Commit

Permalink
Le code postal ne doit comporter que des chiffres
Browse files Browse the repository at this point in the history
Co-authored-by: Clément Prod’homme <[email protected]>
  • Loading branch information
MarineSourin authored and cprodhomme committed Aug 9, 2021
1 parent d7d7ddd commit 03b9711
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/anonymisation/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Anonymisation
class Structure < Anonymisation::Base
def anonymise
super do |structure|
structure.code_postal = 'Non communiqué' if structure.code_postal.nil?
structure.code_postal = ::Structure::TYPE_NON_COMMUNIQUE if structure.code_postal.nil?
structure.nom = FFaker::Company.name
end
end
Expand Down
9 changes: 7 additions & 2 deletions app/models/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ class Structure < ApplicationRecord
organisme_formation orientation_scolaire cap_emploi e2c SMA autre
].freeze

TYPE_NON_COMMUNIQUE = 'non_communique'

validates :nom, :code_postal, :type_structure, presence: true
validates :type_structure, inclusion: { in: (TYPES_STRUCTURES + ['non_communique']) }
validates :type_structure, inclusion: { in: (TYPES_STRUCTURES + [TYPE_NON_COMMUNIQUE]) }
validates :code_postal, numericality: { only_integer: true }, length: { is: 5 },
unless: proc { |s| s.code_postal == TYPE_NON_COMMUNIQUE }

auto_strip_attributes :nom, :code_postal, squish: true
auto_strip_attributes :nom, squish: true
auto_strip_attributes :code_postal, delete_whitespaces: true

geocoded_by :code_postal, state: :region, params: { countrycodes: 'fr' } do |obj, resultats|
if (resultat = resultats.first)
Expand Down
2 changes: 1 addition & 1 deletion spec/integrations/anonymisation/structure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Anonymisation::Structure.new(structure).anonymise

structure.reload
expect(structure.code_postal).to eql('Non communiqué')
expect(structure.code_postal).to eql('non_communique')
end
end
end
13 changes: 13 additions & 0 deletions spec/models/structure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
it { should validate_presence_of(:nom) }
it { should validate_presence_of(:code_postal) }
it { should validate_presence_of(:type_structure) }
it { should validate_numericality_of(:code_postal) }
it { should validate_length_of(:code_postal).is_equal_to(5) }

it do
types_structures = %w[
mission_locale pole_emploi SIAE service_insertion_collectivite CRIA
Expand All @@ -19,6 +22,16 @@
.display_name).to eql('eva - 75012')
end

it "Le code postal ne peut pas comporter d'espaces" do
structure = described_class.create(nom: 'eva', code_postal: '75 01 2 ')
expect(structure.code_postal).to eq('75012')
end

it 'Accepte les codes postaux commençant par 0' do
structure = described_class.create(nom: 'eva', code_postal: '01000')
expect(structure.code_postal).to eq('01000')
end

describe 'géolocalisation à la validation' do
let(:structure) { Structure.new code_postal: '75012' }
before do
Expand Down

0 comments on commit 03b9711

Please sign in to comment.