allowing ':wants_array' to be passed as 'false' in predicate options
This commit is contained in:
parent
54932a4705
commit
0abaab4b1e
|
@ -1,5 +1,10 @@
|
||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
* Allowing `:wants_array` to be set to `false` in the predicate options.
|
||||||
|
([#32](https://github.com/activerecord-hackery/ransack/issues/32))
|
||||||
|
|
||||||
|
*Michael Pavling*
|
||||||
|
|
||||||
## Version 1.6.4 - 2015-03-20
|
## Version 1.6.4 - 2015-03-20
|
||||||
|
|
||||||
* ActionView patch to maintain compatibility with Rails 4.2.1 released today.
|
* ActionView patch to maintain compatibility with Rails 4.2.1 released today.
|
||||||
|
|
|
@ -48,8 +48,8 @@ module Ransack
|
||||||
@validator = opts[:validator] ||
|
@validator = opts[:validator] ||
|
||||||
lambda { |v| v.respond_to?(:empty?) ? !v.empty? : !v.nil? }
|
lambda { |v| v.respond_to?(:empty?) ? !v.empty? : !v.nil? }
|
||||||
@compound = opts[:compound]
|
@compound = opts[:compound]
|
||||||
@wants_array = opts[:wants_array] == true || @compound ||
|
@wants_array = opts.fetch(:wants_array,
|
||||||
Constants::IN_NOT_IN.include?(@arel_predicate)
|
@compound || Constants::IN_NOT_IN.include?(@arel_predicate))
|
||||||
end
|
end
|
||||||
|
|
||||||
def eql?(other)
|
def eql?(other)
|
||||||
|
|
|
@ -62,5 +62,41 @@ module Ransack
|
||||||
expect(Ransack.predicates).not_to have_key 'test_array_predicate_any'
|
expect(Ransack.predicates).not_to have_key 'test_array_predicate_any'
|
||||||
expect(Ransack.predicates).not_to have_key 'test_array_predicate_all'
|
expect(Ransack.predicates).not_to have_key 'test_array_predicate_all'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '`wants_array` option takes precedence over Arel predicate' do
|
||||||
|
it 'implicitly wants an array for in/not in predicates' do
|
||||||
|
Ransack.configure do |config|
|
||||||
|
config.add_predicate(
|
||||||
|
:test_in_predicate,
|
||||||
|
:arel_predicate => 'in'
|
||||||
|
)
|
||||||
|
config.add_predicate(
|
||||||
|
:test_not_in_predicate,
|
||||||
|
:arel_predicate => 'not_in'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(Ransack.predicates['test_in_predicate'].wants_array).to eq true
|
||||||
|
expect(Ransack.predicates['test_not_in_predicate'].wants_array).to eq true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'explicitly does not want array for in/not_in predicates' do
|
||||||
|
Ransack.configure do |config|
|
||||||
|
config.add_predicate(
|
||||||
|
:test_in_predicate_no_array,
|
||||||
|
:arel_predicate => 'in',
|
||||||
|
:wants_array => false
|
||||||
|
)
|
||||||
|
config.add_predicate(
|
||||||
|
:test_not_in_predicate_no_array,
|
||||||
|
:arel_predicate => 'not_in',
|
||||||
|
:wants_array => false
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(Ransack.predicates['test_in_predicate_no_array'].wants_array).to eq false
|
||||||
|
expect(Ransack.predicates['test_not_in_predicate_no_array'].wants_array).to eq false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,5 +64,41 @@ module Ransack
|
||||||
expect(Ransack.predicates).not_to have_key 'test_array_predicate_any'
|
expect(Ransack.predicates).not_to have_key 'test_array_predicate_any'
|
||||||
expect(Ransack.predicates).not_to have_key 'test_array_predicate_all'
|
expect(Ransack.predicates).not_to have_key 'test_array_predicate_all'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '`wants_array` option takes precedence over Arel predicate' do
|
||||||
|
it 'implicitly wants an array for in/not in predicates' do
|
||||||
|
Ransack.configure do |config|
|
||||||
|
config.add_predicate(
|
||||||
|
:test_in_predicate,
|
||||||
|
:arel_predicate => 'in'
|
||||||
|
)
|
||||||
|
config.add_predicate(
|
||||||
|
:test_not_in_predicate,
|
||||||
|
:arel_predicate => 'not_in'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(Ransack.predicates['test_in_predicate'].wants_array).to eq true
|
||||||
|
expect(Ransack.predicates['test_not_in_predicate'].wants_array).to eq true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'explicitly does not want array for in/not_in predicates' do
|
||||||
|
Ransack.configure do |config|
|
||||||
|
config.add_predicate(
|
||||||
|
:test_in_predicate_no_array,
|
||||||
|
:arel_predicate => 'in',
|
||||||
|
:wants_array => false
|
||||||
|
)
|
||||||
|
config.add_predicate(
|
||||||
|
:test_not_in_predicate_no_array,
|
||||||
|
:arel_predicate => 'not_in',
|
||||||
|
:wants_array => false
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(Ransack.predicates['test_in_predicate_no_array'].wants_array).to eq false
|
||||||
|
expect(Ransack.predicates['test_not_in_predicate_no_array'].wants_array).to eq false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue