Skip to content

Commit 5fbbaf3

Browse files
committed
Ensure leading and trailing whitespace are removed from inputted Ghana license number
1 parent 3de52aa commit 5fbbaf3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

app/forms/teacher_interface/ghana_registration_number_form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def registration_number
4747
license_number_part_one,
4848
license_number_part_two,
4949
license_number_part_three,
50-
]
50+
].map(&:strip)
5151

5252
return nil if registration_number_parts.compact_blank.empty?
5353

spec/forms/teacher_interface/ghana_registration_number_form_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
it { is_expected.to be_invalid }
4242
end
4343

44+
context "with license number parts having spaces in the end" do
45+
let(:license_number_part_one) { " PT " }
46+
let(:license_number_part_two) { "123456 " }
47+
let(:license_number_part_three) { " 1234" }
48+
49+
it { is_expected.to be_valid }
50+
end
51+
4452
context "with valid parts" do
4553
let(:license_number_part_one) { "PT" }
4654
let(:license_number_part_two) { "123456" }
@@ -65,6 +73,20 @@
6573
end
6674
end
6775

76+
context "with license number parts having spaces in the end" do
77+
subject(:save) { form.save(validate: true) }
78+
79+
let(:license_number_part_one) { " PT " }
80+
let(:license_number_part_two) { "123456 " }
81+
let(:license_number_part_three) { " 1234" }
82+
83+
it "sets the registration number to the string without spaces" do
84+
expect { save }.to change(application_form, :registration_number).to(
85+
"PT/123456/1234",
86+
)
87+
end
88+
end
89+
6890
context "with invalid parts" do
6991
subject(:save) { form.save(validate: false) }
7092

0 commit comments

Comments
 (0)