-
-
Notifications
You must be signed in to change notification settings - Fork 910
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 more tests to the validate_numericality_of error message #699
Changes from 3 commits
84b7175
4c1013f
d8d7784
2dc787e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -505,51 +505,93 @@ def default_validation_values | |
even: true, | ||
greater_than: 18 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
only_integer. | ||
is_greater_than(18) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
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. Align the operands of an expression in an assignment spanning multiple lines. |
||
only_integer. | ||
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. Align the operands of an expression in an assignment spanning multiple lines. |
||
is_greater_than(18) | ||
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. Align the operands of an expression in an assignment spanning multiple lines. |
||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be an integer" when attr is set to 0.1, | ||
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. Line is too long. [82/80] |
||
got errors: | ||
* "must be even" (attribute: attr, value: "19") | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
record = build_record_validating_numericality(greater_than: 18) | ||
expect(record). | ||
not_to validate_numericality. | ||
only_integer. | ||
is_greater_than(18) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
only_integer. | ||
is_greater_than(18) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be an integer" when attr is set to 0.1, | ||
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. Line is too long. [82/80] |
||
got no errors | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
record = build_record_validating_numericality( | ||
even: true, | ||
greater_than_or_equal_to: 18 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
even. | ||
is_greater_than(18) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
even. | ||
is_greater_than(18) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be greater than 18" when attr is set to 18, | ||
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. Line is too long. [86/80] |
||
got no errors | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
record = build_record_validating_numericality( | ||
odd: true, | ||
greater_than: 18 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
even. | ||
is_greater_than(18) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
even. | ||
is_greater_than(18) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be even" when attr is set to 1, | ||
got errors: | ||
* "must be odd" (attribute: attr, value: "20") | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
record = build_record_validating_numericality( | ||
odd: true, | ||
greater_than_or_equal_to: 99 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
odd. | ||
is_less_than_or_equal_to(99) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
odd. | ||
is_less_than_or_equal_to(99) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be less than or equal to 99" when attr is set to 101, | ||
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. Line is too long. [96/80] |
||
got no errors | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
|
@@ -558,11 +600,19 @@ def default_validation_values | |
greater_than_or_equal_to: 18, | ||
less_than: 99 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
only_integer. | ||
is_greater_than(18). | ||
is_less_than(99) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
only_integer. | ||
is_greater_than(18). | ||
is_less_than(99) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be greater than 18" when attr is set to 18, | ||
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. Line is too long. [86/80] |
||
got no errors | ||
MESSAGE | ||
) | ||
end | ||
end | ||
|
||
|
@@ -572,65 +622,116 @@ def default_validation_values | |
only_integer: true, | ||
greater_than: 19 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
only_integer. | ||
is_greater_than(18) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
only_integer. | ||
is_greater_than(18) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be greater than 18" when attr is set to 18, | ||
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. Line is too long. [86/80] |
||
got errors: | ||
* "must be greater than 19" (attribute: attr, value: "19") | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
record = build_record_validating_numericality( | ||
only_integer: true, | ||
greater_than: 17 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
only_integer. | ||
is_greater_than(18) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
only_integer. | ||
is_greater_than(18) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be greater than 18" when attr is set to 18, | ||
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. Line is too long. [86/80] |
||
got no errors | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
record = build_record_validating_numericality( | ||
even: true, | ||
greater_than: 20 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
even. | ||
is_greater_than(18) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
even. | ||
is_greater_than(18) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be greater than 18" when attr is set to 18, | ||
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. Line is too long. [86/80] |
||
got errors: | ||
* "must be greater than 20" (attribute: attr, value: "20") | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
record = build_record_validating_numericality( | ||
even: true, | ||
greater_than: 16 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
even. | ||
is_greater_than(18) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
even. | ||
is_greater_than(18) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be greater than 18" when attr is set to 18, | ||
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. Line is too long. [86/80] |
||
got no errors | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
record = build_record_validating_numericality( | ||
odd: true, | ||
less_than_or_equal_to: 101 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
odd. | ||
is_less_than_or_equal_to(99) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
odd. | ||
is_less_than_or_equal_to(99) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be less than or equal to 99" when attr is set to 101, | ||
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. Line is too long. [96/80] |
||
got no errors | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
record = build_record_validating_numericality( | ||
odd: true, | ||
less_than_or_equal_to: 97 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
odd. | ||
is_less_than_or_equal_to(99) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
odd. | ||
is_less_than_or_equal_to(99) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be less than or equal to 99" when attr is set to 101, | ||
got errors: | ||
* "must be less than or equal to 97" (attribute: attr, value: "101") | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
|
@@ -639,11 +740,20 @@ def default_validation_values | |
greater_than: 19, | ||
less_than: 99 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
only_integer. | ||
is_greater_than(18). | ||
is_less_than(99) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
only_integer. | ||
is_greater_than(18). | ||
is_less_than(99) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be greater than 18" when attr is set to 18, | ||
got errors: | ||
* "must be less than 99" (attribute: attr, value: "100") | ||
MESSAGE | ||
) | ||
end | ||
|
||
it do | ||
|
@@ -652,11 +762,20 @@ def default_validation_values | |
greater_than: 18, | ||
less_than: 100 | ||
) | ||
expect(record). | ||
not_to validate_numericality. | ||
only_integer. | ||
is_greater_than(18). | ||
is_less_than(99) | ||
assertion = lambda do | ||
expect(record). | ||
to validate_numericality. | ||
only_integer. | ||
is_greater_than(18). | ||
is_less_than(99) | ||
end | ||
expect(&assertion).to fail_with_message( | ||
<<-MESSAGE.strip_heredoc | ||
Expected errors to include "must be less than 99" when attr is set to 100, | ||
got errors: | ||
* "must be less than 100" (attribute: attr, value: "100") | ||
MESSAGE | ||
) | ||
end | ||
end | ||
end | ||
|
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.
And this change was to specifically fix maurogeorge@84b7175#diff-d7c315235a16eb29151b8251207fbd67R539, correct?
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.
Right!
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.
This still seems odd to me, I'm investigating why we have to do this. Seems odd that the record has error messages but then it's valid at the same time.