File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -42,10 +42,12 @@ class Batch < ApplicationRecord
42
42
scope :not_expired ,
43
43
-> { where . not ( expiry : nil ) . where ( "expiry > ?" , Time . current ) }
44
44
45
+ NAME_FORMAT = /\A [A-Za-z0-9]+\z /
46
+
45
47
validates :name ,
46
48
presence : true ,
47
49
format : {
48
- with : / \A [A-Za-z0-9]+ \z /
50
+ with : NAME_FORMAT
49
51
} ,
50
52
length : {
51
53
minimum : 2 ,
Original file line number Diff line number Diff line change @@ -487,6 +487,8 @@ def validate_batch_name
487
487
if batch_name . present?
488
488
if batch_name . to_s . length > 100
489
489
errors . add ( batch_name . header , "is greater than 100 characters long" )
490
+ elsif batch_name . to_s !~ Batch ::NAME_FORMAT
491
+ errors . add ( batch_name . header , "must be only letters and numbers" )
490
492
end
491
493
elsif offline_recording?
492
494
if batch_name . nil?
Original file line number Diff line number Diff line change 190
190
end
191
191
end
192
192
193
+ context "with an invalid batch name" do
194
+ let ( :data ) { { "VACCINATED" => "Y" , "BATCH_NUMBER" => "[invalid]" } }
195
+
196
+ it "has errors" do
197
+ expect ( immunisation_import_row ) . to be_invalid
198
+ expect ( immunisation_import_row . errors [ "BATCH_NUMBER" ] ) . to eq (
199
+ [ "must be only letters and numbers" ]
200
+ )
201
+ end
202
+ end
203
+
193
204
context "with an invalid postcode" do
194
205
let ( :data ) { { "PERSON_POSTCODE" => "ABC DEF" } }
195
206
You can’t perform that action at this time.
0 commit comments