spec/functional/backends/redis_spec.rb in picky-4.0.0pre1 vs spec/functional/backends/redis_spec.rb in picky-4.0.0pre2
- old
+ new
@@ -16,19 +16,18 @@
attr_reader :data, :books
let(:data) do
Picky::Index.new(:books) do
- key_format :to_s # TODO Also make to_i work.
source []
category :title, partial: Picky::Partial::Postfix.new(from: 1)
category :author, similarity: Picky::Generators::Similarity::DoubleMetaphone.new(3)
end
end
let(:books) { Picky::Search.new data }
- its = ->(*) do
+ its_to_s = ->(*) do
it 'searching for it' do
books.search('title').ids.should == ['1']
end
it 'searching for it using multiple words' do
books.search('title author').ids.should == ['1']
@@ -80,28 +79,89 @@
books.search('title').ids.should == ['1']
end
end
- context 'default backend (dump needed)' do
- before(:each) do
- data.backend Picky::Backends::Redis.new
+ its_to_i = ->(*) do
+ it 'searching for it' do
+ books.search('title').ids.should == [1]
+ end
+ it 'searching for it using multiple words' do
+ books.search('title author').ids.should == [1]
+ end
+ it 'searching for it using partial' do
+ books.search('tit').ids.should == [1]
+ end
+ it 'searching for it using similarity' do
+ books.search('aothor~').ids.should == [1]
+ end
+ it 'handles removing' do
+ data.remove 1
+
+ books.search('title').ids.should == []
+ end
+ it 'handles removing with more than one entry' do
+ data.add Book.new(2, 'title', 'author')
+
+ books.search('title').ids.should == [2, 1]
+
+ data.remove 1
+
+ books.search('title').ids.should == [2]
+ end
+ it 'handles removing with three entries' do
+ data.add Book.new(2, 'title', 'author')
+ data.add Book.new(3, 'title', 'author')
+
+ books.search('title').ids.should == [3, 2, 1]
+
+ data.remove 1
+
+ books.search('title').ids.should == [3, 2]
+ end
+ it 'handles replacing' do
+ data.replace Book.new(1, 'toitle', 'oithor')
+
+ books.search('title').ids.should == []
+ books.search('toitle').ids.should == [1]
+ end
+ it 'handles clearing' do
data.clear
- data.add Book.new(1, 'title', 'author')
+ books.search('title').ids.should == []
end
+ it 'handles dumping and loading' do
+ data.dump
+ data.load
- instance_eval &its
+ books.search('title').ids.should == [1]
+ end
end
- context 'immediately indexing backend (no dump needed)' do
- before(:each) do
- data.backend Picky::Backends::Redis.new(immediate: true)
- data.clear
+ context 'to_s key format' do
+ context 'immediately indexing backend (no dump needed)' do
+ before(:each) do
+ data.key_format :to_s
+ data.backend described_class.new
+ data.clear
- data.add Book.new(1, 'title', 'author')
+ data.add Book.new(1, 'title', 'author')
+ end
+
+ instance_eval &its_to_s
end
+ end
+ context 'to_i key format' do
+ context 'immediately indexing backend (no dump needed)' do
+ before(:each) do
+ data.key_format :to_i
+ data.backend described_class.new
+ data.clear
- instance_eval &its
+ data.add Book.new(1, 'title', 'author')
+ end
+
+ instance_eval &its_to_i
+ end
end
end
\ No newline at end of file