|
147 | 147 | expect(duplicate_school).not_to be_valid |
148 | 148 | end |
149 | 149 |
|
| 150 | + it 'does not require a school_roll_number' do |
| 151 | + create(:school, id: SecureRandom.uuid, school_roll_number: nil) |
| 152 | + |
| 153 | + school.school_roll_number = nil |
| 154 | + expect(school).to be_valid |
| 155 | + end |
| 156 | + |
| 157 | + it 'requires school_roll_number to be unique if provided' do |
| 158 | + school.school_roll_number = '01572D' |
| 159 | + school.save! |
| 160 | + |
| 161 | + duplicate_school = build(:school, school_roll_number: '01572d') |
| 162 | + expect(duplicate_school).not_to be_valid |
| 163 | + end |
| 164 | + |
| 165 | + it 'accepts a valid alphanumeric school_roll_number' do |
| 166 | + school.school_roll_number = '01572D' |
| 167 | + expect(school).to be_valid |
| 168 | + end |
| 169 | + |
| 170 | + it 'accepts a school_roll_number with multiple letters' do |
| 171 | + school.school_roll_number = '12345ABC' |
| 172 | + expect(school).to be_valid |
| 173 | + end |
| 174 | + |
| 175 | + it 'rejects a school_roll_number with only numbers' do |
| 176 | + school.school_roll_number = '01572' |
| 177 | + expect(school).not_to be_valid |
| 178 | + expect(school.errors[:school_roll_number]).to include('must be alphanumeric (e.g., 01572D)') |
| 179 | + end |
| 180 | + |
| 181 | + it 'rejects a school_roll_number with only letters' do |
| 182 | + school.school_roll_number = 'ABCDE' |
| 183 | + expect(school).not_to be_valid |
| 184 | + expect(school.errors[:school_roll_number]).to include('must be alphanumeric (e.g., 01572D)') |
| 185 | + end |
| 186 | + |
| 187 | + it 'rejects a school_roll_number with special characters' do |
| 188 | + school.school_roll_number = '01572-D' |
| 189 | + expect(school).not_to be_valid |
| 190 | + expect(school.errors[:school_roll_number]).to include('must be alphanumeric (e.g., 01572D)') |
| 191 | + end |
| 192 | + |
| 193 | + it 'normalizes blank school_roll_number to nil' do |
| 194 | + school.school_roll_number = ' ' |
| 195 | + school.save |
| 196 | + expect(school.school_roll_number).to be_nil |
| 197 | + end |
| 198 | + |
150 | 199 | it 'requires an address_line_1' do |
151 | 200 | school.address_line_1 = ' ' |
152 | 201 | expect(school).not_to be_valid |
|
0 commit comments