|
58 | 58 | expect(question.show_answer_in_csv).to eq({ "#{question_text} - Full name" => name }) |
59 | 59 | end |
60 | 60 | end |
| 61 | + |
| 62 | + describe "length validation" do |
| 63 | + it "is valid with length under 500 characters" do |
| 64 | + question.full_name = "a" * 499 |
| 65 | + expect(question).to be_valid |
| 66 | + expect(question.errors[:full_name]).to be_empty |
| 67 | + end |
| 68 | + |
| 69 | + it "is invalid with length over 499 characters" do |
| 70 | + question.full_name = "a" * 500 |
| 71 | + expect(question).not_to be_valid |
| 72 | + expect(question.errors[:full_name]).to include(I18n.t("activemodel.errors.models.question/name.attributes.full_name.too_long")) |
| 73 | + end |
| 74 | + end |
61 | 75 | end |
62 | 76 |
|
63 | 77 | context "when the name question is in first and last name format" do |
|
147 | 161 | }) |
148 | 162 | end |
149 | 163 | end |
| 164 | + |
| 165 | + describe "length validation" do |
| 166 | + before do |
| 167 | + question.first_name = "a" * 499 |
| 168 | + question.last_name = "a" * 499 |
| 169 | + end |
| 170 | + |
| 171 | + it "is valid when all fields have the maximum allowed length" do |
| 172 | + expect(question).to be_valid |
| 173 | + expect(question.errors).to be_empty |
| 174 | + end |
| 175 | + |
| 176 | + it "is invalid when the first name is over 499 characters" do |
| 177 | + question.first_name = "a" * 500 |
| 178 | + expect(question).not_to be_valid |
| 179 | + expect(question.errors[:first_name]).to include(I18n.t("activemodel.errors.models.question/name.attributes.first_name.too_long")) |
| 180 | + end |
| 181 | + |
| 182 | + it "is invalid when the last name is over 499 characters" do |
| 183 | + question.last_name = "a" * 500 |
| 184 | + expect(question).not_to be_valid |
| 185 | + expect(question.errors[:last_name]).to include(I18n.t("activemodel.errors.models.question/name.attributes.last_name.too_long")) |
| 186 | + end |
| 187 | + end |
150 | 188 | end |
151 | 189 |
|
152 | 190 | context "when the name question is in first, middle and last name format" do |
|
215 | 253 | }) |
216 | 254 | end |
217 | 255 | end |
| 256 | + |
| 257 | + describe "length validation" do |
| 258 | + before do |
| 259 | + question.first_name = "a" * 499 |
| 260 | + question.middle_names = "a" * 499 |
| 261 | + question.last_name = "a" * 499 |
| 262 | + end |
| 263 | + |
| 264 | + it "is valid when all fields have the maximum allowed length" do |
| 265 | + expect(question).to be_valid |
| 266 | + expect(question.errors).to be_empty |
| 267 | + end |
| 268 | + |
| 269 | + it "is invalid when the first name is over 499 characters" do |
| 270 | + question.first_name = "a" * 500 |
| 271 | + expect(question).not_to be_valid |
| 272 | + expect(question.errors[:first_name]).to include(I18n.t("activemodel.errors.models.question/name.attributes.first_name.too_long")) |
| 273 | + end |
| 274 | + |
| 275 | + it "is invalid when the middle name is over 499 characters" do |
| 276 | + question.middle_names = "a" * 500 |
| 277 | + expect(question).not_to be_valid |
| 278 | + expect(question.errors[:middle_names]).to include(I18n.t("activemodel.errors.models.question/name.attributes.middle_names.too_long")) |
| 279 | + end |
| 280 | + |
| 281 | + it "is invalid when the last name is over 499 characters" do |
| 282 | + question.last_name = "a" * 500 |
| 283 | + expect(question).not_to be_valid |
| 284 | + expect(question.errors[:last_name]).to include(I18n.t("activemodel.errors.models.question/name.attributes.last_name.too_long")) |
| 285 | + end |
| 286 | + end |
218 | 287 | end |
219 | 288 |
|
220 | 289 | context "when title_needed is set to true" do |
|
0 commit comments