2011-03-30 20:31:39 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
module Ransack
|
|
|
|
describe Configuration do
|
2011-06-04 18:01:12 -04:00
|
|
|
it 'yields Ransack on configure' do
|
|
|
|
Ransack.configure do |config|
|
2014-05-15 14:29:46 -04:00
|
|
|
expect(config).to eq Ransack
|
2011-03-30 20:31:39 -04:00
|
|
|
end
|
|
|
|
end
|
2011-07-17 19:04:00 -04:00
|
|
|
|
|
|
|
it 'adds predicates' do
|
|
|
|
Ransack.configure do |config|
|
|
|
|
config.add_predicate :test_predicate
|
|
|
|
end
|
|
|
|
|
2014-05-15 14:29:46 -04:00
|
|
|
expect(Ransack.predicates).to have_key 'test_predicate'
|
|
|
|
expect(Ransack.predicates).to have_key 'test_predicate_any'
|
|
|
|
expect(Ransack.predicates).to have_key 'test_predicate_all'
|
2011-07-17 19:04:00 -04:00
|
|
|
end
|
|
|
|
|
2013-08-04 09:13:41 -04:00
|
|
|
it 'avoids creating compound predicates if compounds: false' do
|
2011-07-17 19:04:00 -04:00
|
|
|
Ransack.configure do |config|
|
2013-12-15 13:27:50 -05:00
|
|
|
config.add_predicate(
|
|
|
|
:test_predicate_without_compound,
|
2014-05-01 09:55:39 -04:00
|
|
|
:compounds => false
|
2013-12-15 13:27:50 -05:00
|
|
|
)
|
2011-07-17 19:04:00 -04:00
|
|
|
end
|
2014-05-15 14:29:46 -04:00
|
|
|
expect(Ransack.predicates)
|
|
|
|
.to have_key 'test_predicate_without_compound'
|
|
|
|
expect(Ransack.predicates)
|
|
|
|
.not_to have_key 'test_predicate_without_compound_any'
|
|
|
|
expect(Ransack.predicates)
|
|
|
|
.not_to have_key 'test_predicate_without_compound_all'
|
2011-07-17 19:04:00 -04:00
|
|
|
end
|
2012-03-07 14:31:13 -05:00
|
|
|
|
|
|
|
it 'should have default value for search key' do
|
2014-05-15 14:29:46 -04:00
|
|
|
expect(Ransack.options[:search_key]).to eq :q
|
2012-03-07 14:31:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'changes default search key parameter' do
|
|
|
|
# store original state so we can restore it later
|
|
|
|
before = Ransack.options.clone
|
|
|
|
|
|
|
|
Ransack.configure do |config|
|
2012-04-11 16:44:10 -04:00
|
|
|
config.search_key = :query
|
2012-03-07 14:31:13 -05:00
|
|
|
end
|
|
|
|
|
2014-05-15 14:29:46 -04:00
|
|
|
expect(Ransack.options[:search_key]).to eq :query
|
2012-03-07 14:31:13 -05:00
|
|
|
|
|
|
|
# restore original state so we don't break other tests
|
|
|
|
Ransack.options = before
|
|
|
|
end
|
2012-05-02 02:54:12 -04:00
|
|
|
|
|
|
|
it 'adds predicates that take arrays, overriding compounds' do
|
|
|
|
Ransack.configure do |config|
|
2013-12-15 13:27:50 -05:00
|
|
|
config.add_predicate(
|
|
|
|
:test_array_predicate,
|
2014-05-01 09:55:39 -04:00
|
|
|
:wants_array => true,
|
|
|
|
:compounds => true
|
2013-12-15 13:27:50 -05:00
|
|
|
)
|
2012-05-02 02:54:12 -04:00
|
|
|
end
|
|
|
|
|
2014-05-15 14:29:46 -04:00
|
|
|
expect(Ransack.predicates['test_array_predicate'].wants_array).to eq true
|
|
|
|
expect(Ransack.predicates).not_to have_key 'test_array_predicate_any'
|
|
|
|
expect(Ransack.predicates).not_to have_key 'test_array_predicate_all'
|
2012-05-02 02:54:12 -04:00
|
|
|
end
|
2011-03-30 20:31:39 -04:00
|
|
|
end
|
2014-04-09 23:28:29 -04:00
|
|
|
end
|