Skip to content
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 support to numericality: :other_than #1004

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -9,7 +9,8 @@ class ComparisonMatcher < ValidationMatcher
:>= => :greater_than_or_equal_to,
:< => :less_than,
:<= => :less_than_or_equal_to,
:== => :equal_to
:== => :equal_to,
:!= => :other_than
gmmcal marked this conversation as resolved.
Show resolved Hide resolved
}

def initialize(numericality_matcher, value, operator)
Expand Down Expand Up @@ -125,6 +126,8 @@ def assertions
[true, false, false]
when :<=
[true, true, false]
when :!=
[true, false, true]
end
end

Expand All @@ -146,6 +149,7 @@ def comparison_expectation
when :== then "equal to"
when :< then "less than"
when :<= then "less than or equal to"
when :!= then "other than"
gmmcal marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
Expand Down
Expand Up @@ -395,6 +395,11 @@ def is_less_than_or_equal_to(value)
self
end

def is_other_than(value)
gmmcal marked this conversation as resolved.
Show resolved Hide resolved
prepare_submatcher(comparison_matcher_for(value, :!=).for(@attribute))
self
end

def with_message(message)
@expects_custom_validation_message = true
@expected_message = message
Expand Down
Expand Up @@ -39,6 +39,13 @@ def all_qualifiers
validation_name: :equal_to,
validation_value: 1,
},
{
category: :comparison,
name: :is_other_than,
argument: 1,
validation_name: :other_than,
validation_value: 1,
},
{
category: :cardinality,
name: :odd,
Expand Down