Sha256: 7ea8c1ae62f11383a4bc8fd46628422fff9e486278ce3302a56e3d4229859f87

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require File.expand_path("../abstract_unit", __FILE__)
include ActsAsIndexed

class SearchIndexTest < ActiveSupport::TestCase

  def teardown
    destroy_index
  end

  def test_should_check_for_non_existing_index
    SearchIndex.any_instance.expects(:exists?).returns(false)
    File.expects(:open).never
    assert build_search_index
  end

  def test_should_check_for_existing_index
    SearchIndex.any_instance.expects(:exists?).returns(true)
    SearchIndex.any_instance.expects(:load_record_size).returns(0)
    assert build_search_index
  end
  
  def test_add_record
    search_index = build_search_index
    mock_record = mock(:id => 123)
    mock_condensed_record = ['mock','condensed','record']
    
    search_index.expects(:condense_record).with(mock_record).returns(mock_condensed_record)
    search_index.expects(:load_atoms).with(mock_condensed_record)
    search_index.expects(:add_occurences).with(mock_condensed_record,123)
    
    search_index.add_record(mock_record)
  end
  
  def test_add_records
    search_index = build_search_index
    mock_records = ['record0', 'record1']
    
    search_index.expects(:add_record).with('record0')
    search_index.expects(:add_record).with('record1')
    
    search_index.add_records(mock_records)
  end
  
  private
  
  def build_search_index(root = index_loc, index_depth = 2, fields = [:title, :body], min_word_size = 3)
    SearchIndex.new([root], index_depth, fields, min_word_size)
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_indexed-0.6.3 test/search_index_test.rb