-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OSRA Branches #24
Conversation
class Branch < ActiveRecord::Base | ||
|
||
validates :name, presence: true | ||
validates :code, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 99} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaner:
numericality: { only_integer: true }, inclusion: 0..99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numericality
check isn't required since the database column is an integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its useful though if you wan't error messages etc. for free rather than the database just rejecting the data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also would be consistent if our philosophy is to validate everything possible in the model and to use the db as dumb storage
class Branch < ActiveRecord::Base | ||
|
||
validates :name, presence: true | ||
validates :code, presence: true, numericality: { only_integer: true}, inclusion: 0..99 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is numericality: { only_integer: true}
required? The database column in already an integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a quick test. Without numericality: { only_integer: true}
you can assign a character string for instance to the code and it will saved in the db as 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need it anyway. The discussion were having about whether we do additional db validations creates at least one common theme amongst everyone.
The models should be the one source of truth. Leaving the integer declaration out seems to me to contravene that.
Please rebase with latest code. |
…lper This was newly introduced in Rails 4.1: https://relishapp.com/rspec/rspec-rails/v/3-0/docs/upgrade#pending-migration-checks
8941e43
to
7eddc72
Compare
PT Story: https://www.pivotaltracker.com/story/show/77972984