1
0
Fork 0
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:
Andrew Vit 2016-01-02 10:49:13 -08:00
parent 235eae3b82
commit 3df134e08e
3 changed files with 17 additions and 0 deletions

View file

@ -247,6 +247,10 @@ module Ransack
"Condition <#{data}>"
end
def negative?
predicate.negative?
end
private
def valid_combinator?

View file

@ -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

View file

@ -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(