Currently i am learning with the youtube video Efficient Rails Test Driven Development – by Wolfram Arnold
One exercise is:
A Person object has an optional middle_name.
I create a migration to add the middle name to the database
- rake g migration AddMiddleNameToPerson middle_name:string
and i write a spec
it “can have a middle name”
But i got no idea how to test this issue
how can i test an optional field
thanks for help
Bulleric
To say that an attribute is ‘optional’ implies that the instance is valid when the attribute is
nil. So:If you’re using shoulda then this can be made even simpler: