From 18f6875b54a1ee913134ec15c08c015b556c5793 Mon Sep 17 00:00:00 2001 From: Bilal Date: Thu, 16 Apr 2020 15:31:50 +0200 Subject: [PATCH] add specs to search multiple default columns --- spec/lib/pg_searchable_new_spec.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/spec/lib/pg_searchable_new_spec.rb b/spec/lib/pg_searchable_new_spec.rb index 2bf7fd6..953f194 100644 --- a/spec/lib/pg_searchable_new_spec.rb +++ b/spec/lib/pg_searchable_new_spec.rb @@ -47,6 +47,20 @@ describe PgSearchable do expect(VectorModel.scope_search("#{record2.id}")).to contain_exactly(record2) end + it 'can search multiple default columns if no column name is used with single search term' do + records = VectorModelWithTwoDefaultColumns.create [{ name: 'hamo', value: '5' }, { name: 'meho', value: '20 hamo' }, { name: 'munja-5', value: '300' }] + + expect(VectorModelWithTwoDefaultColumns.scope_search('name:hamo')).to contain_exactly(records[0]) + expect(VectorModelWithTwoDefaultColumns.scope_search('hamo')).to contain_exactly(records[0], records[1]) + expect(VectorModelWithTwoDefaultColumns.scope_search('5')).to contain_exactly(records[0], records[2]) + end + + it 'can search multiple default columns if no column name is used in query containing multiple search terms' do + records = VectorModelWithTwoDefaultColumns.create [{ name: 'hamo', value: '9' }, { name: 'meho', value: '5' }, { name: 'oko-9', value: '100' }] + + expect(VectorModelWithTwoDefaultColumns.scope_search('(9 and not name:hamo) or meho')).to contain_exactly(records[2], records[1]) + end + it 'searches column declared in search term' do record1 = VectorModel.create name: 'hamo', value: '-45' record2 = VectorModel.create name: 'meho', value: '120' @@ -144,8 +158,6 @@ describe PgSearchable do expect(DynamicModelWithTagValues.scope_search('tag:green or value:"not"')).to contain_exactly(record1, record2) end - - it 'can search in referenced column and in model columns with multiple search terms connected with logical operators' do record1 = DynamicModelWithTagValues.create name: 'something', value: 'amazing' record2 = DynamicModelWithTagValues.create name: 'new record', value: 'not so amazing'