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
multiple_of for Numericality #7213
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -113,6 +113,13 @@ def test_validates_numericality_with_other_than | ||
valid!([-1, 42]) | valid!([-1, 42]) | ||
end | end | ||
|
|
||
def test_validates_numericality_with_multiple_of | |||
Topic.validates_numericality_of :approved, :multiple_of => 2 | |||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, use 1.9 hash syntax. Thanks :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this PR still under consideration? I'll update if it has a chance to be pulled in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's not closed, it's under consideration. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently it got closed right after @frodsan asked about this. |
|||
|
|||
invalid!([1, 1.1]) | |||
valid!([4, 8.0]) | |||
end | |||
|
|||
def test_validates_numericality_with_proc | def test_validates_numericality_with_proc | ||
Topic.send(:define_method, :min_approved, lambda { 5 }) | Topic.send(:define_method, :min_approved, lambda { 5 }) | ||
Topic.validates_numericality_of :approved, :greater_than_or_equal_to => Proc.new {|topic| topic.min_approved } | Topic.validates_numericality_of :approved, :greater_than_or_equal_to => Proc.new {|topic| topic.min_approved } | ||
|
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.
not sure but maybe it make sense to use
multiple_of
method fromActiveSupport
? https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/integer/multiple.rbThere 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 would be fine with that by #multiple_of is only supported on
Integer
right now. Modulo works with floats as well.