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

Adding father_alive field to importer and fixtures #149

Closed

Conversation

motasem-salem
Copy link
Member

Jira story: https://osraav.atlassian.net/browse/OSRA-221

Jira tasks:
OSRA-224#Code-Review
OSRA-226#Code-Review

  • Added father_alive to pending_orphan model
  • Added father_alive column to importer yaml settings
  • Updated fixture files to new format
  • Added validation for father_alive, father_is_martyr and father_date_of_death values

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.0%) when pulling e0a5db0 on motasem-salem:update_importer into 1e669ae on AgileVentures:develop.

mandatory: false
type: String
- field: father_cause_of_death
column: G
column: H
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this makes me wonder how we can avoid the future pains of reformatting the entire importer config every time a change needs to be made. And as a more immediate concern: should there be a validation on the settings to ensure at least that the sequence of column names is not broken?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) when pulling 5bde386 on motasem-salem:update_importer into e1af236 on AgileVentures:develop.

validates :father_alive, inclusion: { in: [true, false] }, exclusion: { in: [nil] }
validates :father_alive, inclusion: { in: [false] }, exclusion: { in: [true] }, if: :father_is_martyr
validates :father_alive, inclusion: { in: [true] }, exclusion: { in: [false] }, if: 'father_date_of_death.nil?'
validates :father_alive, inclusion: { in: [false] }, exclusion: { in: [true] }, unless: 'father_date_of_death.nil?'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels awkward to me. What are peoples thoughts on this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does father_alive need to be in the db? Or could it be calculated as needed by a method from the other attributes
father_alive= !(father_is_martyr || father_date_of_death)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validates inclusion in: -> { [false, !(father_is_martyr || !(father_date_of_death.nil?)) ] }

This covers the edge case where he isn't alive, isn't martyr, and the date of death is unknown

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't inclusion: { in: [false] } automatically handle exclusion: { in: [anything else] }?
Would exclusion: { in: [nil] } not be better done with presence: true? (Right, right, Booleans. But is exclusion still necessary?)
Overall, I agree with the awkwardness - perhaps everything related to father's status would be better handled by a custom validator(s).
@theB264: I think it needs to be in the db to ensure record validity: if date of death is not recorded, does that mean that it's missing or that the father is alive? It seems that OSRA do not operate under the assumption that the date of death can be unknown. I would also prefer clarity over conciseness in the validation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nik :+1 for the explanation on why it needs to be in the db. I was going to reply with something similar to @theB264.

I started with a plan to write a custom validator that takes these 3 attributes (father_alive, father_is_martyr & father_date_of_death) and validates their value combination. But then I thought it might be better to use existing one-liner validations. This is the result (which I didn't like much). I submitted it to get your feedback.

I can take all of that out and have a custom validator which will be later used by pending_orphan and importer as well. What do you guys think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially if it's going to be reused by other models, extracting all this into a custom validator sounds like a terrific idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@motasem-salem Please see #162 and my WIP on the Father model. Perhaps at least some of this refactoring can be done now, and it would address the concerns raised here.

This was referenced Nov 26, 2014
@NikitaAvvakumov
Copy link
Member

Superseded by #179

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.

5 participants