spec/lib/indexers/parallel_spec.rb in picky-4.17.0 vs spec/lib/indexers/parallel_spec.rb in picky-4.17.1

- old
+ new

@@ -1,28 +1,83 @@ require 'spec_helper' describe Picky::Indexers::Parallel do + + thing = Struct.new :id, :text before(:each) do - @source = stub :source - @index = stub :index, :name => :some_index, :source => @source - - @categories = stub :categories - + @index = Picky::Index.new(:test) # stub :index, :name => :some_index, :source => @source, :backend => stub(:backend) @indexer = described_class.new @index @indexer.stub! :timed_exclaim end + + context 'with untokenized category' do + + before(:each) do + @categories = [ + Picky::Category.new(:text, @index) + ] + @source = [ + thing.new(1, "hello"), + thing.new(2, "world"), + ] + end - describe 'flush' do - it 'flushes to joined cache to the file and clears it' do - cache = stub :cache - file = stub :file + describe 'flush' do + it 'flushes to joined cache to the file and clears it' do + cache = stub :cache + file = stub :file - cache.should_receive(:join).once.and_return :joined - file.should_receive(:write).once.with(:joined).and_return :joined - cache.should_receive(:clear).once + cache.should_receive(:join).once.and_return :joined + file.should_receive(:write).once.with(:joined).and_return :joined + cache.should_receive(:clear).once - @indexer.flush file, cache + @indexer.flush file, cache + end end + + describe 'process' do + it 'flushes to joined cache to the file and clears it' do + @indexer.process @source, @categories do |file| + file.path.should == 'spec/temp/index/test/test/text.prepared.txt' + end + end + end + + end + + context 'with tokenized category' do + + before(:each) do + @categories = [ + Picky::Category.new(:text, @index, tokenize: false) + ] + @source = [ + thing.new(1, ["hello"]), + thing.new(2, ["world"]), + ] + end + + describe 'flush' do + it 'flushes to joined cache to the file and clears it' do + cache = stub :cache + file = stub :file + + cache.should_receive(:join).once.and_return :joined + file.should_receive(:write).once.with(:joined).and_return :joined + cache.should_receive(:clear).once + + @indexer.flush file, cache + end + end + + describe 'process' do + it 'flushes to joined cache to the file and clears it' do + @indexer.process @source, @categories do |file| + file.path.should == 'spec/temp/index/test/test/text.prepared.txt' + end + end + end + end end \ No newline at end of file