Skip to content

Commit

Permalink
Start of thoughtbot#509
Browse files Browse the repository at this point in the history
  • Loading branch information
maurogeorge committed Apr 9, 2015
1 parent 9748869 commit 334131c
Showing 1 changed file with 96 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 Down

0 comments on commit 334131c

Please sign in to comment.