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

Changeset 18

Show
Ignore:
Timestamp:
03/25/06 13:15:43 (3 years ago)
Author:
jk
Message:

added unit test for patch of Ticket #2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/demo/app/models/content.rb

    r16 r18  
    44  # a higher boost means more importance for the field --> documents having a 
    55  # match in a field with a higher boost value will be ranked better 
    6   acts_as_ferret :fields => { 'title' => { :boost => 2 }, 'description' => { :boost => 1 } }, :store_class_name => true 
     6  # 
     7  # we use the store_class_name flag to be able to retrieve model instances when 
     8  # searching multiple indexes at once. 
     9  acts_as_ferret :fields => { :comment_count => {}, 'title' => { :boost => 2 }, 'description' => { :boost => 1 } }, :store_class_name => true 
    710 
    811  # use this instead to not assign special boost values: 
    912  #acts_as_ferret :fields => [ 'title', 'description' ] 
     13 
     14  # returns the number of comments attached to this content. 
     15  # the value returned by this method will be indexed, too. 
     16  def comment_count 
     17    comments.size 
     18  end 
    1019end 
  • trunk/demo/test/unit/content_test.rb

    r16 r18  
    1616    @comment2 = Comment.new( :author => 'another', :content => 'content' ) 
    1717    @comment2.save 
     18 
     19    @another_content.comments << @comment 
     20    @another_content.comments << @comment2 
     21    @another_content.save 
    1822  end 
    1923   
     
    3135  def test_class_index_dir 
    3236    assert_equal "#{RAILS_ROOT}/index/test/Content", Content.class_index_dir 
     37  end 
     38 
     39  def test_indexed_method 
     40    assert_equal 2, @another_content.comments.size 
     41    # retrieve all content objects having more than 1 comments 
     42    result = Content.find_by_contents('comment_count:[2 TO 1000]') 
     43    assert_equal 1, result.size 
     44    assert_equal @another_content.id, result.first.id 
    3345  end 
    3446 

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