Skip to content

Commit

Permalink
Fix length validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pskl committed Feb 18, 2025
1 parent 1781e2b commit 3cdd5ff
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
17 changes: 12 additions & 5 deletions lib/asp/entities/adresse/indu_etranger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module Adresse
class InduEtranger < Entity
ADRESSE_ATTR_MAX_LENGTH = 38

attribute :localiteetranger, :string, limit: ADRESSE_ATTR_MAX_LENGTH
attribute :bureaudistribetranger, :string, limit: ADRESSE_ATTR_MAX_LENGTH
attribute :voiepointgeoetranger, :string, limit: ADRESSE_ATTR_MAX_LENGTH
attribute :districtetranger, :string, limit: ADRESSE_ATTR_MAX_LENGTH
attribute :regionetranger, :string, limit: ADRESSE_ATTR_MAX_LENGTH
attribute :localiteetranger, :string
attribute :bureaudistribetranger, :string
attribute :voiepointgeoetranger, :string
attribute :districtetranger, :string
attribute :regionetranger, :string
attribute :codetypeadr, :string
attribute :codeinseepays, :string

Expand All @@ -21,6 +21,13 @@ class InduEtranger < Entity
codeinseepays
]

validates_length_of :localiteetranger, maximum: ADRESSE_ATTR_MAX_LENGTH
validates_length_of :bureaudistribetranger, maximum: ADRESSE_ATTR_MAX_LENGTH

validates_length_of :voiepointgeoetranger, maximum: ADRESSE_ATTR_MAX_LENGTH, allow_nil: true
validates_length_of :districtetranger, maximum: ADRESSE_ATTR_MAX_LENGTH, allow_nil: true
validates_length_of :regionetranger, maximum: ADRESSE_ATTR_MAX_LENGTH, allow_nil: true

def self.payment_mapper_class
Mappers::Adresse::InduEtrangerMapper
end
Expand Down
7 changes: 5 additions & 2 deletions lib/asp/entities/adresse/indu_france.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module Adresse
class InduFrance < Entity
ADRESSE_ATTR_MAX_LENGTH = 38

attribute :pointremise, :string, limit: ADRESSE_ATTR_MAX_LENGTH
attribute :cpltdistribution, :string, limit: ADRESSE_ATTR_MAX_LENGTH
attribute :pointremise, :string
attribute :cpltdistribution, :string
attribute :codetypeadr, :string
attribute :codecominsee, :string
attribute :codeinseepays, :string
Expand All @@ -21,6 +21,9 @@ class InduFrance < Entity
codecominsee
]

validates_length_of :pointremise, maximum: ADRESSE_ATTR_MAX_LENGTH
validates_length_of :cpltdistribution, maximum: ADRESSE_ATTR_MAX_LENGTH, allow_nil: true

def self.payment_mapper_class
Mappers::Adresse::InduFranceMapper
end
Expand Down
20 changes: 16 additions & 4 deletions spec/lib/asp/entities/adresse/indu_etranger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

before do
pfmp.student.update(
address_line1: "A" * 50,
address_line2: "B" * 50,
address_line1: "A" * 38,
address_line2: "B" * 38,
address_city: "Cool City",
address_postal_code: 66666
address_postal_code: 66_666
)
end

Expand All @@ -27,7 +27,19 @@

it "uses the establishment details for the address" do # rubocop:disable RSpec/MultipleExpectations
expect(document.at("localiteetranger").text).to eq "Cool City"
expect(document.at("bureaudistribetranger").text).to eq 66666.to_s
expect(document.at("bureaudistribetranger").text).to eq 66_666.to_s
end

context "when the addresse is too long" do
before do
pfmp.student.update(
address_city: "A" * 50
)
end

it "errors" do
expect { document.to_s }.to raise_error ActiveModel::ValidationError
end
end
end
end
Expand Down
17 changes: 15 additions & 2 deletions spec/lib/asp/entities/adresse/indu_france_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

before do
pfmp.student.update(
address_line1: "A" * 50,
address_line2: "B" * 50
address_line1: "A" * 38,
address_line2: "B" * 38
)
end

Expand All @@ -29,6 +29,19 @@
expect(document.at("pointremise").text).to eq "A" * 38
expect(document.at("cpltdistribution").text).to eq "B" * 38
end

context "when the addresse is too long" do
before do
pfmp.student.update(
address_line1: "A" * 50,
address_line2: "B" * 50
)
end

it "errors" do
expect { document.to_s }.to raise_error ActiveModel::ValidationError
end
end
end
end
end

0 comments on commit 3cdd5ff

Please sign in to comment.