Skip to content

Commit

Permalink
Add more tests to the validate_numericality_of error message
Browse files Browse the repository at this point in the history
  • Loading branch information
maurogeorge committed Apr 10, 2015
1 parent 9748869 commit 5710a64
Showing 1 changed file with 228 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,22 @@ def default_validation_values
is_greater_than(18)
end

it do
record = build_record_validating_numericality(
even: true,
greater_than: 18
)
assertion = lambda do
expect(record).
to validate_numericality.
only_integer.
is_greater_than(18)
end
expect(&assertion).to fail_with_message_including(
'* "must be even" (attribute: attr, value: "19")'
)
end

it do
record = build_record_validating_numericality(greater_than: 18)
expect(record).
Expand All @@ -519,6 +535,20 @@ def default_validation_values
is_greater_than(18)
end

it do
skip 'Need to be fixed the code, actually do not have the right message'
record = build_record_validating_numericality(greater_than: 18)
assertion = lambda do
expect(record).
to validate_numericality.
only_integer.
is_greater_than(18)
end
expect(&assertion).to fail_with_message_including(
''
)
end

it do
record = build_record_validating_numericality(
even: true,
Expand All @@ -530,6 +560,22 @@ def default_validation_values
is_greater_than(18)
end

it do
record = build_record_validating_numericality(
even: true,
greater_than_or_equal_to: 18
)
assertion = lambda do
expect(record).
to validate_numericality.
even.
is_greater_than(18)
end
expect(&assertion).to fail_with_message_including(
%{Expected errors to include "must be greater than 18" when attr is set to 18,\ngot no errors}
)
end

it do
record = build_record_validating_numericality(
odd: true,
Expand All @@ -541,6 +587,22 @@ def default_validation_values
is_greater_than(18)
end

it do
record = build_record_validating_numericality(
odd: true,
greater_than: 18
)
assertion = lambda do
expect(record).
to validate_numericality.
even.
is_greater_than(18)
end
expect(&assertion).to fail_with_message_including(
'* "must be odd" (attribute: attr, value: "20")'
)
end

it do
record = build_record_validating_numericality(
odd: true,
Expand All @@ -552,6 +614,22 @@ def default_validation_values
is_less_than_or_equal_to(99)
end

it do
record = build_record_validating_numericality(
odd: true,
greater_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_including(
%{Expected errors to include "must be less than or equal to 99" when attr is set to 101,\ngot no errors}
)
end

it do
record = build_record_validating_numericality(
only_integer: true,
Expand All @@ -564,6 +642,24 @@ def default_validation_values
is_greater_than(18).
is_less_than(99)
end

it do
record = build_record_validating_numericality(
only_integer: true,
greater_than_or_equal_to: 18,
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_including(
%{Expected errors to include "must be greater than 18" when attr is set to 18,\ngot no errors}
)
end
end

context 'when qualifiers match the validation options but the values are different' do
Expand All @@ -578,6 +674,22 @@ def default_validation_values
is_greater_than(18)
end

it do
record = build_record_validating_numericality(
only_integer: true,
greater_than: 19
)
assertion = lambda do
expect(record).
to validate_numericality.
only_integer.
is_greater_than(18)
end
expect(&assertion).to fail_with_message_including(
'* "must be greater than 19" (attribute: attr, value: "19")'
)
end

it do
record = build_record_validating_numericality(
only_integer: true,
Expand All @@ -589,6 +701,22 @@ def default_validation_values
is_greater_than(18)
end

it do
record = build_record_validating_numericality(
only_integer: true,
greater_than: 17
)
assertion = lambda do
expect(record).
to validate_numericality.
only_integer.
is_greater_than(18)
end
expect(&assertion).to fail_with_message_including(
%{Expected errors to include "must be greater than 18" when attr is set to 18,\ngot no errors}
)
end

it do
record = build_record_validating_numericality(
even: true,
Expand All @@ -600,6 +728,22 @@ def default_validation_values
is_greater_than(18)
end

it do
record = build_record_validating_numericality(
even: true,
greater_than: 20
)
assertion = lambda do
expect(record).
to validate_numericality.
even.
is_greater_than(18)
end
expect(&assertion).to fail_with_message_including(
'* "must be greater than 20" (attribute: attr, value: "20")'
)
end

it do
record = build_record_validating_numericality(
even: true,
Expand All @@ -611,6 +755,22 @@ def default_validation_values
is_greater_than(18)
end

it do
record = build_record_validating_numericality(
even: true,
greater_than: 16
)
assertion = lambda do
expect(record).
to validate_numericality.
even.
is_greater_than(18)
end
expect(&assertion).to fail_with_message_including(
%{Expected errors to include "must be greater than 18" when attr is set to 18,\ngot no errors}
)
end

it do
record = build_record_validating_numericality(
odd: true,
Expand All @@ -622,6 +782,22 @@ def default_validation_values
is_less_than_or_equal_to(99)
end

it do
record = build_record_validating_numericality(
odd: true,
less_than_or_equal_to: 101
)
assertion = lambda do
expect(record).
to validate_numericality.
odd.
is_less_than_or_equal_to(99)
end
expect(&assertion).to fail_with_message_including(
%{Expected errors to include "must be less than or equal to 99" when attr is set to 101,\ngot no errors}
)
end

it do
record = build_record_validating_numericality(
odd: true,
Expand All @@ -633,6 +809,22 @@ def default_validation_values
is_less_than_or_equal_to(99)
end

it do
record = build_record_validating_numericality(
odd: true,
less_than_or_equal_to: 97
)
assertion = lambda do
expect(record).
to validate_numericality.
odd.
is_less_than_or_equal_to(99)
end
expect(&assertion).to fail_with_message_including(
'* "must be less than or equal to 97" (attribute: attr, value: "101")'
)
end

it do
record = build_record_validating_numericality(
only_integer: true,
Expand All @@ -646,6 +838,24 @@ def default_validation_values
is_less_than(99)
end

it do
record = build_record_validating_numericality(
only_integer: true,
greater_than: 19,
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_including(
'* "must be less than 99" (attribute: attr, value: "100")'
)
end

it do
record = build_record_validating_numericality(
only_integer: true,
Expand All @@ -658,6 +868,24 @@ def default_validation_values
is_greater_than(18).
is_less_than(99)
end

it do
record = build_record_validating_numericality(
only_integer: true,
greater_than: 18,
less_than: 100
)
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_including(
'* "must be less than 100" (attribute: attr, value: "100")'
)
end
end
end

Expand Down

0 comments on commit 5710a64

Please sign in to comment.