Skip to content
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

Merged
merged 8 commits into from
Sep 7, 2014
Merged

Conversation

motasem-salem
Copy link
Member

PT Story: https://www.pivotaltracker.com/story/show/77972984

  • Added Branch model and seed data
  • Added Branch specs and factory
  • Added relationship between Sponsor and Branch

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}
Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

@sampritipanda
Copy link
Member

Please rebase with latest code.

sampritipanda added a commit that referenced this pull request Sep 7, 2014
@sampritipanda sampritipanda merged commit 0083476 into AgileVentures:develop Sep 7, 2014
@motasem-salem motasem-salem deleted the branches branch October 26, 2014 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants