I am testing with rspecs on model
u = User.create(email: 'asd@we.com', password: 'asdasdasd', admin: true, firstname: 'qwe', lastname: 'wer', grade: 5, section: 'w', role: 'teacher')
expect(u).to be_valid
but it raises an exception if role is set to a random value for example "principal" this happens because role is an enum with two possible values "student" and "teacher"
So in this case i cannot use expect(u).to be_valid. I have to catch the exception. The error it throws is
ArgumentError:
'principal' is not a valid role
So i am wondering what other cases does .create throw an error instead of just populating the errors in model.errors. When should i catch errors? I appreciate any help! Thanks!
Aucun commentaire:
Enregistrer un commentaire