Skip to content

Check valid options in numericality validator#32675

Closed
rfrm wants to merge 2 commits intorails:masterfrom
rfrm:rfrm/check-valid-options-in-numericality-validator
Closed

Check valid options in numericality validator#32675
rfrm wants to merge 2 commits intorails:masterfrom
rfrm:rfrm/check-valid-options-in-numericality-validator

Conversation

@rfrm
Copy link

@rfrm rfrm commented Apr 21, 2018

Invalid options should not be ignored by the validator:

  class User
    include ActiveModel::Validations

    validates_numericality_of :argument, :greather_than_or_equal_to: 0
  end

The previous model would allow negative values because of the option misspelling.
Add a check to ensure valid options are passed to the validator.

Invalid options should not be ignored by the validator:

      class User
        include ActiveModel::Validations

        validates_numericality_of :argument, :greather_than_or_equal_to: 0
      end

The previous model will allow negative values because of
the option misspelling.
@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@georgewambold
Copy link
Contributor

Do you think assert_valid_keys (https://apidock.com/rails/Hash/assert_valid_keys) would be more concise for checking VALID_OPTIONS?

Copy link
Member

@eileencodes eileencodes left a comment

Choose a reason for hiding this comment

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

Hey @rfrm thanks for the PR!

This is causing a fair amount of tests to fail https://travis-ci.org/rails/rails/jobs/369400417#L1569. Can you take a look?

Once you fix the tests can you squash your commits into one? Thanks!

@rails-bot
Copy link

rails-bot bot commented Dec 18, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Dec 18, 2019
@eileencodes
Copy link
Member

Failing tests were never addressed so I'm going to close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants