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

Local census records fixes #3773

Merged

Conversation

Senen
Copy link
Member

@Senen Senen commented Oct 17, 2019

References

Related pull request: #3479, #3500
Closes #3742

Objectives

Regarding LocalCensusRecord CRUD interface
Display a select with allowed document types in place of a text field to make easier to users to create correct local census records.

Regarding local census records import
Add a validation to detect invalid document_types provided through the CSV import process.

Visual Changes

Regarding LocalCensusRecord CRUD interface

To check previous version screenshots got to #3479.

Captura de pantalla 2019-10-17 a las 16 18 56

Regarding local census records import

To check previous version screenshots got to #3500.

Captura de pantalla 2019-10-17 a las 16 35 57

Notes

None

@javierm javierm added this to Reviewing in Roadmap via automation Oct 17, 2019
before_validation :sanitize

validates :document_number, presence: true
validates :document_type, presence: true
validates :document_type, inclusion: { in: ALLOWED_DOCUMENT_TYPES.values },
if: -> { document_type.present? }
Copy link
Member

Choose a reason for hiding this comment

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

Just curious: why is this if condition necessary? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question @javierm, what i was trying to do is to not validate inclussion when document_type is empty, but i think a better way to do the same should be to use allow_blank validation option to achieve the same.

validates :document_type, presence: true, inclusion: { in: ALLOWED_DOCUMENT_TYPES.values, allow_blank: true }

The inclussion validation is only needed when running import of local census records or if anyone is creating records from rails console, to help the user to understand what values are the accepted ones. This problems does not exists when an administrator creates local census records through the web interface cause we are forcing to select document_typefrom correct values always.

What do you think? Maybe you prefer to run both validation always?

Copy link
Member Author

Choose a reason for hiding this comment

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

Finally update inclussion validation with allow_blank option set to true in place of using an if condition.

Copy link
Member

@javierm javierm Nov 7, 2019

Choose a reason for hiding this comment

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

I've just realized document_type cannot be empty because the line above this one says:

 validates :document_type, presence: true

So the allow_blank option doesn't seem necessary 🤔. I've tried creating a record without a document type and I get a validation error because of the presence condition.

So what do you think about:

 validates :document_type, presence: true, inclusion: { in: ["1", "2", "3"] }

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, of course, but there is a little difference between both versions. Without allow_blank option model will have 2 validation errors when the document_type is empty, the will see:

  1. can't be blank
    2 is not included in the list, allowed values are 1 for DNI, 2 for Passport and 3 for Residence Card

When the allow_blank option is present and set to true the user will see only one validation error at a time.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting! I didn't know that.

app/models/local_census_record.rb Outdated Show resolved Hide resolved
config/locales/en/activerecord.yml Outdated Show resolved Hide resolved
@javierm javierm moved this from Reviewing to Doing in Roadmap Oct 21, 2019
@javierm javierm moved this from Doing to Reviewing in Roadmap Oct 22, 2019
@javierm javierm moved this from Reviewing to Doing in Roadmap Oct 22, 2019
@javierm javierm self-assigned this Oct 22, 2019
@Senen Senen force-pushed the local-census-records-fixes branch 6 times, most recently from f248a6b to 157ef91 Compare November 7, 2019 15:23
* Add custom message for inclusion validation to include the allowed values.
* Force user to choose document_type from select lik the one shown at verification form.
* Convert stored document_type to a human readable text
@javierm javierm moved this from Doing to Reviewing in Roadmap Nov 7, 2019
@javierm javierm moved this from Reviewing to Doing in Roadmap Nov 7, 2019
Roadmap automation moved this from Doing to Testing Nov 8, 2019
@javierm javierm merged commit 943f2d9 into consuldemocracy:master Nov 8, 2019
Roadmap automation moved this from Testing to Release 1.1.0 Nov 8, 2019
smarques pushed a commit to venetochevogliamo/consul that referenced this pull request Apr 29, 2020
…records-fixes

Local census records fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Roadmap
  
Release 1.1.0
Development

Successfully merging this pull request may close these issues.

Can't verify users using only the local census
2 participants