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

root/trunk/demo/test/unit/shared_index1_test.rb

Revision 320, 3.8 kB (checked in by jk, 8 months ago)

local mode works

Line 
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class SharedIndex1Test < Test::Unit::TestCase
4   fixtures :shared_index1s, :shared_index2s
5
6   def setup
7     SharedIndex1.rebuild_index
8   end
9
10   def test_lazy_loading
11     results = ActsAsFerret::find 'first', 'shared', :lazy => [ :name ]
12     assert_equal 2, results.size
13     found_lazy_result = false
14     results.each { |r|
15       assert ActsAsFerret::FerretResult === r
16       assert !r.name.blank?
17       assert_nil r.instance_variable_get(:@ar_record) # lazy, AR record has not been fetched
18     }
19   end
20  
21   def test_find
22     assert_equal shared_index1s(:first), SharedIndex1.find(1)
23     assert_equal shared_index2s(:first), SharedIndex2.find(1)
24   end
25
26   def test_find_ids_with_ferret
27     result = SharedIndex1.find_ids_with_ferret("first")
28     assert_equal 2, result.size
29   end
30
31   def test_find_with_ferret_one_class
32     result = SharedIndex1.find_with_ferret("first")
33     assert_equal 1, result.size, result.inspect
34     assert_equal shared_index1s(:first), result.first
35   end
36
37   def test_custom_query
38     result = SharedIndex1.find_with_ferret("name:first class_name:SharedIndex1")
39     assert_equal 1, result.size
40     assert_equal shared_index1s(:first), result.first
41   end
42
43   def test_find_with_index_name
44     result = ActsAsFerret::find("first", 'shared')
45     assert_equal 2, result.size
46     assert result.include?(shared_index1s(:first))
47     assert result.include?(shared_index2s(:first))
48   end
49
50   def test_find_with_class_list
51     result = ActsAsFerret::find("name:first", [SharedIndex1, SharedIndex2])
52     assert_equal 2, result.size
53     assert result.include?(shared_index1s(:first))
54     assert result.include?(shared_index2s(:first))
55   end
56
57   def test_query_for_record
58     assert_match /SharedIndex1/, shared_index1s(:first).query_for_record.to_s
59   end
60
61   def test_destroy
62     result = ActsAsFerret::find("first OR another", 'shared')
63     assert_equal 4, result.size
64     SharedIndex1.destroy(shared_index1s(:first))
65     result = ActsAsFerret::find("first OR another", 'shared')
66     assert_equal 3, result.size
67     shared_index2s(:first).destroy
68     result = ActsAsFerret::find("first OR another", 'shared')
69     assert_equal 2, result.size
70   end
71
72   def test_ferret_destroy
73     SharedIndex1.rebuild_index
74     result = SharedIndex1.find_ids_with_ferret("first OR another", :models => :all)
75     assert_equal 4, result.first
76     shared_index1s(:first).ferret_destroy
77     result = SharedIndex1.find_ids_with_ferret("first OR another", :models => :all)
78     assert_equal 3, result.first
79   end
80
81   def test_ferret_destroy_ticket_88
82     SharedIndex1.rebuild_index
83     result = SharedIndex1.find_ids_with_ferret("first OR another", :models => :all)
84     assert_equal 4, result.first
85     result = SharedIndex2.find_ids_with_ferret("first OR another", :models => :all)
86     assert_equal 4, result.first
87     SharedIndex1.destroy(shared_index1s(:first))
88     result = SharedIndex1.find_ids_with_ferret("first OR another", :models => :all)
89     assert_equal 3, result.first
90     result = SharedIndex2.find_ids_with_ferret("first OR another", :models => :all)
91     assert_equal 3, result.first
92     shared_index2s(:first).destroy
93     result = SharedIndex1.find_ids_with_ferret("first OR another", :models => :all)
94     assert_equal 2, result.first
95     result = SharedIndex2.find_ids_with_ferret("first OR another", :models => :all)
96     assert_equal 2, result.first
97   end
98
99   def test_update
100     assert SharedIndex1.find_with_ferret("new").empty?
101     shared_index1s(:first).name = "new name"
102     shared_index1s(:first).save
103     assert_equal 1, SharedIndex1.find_with_ferret("new").size
104     assert_equal 1, SharedIndex1.find_with_ferret("new").size
105     assert_equal 1, SharedIndex1.find_with_ferret("new", :models => [SharedIndex2]).size
106     assert_equal 0, SharedIndex2.find_with_ferret("new").size
107   end
108 end
Note: See TracBrowser for help on using the browser.

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