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|
|
|
|
|
config.should 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
|
|
|
|
|
|
|
|
Ransack.predicates.should have_key 'test_predicate'
|
|
|
|
Ransack.predicates.should have_key 'test_predicate_any'
|
|
|
|
Ransack.predicates.should have_key 'test_predicate_all'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'avoids creating compound predicates if :compounds => false' do
|
|
|
|
Ransack.configure do |config|
|
|
|
|
config.add_predicate :test_predicate_without_compound, :compounds => false
|
|
|
|
end
|
|
|
|
|
|
|
|
Ransack.predicates.should have_key 'test_predicate_without_compound'
|
|
|
|
Ransack.predicates.should_not have_key 'test_predicate_without_compound_any'
|
|
|
|
Ransack.predicates.should_not have_key 'test_predicate_without_compound_all'
|
|
|
|
end
|
2012-03-07 14:31:13 -05:00
|
|
|
|
|
|
|
it 'should have default value for search key' do
|
|
|
|
Ransack.options[:search_key].should eq :q
|
|
|
|
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
|
|
|
|
|
|
|
|
Ransack.options[:search_key].should eq :query
|
|
|
|
|
|
|
|
# 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|
|
|
|
|
config.add_predicate :test_array_predicate, :wants_array => true, :compounds => true
|
|
|
|
end
|
|
|
|
|
|
|
|
Ransack.predicates['test_array_predicate'].wants_array.should eq true
|
|
|
|
Ransack.predicates.should_not have_key 'test_array_predicate_any'
|
|
|
|
Ransack.predicates.should_not have_key 'test_array_predicate_all'
|
|
|
|
end
|
2011-03-30 20:31:39 -04:00
|
|
|
end
|
|
|
|
end
|