mirror of
https://github.com/activerecord-hackery/ransack.git
synced 2022-11-09 13:47:45 -05:00
Tell if a condition is negative
This commit is contained in:
parent
235eae3b82
commit
3df134e08e
3 changed files with 17 additions and 0 deletions
|
@ -247,6 +247,10 @@ module Ransack
|
|||
"Condition <#{data}>"
|
||||
end
|
||||
|
||||
def negative?
|
||||
predicate.negative?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_combinator?
|
||||
|
|
|
@ -74,5 +74,9 @@ module Ransack
|
|||
vals.any? { |v| validator.call(type ? v.cast(type) : v.value) }
|
||||
end
|
||||
|
||||
def negative?
|
||||
@name.include?("not_".freeze)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,6 +29,15 @@ module Ransack
|
|||
specify { expect(subject.values.size).to eq(2) }
|
||||
end
|
||||
|
||||
describe '#negative?' do
|
||||
let(:context) { Context.for(Person) }
|
||||
let(:eq) { Condition.extract(context, 'name_eq', 'A') }
|
||||
let(:not_eq) { Condition.extract(context, 'name_not_eq', 'A') }
|
||||
|
||||
specify { expect(not_eq.negative?).to be true }
|
||||
specify { expect(eq.negative?).to be false }
|
||||
end
|
||||
|
||||
context 'with an invalid predicate' do
|
||||
subject {
|
||||
Condition.extract(
|
||||
|
|
Loading…
Reference in a new issue