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

Changeset 27

Show
Ignore:
Timestamp:
04/17/06 10:28:49 (2 years ago)
Author:
jk
Message:

tests

Files:

Legend:

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

    r16 r27  
    1 require 'ferret' 
    2  
    31class Comment < ActiveRecord::Base 
    42  belongs_to :parent, :class_name => 'Content' 
  • trunk/demo/test/fixtures/comments.yml

    r14 r27  
    33  id: 1 
    44  content: comment from fixture 
     5  content_id: 1 
    56another: 
    67  id: 2 
    78  content: second comment from fixture 
     9  content_id: 1 
     10comment_for_c2: 
     11  id: 3 
     12  content: regarding content 2 
     13  content_id: 2 
  • trunk/demo/test/unit/content_test.rb

    r18 r27  
    3737  end 
    3838 
     39  def test_update 
     40    contents_from_ferret = Content.find_by_contents('useless') 
     41    assert_equal 1, contents_from_ferret.size 
     42    assert_equal @content.id, contents_from_ferret.first.id 
     43    @content.description = 'Updated description, still useless' 
     44    @content.save 
     45    contents_from_ferret = Content.find_by_contents('useless') 
     46    assert_equal 1, contents_from_ferret.size 
     47    assert_equal @content.id, contents_from_ferret.first.id 
     48    contents_from_ferret = Content.find_by_contents('updated AND description') 
     49    assert_equal 1, contents_from_ferret.size 
     50    assert_equal @content.id, contents_from_ferret.first.id 
     51    contents_from_ferret = Content.find_by_contents('updated OR description') 
     52    assert_equal 1, contents_from_ferret.size 
     53    assert_equal @content.id, contents_from_ferret.first.id 
     54  end 
     55 
    3956  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 
     57    #Content.rebuild_index 
     58    assert_equal 2, @another_content.comment_count 
     59    assert_equal 2, contents(:first).comment_count 
     60    assert_equal 1, contents(:another).comment_count 
     61    # retrieve all content objects having 2 comments 
     62    result = Content.find_by_contents('comment_count:2') 
     63    # TODO check why this range query returns 3 results 
     64    #result = Content.find_by_contents('comment_count:[2 TO 1000]') 
     65    # p result 
     66    assert_equal 2, result.size 
     67    assert result.include?(@another_content) 
     68    assert result.include?(contents(:first)) 
    4569  end 
    4670 

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