To edit pages or tickets please login with username/password: aaf/aaf

Changeset 59

Show
Ignore:
Timestamp:
06/08/06 20:10:56 (2 years ago)
Author:
jk
Message:

unit tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/demo/test/unit/comment_test.rb

    r57 r59  
    1515  # tests the automatic building of an index when none exists 
    1616  # delete index/test/* before running rake to make this useful 
    17   def test_index_rebuild 
     17  def test_automatic_index_build 
    1818    # TODO: check why this fails, but querying for 'comment fixture' works. 
    1919    # maybe different analyzers at index creation and searching time ? 
     
    2323    assert comments_from_ferret.include?(comments(:first)) 
    2424    assert comments_from_ferret.include?(comments(:another)) 
     25  end 
     26 
     27  def test_rebuild_index 
     28    Comment.ferret_index.query_delete('comment') 
     29    comments_from_ferret = Comment.find_by_contents('comment AND fixture') 
     30    assert comments_from_ferret.empty? 
     31    Comment.rebuild_index 
     32    comments_from_ferret = Comment.find_by_contents('comment AND fixture') 
     33    assert_equal 2, comments_from_ferret.size 
     34  end 
     35 
     36  def test_total_hits 
     37    comments_from_ferret = Comment.find_by_contents('comment AND fixture', :num_docs => 1) 
     38    assert_equal 1, comments_from_ferret.size 
     39    assert_equal 2, comments_from_ferret.total_hits 
     40  end 
     41 
     42  def test_find_all 
     43    20.times do |i| 
     44      Comment.create( :author => 'multi-commenter', :content => "This is multicomment no #{i}" ) 
     45    end 
     46    assert_equal 10, (res = Comment.find_by_contents('multicomment')).size 
     47    assert_equal 20, res.total_hits 
     48    assert_equal 15, (res = Comment.find_by_contents('multicomment', :num_docs => 15)).size 
     49    assert_equal 20, res.total_hits 
     50    assert_equal 20, (res = Comment.find_by_contents('multicomment', :num_docs => :all)).size 
     51    assert_equal 20, res.total_hits 
     52 
     53    Comment.configuration[:max_results] = 15 
     54    assert_equal 15, (res = Comment.find_by_contents('multicomment', :num_docs => :all)).size 
     55    assert_equal 20, res.total_hits 
    2556  end 
    2657 
     
    3869 
    3970  def test_find_by_contents 
    40     comment = Comment.new( :author => 'john doe', :content => 'This is a useless comment' ) 
    41     comment.save 
    42     comment2 = Comment.new( :author => 'another', :content => 'content' ) 
    43     comment2.save 
     71    comment = Comment.create( :author => 'john doe', :content => 'This is a useless comment' ) 
     72    comment2 = Comment.create( :author => 'another', :content => 'content' ) 
    4473 
    4574    comments_from_ferret = Comment.find_by_contents('anoth* OR jo*') 

To edit pages or tickets please login with username/password: aaf/aaf