prix-fixe

Expand History Expand History
Collapse History Collapse History

Validate presence of notes.content

This commit adds both model and controller coverage for validating that Note model is created with its required fields.

Extends the Note model to use the validates_presence_of validator by passing presence: true to the validates macro.

When validating a record without a content field, the presence: true validation’s failure supersedes the previous behavior of violating the column’s NOT NULL constraint and raising a ActiveRecord::NotNullViolation error. Since the two are not compatible, this commit removes the previous test coverage from notes_test.rb.

When responding to a POST /notes request that would result in an invalid Note record, our controller will re-render the notes#new to present the client with another opportunity to submit a Note. In addition, the controller will respond with a 422 HTTP Status to indicate to the client that the previous request was unprocessable entity.