Sha256: 391c7e336272f3fd600af40d68ebad619844c854bb2a454af8c57a35d93f1b9d
Contents?: true
Size: 1.88 KB
Versions: 1
Compression:
Stored size: 1.88 KB
Contents
require 'spec_helper' class ActiveModelUserFilter < StubModelBase ac_field :full_name def self.test_data [ {:full_name => 'Laura Nelson', :interest_ids => [1, 2]}, {:full_name => 'Laura Flores', :interest_ids => [2, 3]}, {:full_name => 'Laura Larson', :interest_ids => [3, 4]} ] end def self.populate test_data.each_with_index do |data, id| u = new(data) u.id = id u.save end end def to_indexed_json for_json = {} attrs = [:id, :created_at, :interest_ids] + self.class.ac_search_attrs attrs.each do |attr| for_json[attr] = send(attr) end MultiJson.encode(for_json) end end describe 'search filters' do let(:model) { ActiveModelUserFilter } before :all do model.setup_index end it 'filter suggestions with terms' do model.ac_search('Laura', :with => {:interest_ids => [2]}).map(&:full_name).should =~ ['Laura Nelson', 'Laura Flores'] end it 'accept coma separated string for filter' do model.ac_search('Laura', :with => {:interest_ids => '1,4'}).map(&:full_name).should =~ ['Laura Nelson', 'Laura Larson'] end it 'filter suggestions without terms' do model.ac_search('Laura', :without => {:interest_ids => [2]}).map(&:full_name).should =~ ['Laura Larson'] end it 'can order suggestions desc' do res = model.ac_search('Laura', :order => :id, :sort_mode => 'desc').map(&:id) res.should == res.sort.reverse end it 'can order suggestions asc' do res = model.ac_search('Laura', :order => :id, :sort_mode => 'asc').map(&:id) res.should == res.sort end it 'limit suggestions collection size' do model.ac_search('Laura', :per_page => 1).to_a.should have(1).result end it 'paginate suggestions' do res = model.ac_search('Laura', :per_page => 1, :page => 2).to_a res.should have(1).result res.first.full_name.should == 'Laura Flores' end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
elasticsearch_autocomplete-0.1.2 | spec/elasticsearch_autocomplete/search_filters_spec.rb |